## Implementation Plan 1. **Fix non-deterministic LLM call** `services/correction.py`, function `gateway_complete()` (around line 73) Change `"temperature": 0.1` → `"temperature": 0.0` in the JSON payload sent to the OpenAI-compatible gateway. 2. **Add content-hash dedup in message persistence** `services/messaging/persist.py`, function `persist_message()` after the empty-content guard (line 66) Compute `sha256(content.encode()).hexdigest()` and check an in-memory dict keyed by `(sender_uid, content_hash)` with a 3‑second TTL. If a duplicate is found within the window, skip DB insertion and return the existing message’s `uid`. *Simplicity over perfection: use a `dict` + `time.time()` with periodic cleanup on a timer or at the next call (len > 1000 → pop expired).* 3. **Add regression tests** Create `tests/api/messages/test_correction_determinism.py` with: - **`test_duplicate_http_submission_identical_correction`**: POST `/messages/send` twice with identical content in rapid succession; assert the corrected content fields of both returned messages are equal. - **`test_gateway_complete_temperature_zero`**: Mock `requests.post`, call `gateway_complete()`, verify the sent JSON contains `"temperature": 0.0`. 4. **Update existing tests (if any) that rely on non‑deterministic output** Grep for `temperature` and `0.1` in test files; no changes expected. --- ## Definition of Done - [ ] `services/correction.py` has `"temperature": 0.0` in the `gateway_complete()` payload. - [ ] `services/messaging/persist.py` contains a content-hash dedup check that prevents duplicate DB rows for identical content from the same sender within 3 seconds. - [ ] New test file `tests/api/messages/test_correction_determinism.py` passes all tests. - [ ] All existing unit tests pass: `pip install -e '.[dev]' -q && make test-unit` - [ ] Lint passes with no new issues: `pip install -q ruff && ruff check .`