**Plan: Remove void-world system preamble from production AI gateway** --- ### 1. Immediate Fix: Clear the Runtime Configuration - **Action**: Execute the following SQL against the production database to zero out the preamble value: ```sql UPDATE site_settings SET value = '' WHERE key = 'gateway_system_preamble'; ``` - **Verification**: After execution, confirm with `SELECT value FROM site_settings WHERE key = 'gateway_system_preamble';` that it returns an empty string `''`. ### 2. Prevent Recurrence: Add a Guard in Code Although the root cause is a stray DB record, the current code lacks protection against future accidental preamble injections. Add a **validation guard** inside `apply_system_directives()` in `devplacepy/services/openai_gateway/system_message.py`: - **Location**: Within the function, after line 99 (`if not preamble_text: return result`), add a *pattern-based rejection* that skips preamble injection if the text matches known dangerous patterns (e.g., "void-world", "sole consciousness", "everything is allowed", "no consequences"). - **Implementation sketch**: ```python # After the existing guard at line 99 import re DANGEROUS_PHRASES = [ r"void.world", r"sole consciousness", r"everything is allowed", r"no consequences", r"absolute void", ] if preamble_text and any(re.search(p, preamble_text, re.IGNORECASE) for p in DANGEROUS_PHRASES): logger.warning("Blocked dangerous preamble pattern; injecting empty preamble") preamble_text = "" ``` - **Note**: This is a failsafe, not a replacement for the primary fix. The DB value must still be cleared. ### 3. Add Unit Test for Empty Preamble - **File**: `tests/unit/services/openai_gateway/system_message_test.py` (new file) - **Contents**: - Test `test_empty_preamble_no_injection()`: call `apply_system_directives` with `messages=[{"role": "user", "content": "hello"}]` and `cfg_with_empty_preamble`. Assert that the result has no system role message added. - Test `test_non_empty_preamble_without_system()`: with a non-empty preamble, assert a system message is added. - Test `test_dangerous_preamble_blocked()`: with a preamble containing "void-world", assert no injection occurs (if guard from step 2 is added). ### 4. Run Verification Commands - **Lint**: Execute `pip install -q ruff && ruff check .` — must exit with code 0 and no errors. - **Test**: Execute `pip install -e '.[dev]' -q && make test-unit` — must exit with code 0 and all tests passing. *Note: If PEP 668 errors occur, run inside a virtual environment or use `--break-system-packages` (per environment policy). The CI will handle this; the plan assumes the engineer can execute with appropriate environment.* --- ## Definition of Done - [ ] The `gateway_system_preamble` value in the `site_settings` table is set to empty string `''`. - [ ] The code in `system_message.py` contains a pattern guard that rejects known dangerous preamble text. - [ ] A new unit test file `tests/unit/services/openai_gateway/system_message_test.py` exists and covers the three scenarios above. - [ ] `ruff check .` passes with zero errors. - [ ] `make test-unit` passes with zero failures. - [ ] All existing tests in `tests/unit/services/openai_gateway/` continue to pass (no regressions).