SQLite history load merges LMC corrections regardless of PREF_CORRECTION_ALLOW #125
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
When
/correction off(i.e.PREF_CORRECTION_ALLOW = false) is set, the SQLite history backend still merges Last Message Correction (LMC) updates into the originals when re-loading chat history. The user sees the corrected text in the history pane instead of seeing the original and the correction as separate messages. This contradicts the documented semantics of/correction offintroduced in #114 / PR #116, which state that "every correction (incoming, outgoing, carbon-reflected) is rendered as a fresh message instead of mutating an existing buffer entry".Where the gap is
The merge happens at SQL level in
_sqlite_get_previous_chat(src/database_sqlite.c:387) — the query unconditionally joins correction rows onto their originals and returns the corrected text viaCOALESCE:No matter what
PREF_CORRECTION_ALLOWis, the loaded message is already the corrected text and the correction row itself is filtered out. The live (win_print_*) paths in src/ui/window.c honourPREF_CORRECTION_ALLOWfor in-session corrections, but that gate does not extend to history fetched from DB.The flatfile backend already handles this correctly — when
PREF_CORRECTION_ALLOWisfalse,_flatfile_get_previous_chat(src/database_flatfile.c:875-888) skips_ff_apply_lmcand returns all parsed lines (originals + corrections) as separateProfMessages. SQLite needs to do the analogous thing.Reproduction
/correctto correct your own outgoing message/correction onbehaviour)/correction off/correction onExpected: with
/correction off, the loaded history should show both the original message and the correction as separate entries, matching the flatfile behaviour and the in-session live path.Suggested fix
Branch the SQL in
_sqlite_get_previous_chatonPREF_CORRECTION_ALLOW:COALESCE+replaces_db_id IS NULLfilter)replaces_db_idfilter, return raw rowsA working implementation already exists — it was developed in the original review iteration of PR #116 and reverted on request to keep that PR's scope tight (see the discussion under #116). Can be lifted from the diff history or re-derived.
Why this is split out from PR #116
The reviewer's comment on PR #116 ("Doesn't affect messages fetched from DB though") flagged the gap on the gated line in
win_print_outgoing, but the fix lives indatabase_sqlite.cwhich the PR otherwise does not touch. To keep PR #116 focused on the in-session/UI half of/correction offand on the wider /history & /logging cleanup, the DB-side fix is being moved to a follow-up.Acceptance
/correction off, history re-load shows original + correction as separate messages/correction on(default), no behaviour change vs. todayReferences