Skip to content

fix(journal): preserve original rows in sealed repair generations (STA-6925) - #19399

Closed
brennanb2025 wants to merge 4 commits into
mainfrom
brennanb2025/arch-execution-boundary
Closed

brennanb2025 wants to merge 4 commits into
mainfrom
brennanb2025/arch-execution-boundary

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​385 $\color{#cf222e}{\Huge{\mathbf{−}}}$​28 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​357
Prod 11 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​257 $\color{#cf222e}{\Huge{\mathbf{−}}}$​117 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​140

ELI5

Opening a damaged chat journal no longer deletes the unreadable row and everything after it. Orca keeps the original bytes and opens the readable prefix in a new generation, so Orca-only receipts remain available as recovery evidence.

What Changed

  • Schema v3 records and seals original recovery epochs. A single SQLite transaction seals the source, admits the readable prefix, records the rebuild marker, and publishes the replacement epoch.
  • Normal epoch replacement preserves sealed rows. SQLite triggers prevent sealed history and recovery metadata from being modified.
  • Future database versions and future row versions in TEXT or valid UTF-8 BLOBs remain read-only; all retained rows are checked before migration, including behind corruption. Admission and replay share raw SQLite value decoding; invalid UTF-8 and unsupported value types conservatively refuse writes. Decoding never rewrites source bytes or storage types. Existing epoch-change resets handle held cursors without new wire fields or opcodes.

Why

The former suffix deletion was irreversible, and provider transcripts cannot reconstruct Orca-only receipts. Sealing removes that destructive repair path while reusing the journal's atomic row/session transaction and FULL-sync durability. Failed admission refuses writable open and preserves the original rows.

Linked Issue

STA-6925

This is the bounded recovery foundation only. Payload clipping (STA-6924), retention and physical capacity budgeting (STA-6837), and a recovery UI remain separate work. Recovery metadata includes logical row counts/bytes; it does not claim a physical quota or reclaim sealed epochs.

Visual Proof

N/A — SQLite storage and recovery changes; no layout or interaction surface changed. Validation used disposable journals without real provider sessions or configuration.

Testing

Validation of the F1 fix at 885bdbb85617ba248c720073678d34e1e14b62b4:

  • Shipping suite: pnpm exec vitest run --config config/vitest.config.ts src/main/native-chat/agent-session-journal src/main/native-chat/agent-session-wire/agent-session-journal-recovery.test.ts --maxWorkers=2 — 19 files / 216 tests passed after exact ablation restoration.
  • Future UTF-8 BLOB at sequence 1 and behind corruption: read-only, append refused, original storage type/bytes and whole-file identity preserved, with schema v3 and actual v2 schema before migration. Direct replay agrees. Unsupported binary encoding remains read-only with whole-file identity.
  • Original version probe now passes both baseline-v2-opener/v3 fencing and future-BLOB read-only/file identity. This uses the baseline opener module with the current SQLite adapter, not an old packaged app.
  • Manual shipping-factory cases at sequence 1/3/5/6 with malformed JSON in valid UTF-8 BLOBs: two sealed generations, smaller replacement, rollover and reopen preserve type/bytes and matching SHA-256 values. Invalid UTF-8 has a different deliberate result: read-only without repair, covered by the shipping test.
  • Post-commit F1 ablation restored the raw type assertion: both targeted shipping tests failed at read-only admission (2 failed / 12 skipped, exit 1). Restored by cp; cmp, nonzero decoding-code match and empty source diff confirmed exact restoration.
  • Final node, web and CLI checks passed sequentially using npx tsc --noEmit -p config/tsconfig.node.json, then config/tsconfig.tc.web.json, then config/tsconfig.tc.cli.json. Initial node failures in three recovery-test assertions were fixed by handling raw values; final checks have no diagnostics. Commit lint/format hooks passed.
  • Existing suite also covers five abrupt child-process exits, SQLite max_page_count exhaustion, migration, repair markers and immutable evidence. Process exits are not hardware power loss; page limits are not host-volume exhaustion.

No Electron rendering/build, real provider sessions/profiles, Linux, Windows, WSL, live SSH, folder/worktree UI journey, mobile or packaged client/host version pairings were exercised. No transport behavior changed. Main advanced to 588240043e84b1f8e58013298e692e7a57ba8ad5; merging was prohibited, so integration with that main is unvalidated.

Review

Draft for a fresh independent architectural and implementation review; no readiness claim. Please challenge whether sealing plus prefix publication removes the data-loss mechanism and whether preservation survives every later epoch replacement.

Agent skill upstream boundary

  • Not applicable; no upstream skill-installer material is included.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Validation status for 903c5f637310ef51f34aa9e4c8bddc0ed9e7a48b (draft; fresh independent review still required):

  • 19 targeted journal/recovery files: 206 tests passed, 0 failed, using --config config/vitest.config.ts.
  • Node, web, and CLI typechecks passed sequentially; final node recheck also passed after the last test edits. Changed-file lint, normal commit hooks, and diff whitespace checks passed.
  • Disposable macOS arm64 / Node 26.5.0 manual runs placed corruption before, at, and after an Orca-only receipt. Original row hashes remained identical through repair, reopen, smaller replacement, and another reopen; intact sealed receipts were decoded successfully.
  • Five abrupt process-exit boundaries and real SQLite page-limit exhaustion passed. Original evidence remained preserved; after-commit publication was complete.
  • Committed before ablation: removing sealing caused both selected byte-preservation tests to fail. cp restoration, exact file comparison, nonzero sealing-code match, and committed-source comparison passed; all 15 repair/crash tests passed afterward.
  • Local HEAD, remote branch from git ls-remote, and GitHub PR API head all match the SHA above. Base main matched 9f044031fc9e4985b855d984311fac1b943809eb locally/remotely/API.

Not exercised: Linux, Windows, WSL, rendered Electron, real paired SSH, actual folder/worktree UI flows, released client/host version pairings, physical disk exhaustion, or hardware power loss. Existing reset behavior is unit-tested; no wire fields/opcodes changed. Payload clipping, retention, physical capacity policy, and a recovery UI remain outside this slice. No real provider/session/config data was accessed.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Independent review at 903c5f6: changes requested; not CLEAN/READY.

P2 — future-version JSON BLOB bypasses read-only admission (src/main/native-chat/agent-session-journal/journal-database.ts:100). entry.row_json as string does not convert node:sqlite's Uint8Array BLOB. JSON.parse misclassifies UTF-8 bytes for {"v":999} as ordinary corruption, so the shipping opener returns writable and changes the database instead of preserving future-version byte identity. Independently reproduced by binding Buffer.from('{"v":999}') into row_json of a disposable journal and reopening through openAgentSessionJournal: readOnly=false, file identity=false. This is a synthetic storage-class fault; normal writer output is TEXT. Inspect raw types before write admission, conservatively refuse unknown representations or decode for version inspection without rewriting original bytes, and cover anchor/behind-corruption/v2 cases.

The sealing architecture otherwise removes destructive suffix repair and protects later rollover/replacement. Concrete reuse matches the existing row/session transaction and epoch reset; sealed-history ownership is new. Capacity accounting and reclamation remain separate work.

Independently observed: 19 files / 206 tests passed; four disposable manual scenarios at anchor and before/at/after receipt preserved binary bytes, SQLite types and hashes across two repairs, smaller replacement, rollover and reopen; deliberate preservation ablation caused 2 expected failures, exact cp/cmp restoration followed by 15 passing repair/crash tests. Baseline v2 opener module against v3 was read-only and byte-identical. One additional version probe remains failing as above.

No rendered Electron UI, actual released client/host pairing, live SSH, Linux/Windows/WSL, real provider profile, hardware power loss or full physical disk was exercised. SQLite page-limit and abrupt process-exit tests do not establish those guarantees. Typechecks were not repeated independently. Reviewed base was 9f04403; remote main subsequently advanced, so integration with newer main is unreviewed.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

F1 fix pushed at 885bdbb85617ba248c720073678d34e1e14b62b4; local HEAD, remote branch and PR API head agree.

The shared parser now receives raw SQLite values, decodes valid UTF-8 BLOBs for both admission and replay, and refuses writes for unsupported encodings/types. It never rewrites source bytes or storage types. Future BLOBs at the anchor and behind corruption remain read-only with whole-file identity, including before actual v2 migration. Invalid UTF-8 is deliberately read-only; supported malformed JSON still uses sealed-generation repair.

Final validation: 19 files / 216 tests passed; original version probe now passes read-only and whole-file identity; four manual BLOB preservation cases passed through two repairs, replacement, rollover and reopen. Final-head ablation restored the bad raw type assertion and caused both targeted shipping tests to fail (2 failed / 12 skipped); cp restoration, cmp, nonzero decoder grep and the restored full suite passed. Node, web and CLI typechecks passed sequentially on the final head. Initial node errors in recovery-test assertions were fixed; no final diagnostics remain.

The standalone body and recovery documentation now describe the representation boundary. No Electron UI/platform/SSH/packaged-version coverage is claimed. Main is 588240043e84b1f8e58013298e692e7a57ba8ad5; integration remains unvalidated because merging was prohibited. This is an author fix report, not an independent CLEAN/READY judgment: fresh independent review of this exact head is required.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Fresh independent re-review: CLEAN for 885bdbb85617ba248c720073678d34e1e14b62b4 only, with no unresolved in-scope findings.

  • Functional: F1 is resolved at the shared raw SQLite parser used by admission and replay. Future UTF-8 BLOB rows at the anchor or behind corruption remain read-only before v2 migration; invalid encoding/types fail closed. Original storage bytes/types remain untouched. Sealing, prefix publication and session projection commit atomically; subsequent replacement/rollover retain sealed evidence.
  • Architecture/precedent: This removes destructive suffix repair and later deletion of preserved rows, using existing row/session transaction ownership and existing epoch-reset delivery. The new immutable evidence lifetime intentionally differs from ordinary live-history deletion. A second quarantine store is not justified for this bounded fix.
  • Independent validation: 19 shipping files / 216 tests passed, 0 failed using config/vitest.config.ts; original failed version probe now reports read-only and whole-file identity. Four observed disposable-journal cases at seq 1/3/5/6 each preserve two sealed epochs through smaller replacement, rollover and reopen, with matching original/type/byte arrays and SHA-256 pairs. The suite includes five abrupt process exits and SQLite page-limit refusal.
  • Gaps: No independently repeated broad typechecks, rendered Electron/build, real provider/profile, Linux/Windows/WSL, live SSH, mobile, workspace UI journey or packaged client/host version matrix. The v2 compatibility probe uses the baseline opener with the current SQLite adapter. Process exits are not power loss; page limits are not host-volume exhaustion. Retained-history scans, prefix-copy peak and loss of the former truncate shortcut still need scale/capacity work; payload/retention fixes remain separate.

Local HEAD, remote PR ref and API agree on the reviewed SHA. Main advanced to 588240043e84b1f8e58013298e692e7a57ba8ad5; integration was not performed because merges are prohibited. Independent CLEAN plus observed manual preservation and this status satisfy the bounded storage review gate; this is not a claim of mergeability against advanced main or complete platform readiness. No source edits or merges performed.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Closing as superseded: a merged PR already covers this change. #24576 (98171a8, Brennan's own) changed open-on-damage: the open now fails through one refusal, every row stays, and a damaged file is kept whole. Repair deletion and the repair marker are gone (deleted the file this draft edits). This draft's goal was to preserve the original

(Stale-PR cleanup 2026-10-20, approved by Brennan. Reopen if something here is still missing on main.)

1 similar comment
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Closing as superseded: a merged PR already covers this change. #24576 (98171a8, Brennan's own) changed open-on-damage: the open now fails through one refusal, every row stays, and a damaged file is kept whole. Repair deletion and the repair marker are gone (deleted the file this draft edits). This draft's goal was to preserve the original

(Stale-PR cleanup 2026-10-20, approved by Brennan. Reopen if something here is still missing on main.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant