Repository navigation
fix(backup): replay historical Codex append payloads - #4457
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0504c1212b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
(#4457) ## Summary Backup recoverability proofs now reproduce historical Codex append blobs through the shared append payload encoder and re-anchor stale archive-root paths before ZIP member replay. ## Problem Five real rehearsal rows disproved the prior normalized-JSON derivation. Each recorded Codex append blob was 80 bytes larger than its recorded source window and matched a compact synthetic `session_meta` line followed by the literal delta. ## Solution `batch_support.py` owns the Codex append encoder used by the live writer and replay. Replay reads the source session identity and selects the historical header shape only when the recorded blob size proves it; current literal-delta rows retain literal bytes. The NFC change in `source_acquisition_components.py` was reverted because the real hashes are explained by the historical header, not text normalization. Source resolution still tries the active `inbox`, `browser-capture`, and `hooks` path before classifying a source as missing. ## Verification `.venv/bin/python /realm/tmp/work/nan3l-probe.py` printed `5/5 match` against the read-only rehearsal clone. `uv run devtools test tests/unit/daemon/test_backup.py -k 'historical_codex_append_header or dead_root or reacquires_live_append_segment'` passed 3 tests. `uv run devtools test tests/unit/sources/test_live_batch_support.py -k codex_append tests/unit/sources/test_revision_backfill.py -k codex tests/unit/sources/test_source_laws.py` passed 22 tests. `uv run devtools verify --quick` exited 0. `uv run devtools why` reported `quick run success (exit 0)`. ## Residual risk The full corpus and operational rehearsal were not run in this lane. Provider-specific append formats outside Codex retain their recorded byte-window behavior.
…4587) ## Summary Fixes the eleven verified Codex review findings in the sources / daemon / operations sweep. Each was re-confirmed at this branch's base before being changed; none were taken on faith from the sweep file. ## Findings and what changed | # | PR | Site | Claim | Action | | --- | --- | --- | --- | --- | | 1 | #4455 | `daemon/backup.py` `_source_recoverability_proofs` | a full-snapshot append row is hashed as a byte window | fixed: falls back to the full prefix `[0, end)` when the window does not prove the blob | | 2 | #4457 | `operations/append_acquisition_replay.py` | unbounded `handle.readline()` during replay | fixed: bounded at 1 MiB, matching live acquisition | | 3 | #4506 | `sources/live/deferred_cursor.py` | semantic frontier re-derived from current bytes with no comparison to retained evidence | fixed: recomposed frontier must reproduce the recorded **body** digest | | 4 | #4506 | `sources/origin_specs.py` | ChatGPT derives `inheritance_branch_point` from `mapping.parent`/`mapping.children` | fixed: declared structurally absent | | 5 | #4515 | `sources/live/source_selection.py` | no typed-vs-generic tiebreak, so a typed source loses ownership to a nested generic root | fixed: ownership resolved among sources that accept the path | | 6 | #4539 | `sources/live/watcher.py` | tool-outcome semantics changed without a parser-fingerprint bump | fixed: `live-batched-v2` -> `live-batched-v3` | | 7 | #4549 | `sources/live/batch.py` | legacy promotion commits durably before append planning succeeds; resynthesized cursor never returned | fixed: promotion deferred behind a successful plan; cursor handed back to the caller | | 8 | #4549 | `sources/sqlite_snapshot.py` | `sqlite_sequence` excluded, so insert-then-delete on AUTOINCREMENT yields no digest change | fixed: AUTOINCREMENT state included | | 9 | #4549 | `sources/live/batch.py` | full-head Claude authority computed from the live file | fixed: live prefix must reproduce the retained blob digest | | 10 | #4554 | `parsers/base_support.py` -> write boundary | idless model turn yields `("model_output", None)` and the write rejects the whole session | fixed at the write boundary (see note) | | 11 | #4558 | `sources/origin_specs.py` | fingerprint memo keyed on `(path, mtime, size)` | fixed: keyed by content digest | None were refuted. Master moved while this work ran; `git diff` over all eleven files across that range is empty, so every cited line still described current code. ### Finding 1: live exposure remains unconfirmed The code-level defect is real and now covered by a test. Its **live** reachability is not established: every current production caller of `admit_raw_observation` (`revision_governance.py:825,3995,4126`) passes `prior_head=None`, which never reaches the append arm that writes the full-payload-with-tail-offsets shape. This fixes the defect without claiming it was reachable in production. ### Finding 6: schema-regime classification Classified as **none of the schema-regime classes** -- it is not a schema change. There is no DDL edit and no derived-tier version bump, so no `DerivedDeltaClass` declaration in `storage/sqlite/lifecycle.py` applies; that table is keyed on index-schema version pairs. It is a *parser-semantic* change, whose declared route is the fingerprint bump itself. `base_support.py` is already inside the origin-spec parser-semantic closure (verified: `_semantic_source_paths` for a parser resolves it), so the origin-scoped fingerprint recomputed on its own with #4539. The gap was only the live watcher's hand-written literal. Bumping it marks every existing live cursor as stale, and the watcher routes those sources back through parse on its next pass -- the production convergence route. Nothing forces a rebuild by hand. **Operational consequence:** the first daemon pass after this lands re-ingests every live-watched source once. That is the intended cost of the correction, but it is a real one. ### Finding 10: fixed at the write boundary, not the parser The sweep points at `base_support.py:633-635`. The parser genuinely cannot fix this: `attachment_from_meta` takes `message_id: str | None` and there is no identity to name when it is `None`. The stored message id exists only at the write boundary, which is where the producer is now supplied -- covering both the parser-declared and role-derived paths. The fallback completes missing provenance and never overwrites parser-supplied evidence. ### Findings 3 and 9 are one fix Both derived Claude authority from bytes on disk at planning time rather than from retained evidence, so a rewrite preserving the prefix length inherited the previous observation's authority. Finding 3 (deferred cursor) compares the recomposed frontier's body digest against the recorded one; finding 9 (full-head resynthesis) requires the live prefix to hash to the retained blob. The reconstructed-chain branch already proved its prefix byte by byte and is left alone. Finding 3's check is deliberately on the **body**, not the whole frontier token: `ClaudeSemanticFrontier` is "replaceable header plus stable body", and an equality check on the token broke `test_deferred_claude_cursor_rebases_frontier_after_header_rewrite`, which protects legitimate rebasing onto a rewritten header. ## Verification Anti-vacuity was verified mechanically, not asserted: with all ten source files reverted to master and the new tests kept, every new test fails. ``` git checkout <master> -- <the ten source files> devtools test tests/unit/sources/test_reviewed_acquisition_defects.py \ tests/unit/storage/test_attachment_idless_model_turn.py \ tests/unit/sources/test_live_deferred_append_dedup.py \ tests/unit/sources/test_live_append_cursor_resynthesis.py \ tests/unit/daemon/test_backup.py -n 2 -> 15 failed, 79 passed ``` The 15 are the 13 new tests plus the 2 existing expectations this change updates. `test_backup_still_proves_a_window_shaped_append_row` **passes** on master -- it is the control proving finding 1's fix did not over-generalize into "always read the full prefix". With the fixes restored, the same selection is green: ``` devtools test tests/unit/sources/test_reviewed_acquisition_defects.py -n 2 -> 5 passed devtools test tests/unit/sources/test_live_deferred_append_dedup.py -n 2 -> 8 passed devtools test tests/unit/sources/test_live_append_cursor_resynthesis.py -n 2 -> 13 passed devtools test tests/unit/daemon/test_backup.py \ tests/unit/storage/test_attachment_idless_model_turn.py -n 2 -> 68 passed devtools verify --quick -> all 12 gates ok devtools render all --check -> exit 0, no "out of sync" ``` Collateral selection over the consumers of the changed modules (live watcher, source snapshot, source differential, catchup planning, codex state, and the four attachment suites): ``` devtools test tests/unit/sources/test_live_watcher.py \ tests/unit/sources/test_source_snapshot.py \ tests/unit/sources/test_source_differential.py \ tests/unit/sources/test_live_catchup_planning.py \ tests/unit/sources/parsers/test_codex_state.py \ tests/unit/storage/test_attachment_acquisition.py \ tests/unit/storage/test_attachment_first_class_ids.py \ tests/unit/storage/test_source_attachments.py \ tests/unit/storage/test_attachment_relink.py -n 2 -> 1 failed, 218 passed ``` After the fixture fix below, the one affected file was re-run on its own: ``` devtools test tests/unit/sources/test_live_watcher.py -n 2 -> 125 passed ``` The other eight files were green in the combined run and are untouched by that fixture change; no combined re-run was made, so the "219" total is not claimed as an observed number. The single failure was `test_parser_fingerprint_change_triggers_reingest`, caused by this branch and not inherited. It simulated a fingerprint change by monkeypatching `_PARSER_FINGERPRINT` to the *literal* `"live-batched-v3"`, which finding 6 makes the real value -- so the patch became a no-op, no change was simulated, and no reingest fired. The bump is not miswired; the fixture collided with it. The sentinel now derives from the real constant (`f"{_PARSER_FINGERPRINT}-changed"`), so the test asserts the same behaviour and cannot silently no-op on a future bump. Finding 6's own test (`test_superseded_parser_fingerprint_refuses_append_ planning`) independently proves a `live-batched-v2` cursor refuses append planning, and went red when the constant was reverted. Selected scope only: this proves the selected files, not the corpus. ## Residual risk - **Finding 6 forces a one-time live re-ingest** of every watched source on the next daemon pass. - **Finding 8 changes `sqlite_logical_revision`** for every AUTOINCREMENT database, so previously recorded identities differ once and those sources re-acquire on next observation. Self-healing, but not free. - **Finding 5 changes ownership for overlapping default roots** beyond the reported case: a `.db` under `~/.codex/sessions/` now resolves to `codex-state` rather than `codex`, because only `codex-state` accepts it. That looks correct, but it is a behaviour change the finding did not name. - **Finding 7** delays promotion until planning succeeds, not until the plan is *applied*. Closing that gap needs a larger refactor of the ingest stage. - **Finding 11** reads parser sources instead of stat-ing them. A per-process digest cache keyed on full inode identity including `st_ctime_ns` (which `os.utime` cannot restore) keeps this correct and measurably faster than before: 0.818 ms/call warm vs 1.343 ms/call for the previous stat-keyed signature, over a 449-file / 9 MB closure. - Three tests are reported red on master itself (`test_archive_tiers_api_session_costs_read_index_tier`, `test_existing_same_version_ops_database_receives_additive_call_log`, `test_record_context_delivery_requires_initialized_user_tier`). None are in files this branch touches and none were in the selections run here. --------- Co-authored-by: Claude Fable 5.1 <[email protected]>
|
Codex review threads on this PR whose cited code is gone (checked against master at 23f91a5):
Resolving these threads. |
|
Historical Codex triage: evidence checked at 5ebcfe5. This records that source revision; it does not claim a fresh review of current master.
Only the rows listed above are dispositioned. Held findings remain open. |
Summary
Backup recoverability proofs now reproduce historical Codex append blobs through the shared append payload encoder and re-anchor stale archive-root paths before ZIP member replay.
Problem
Five real rehearsal rows disproved the prior normalized-JSON derivation. Each recorded Codex append blob was 80 bytes larger than its recorded source window and matched a compact synthetic
session_metaline followed by the literal delta.Solution
batch_support.pyowns the Codex append encoder used by the live writer and replay. Replay reads the source session identity and selects the historical header shape only when the recorded blob size proves it; current literal-delta rows retain literal bytes. The NFC change insource_acquisition_components.pywas reverted because the real hashes are explained by the historical header, not text normalization.Source resolution still tries the active
inbox,browser-capture, andhookspath before classifying a source as missing.Verification
.venv/bin/python /realm/tmp/work/nan3l-probe.pyprinted5/5 matchagainst the read-only rehearsal clone.uv run devtools test tests/unit/daemon/test_backup.py -k 'historical_codex_append_header or dead_root or reacquires_live_append_segment'passed 3 tests.uv run devtools test tests/unit/sources/test_live_batch_support.py -k codex_append tests/unit/sources/test_revision_backfill.py -k codex tests/unit/sources/test_source_laws.pypassed 22 tests.uv run devtools verify --quickexited 0.uv run devtools whyreportedquick run success (exit 0).Residual risk
The full corpus and operational rehearsal were not run in this lane. Provider-specific append formats outside Codex retain their recorded byte-window behavior.