[codex] Guard COW row merges against target trigger rewrites#45
Merged
Conversation
42090e5 to
9eba805
Compare
This was referenced May 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What it does
Prevents COW mergeback from silently accepting source row inserts, updates, or reviewed source conflict resolutions when target-side triggers rewrite the row during the apply step.
When a source row write succeeds, ForkPress now verifies the row in target still matches the audited source or merged payload. If a target trigger rewrote or removed it, the write is rolled back to a per-row savepoint and the case stays reviewable instead of being recorded as a misleading source-applied result.
Rationale
The merge logic already handled SQLite constraint failures, unique collisions, foreign-key ordering, and trigger/schema validation. The remaining rough edge was successful target-trigger side effects: SQLite could accept the write, a target trigger could change the row, and the audit log would still claim the source payload landed exactly. That is a bad surprise for plugin tables with triggers.
The same guard is needed when a reviewer explicitly chooses the source side of a row conflict. A reviewed source choice should either land the audited source payload byte-for-byte at the row level, or fail validation and leave both the target DB and resolution metadata unchanged.
Implementation
RAISE(ROLLBACK)triggers, where SQLite removes savepoints as part of the transaction abort.Testing instructions
php tests/cow/merge.phppasses with2038assertions, including coverage for target triggers rewriting source inserts/updates and reviewed source resolutions remaining validation-gated with no resolution metadata recorded.