Skip to content

Keep journal cleanup from freezing chat actions - #37802

Closed
brennanb2025 wants to merge 20 commits into
mainfrom
brennanb2025/journal-cleanup-freeze-fix
Closed

brennanb2025 wants to merge 20 commits into
mainfrom
brennanb2025/journal-cleanup-freeze-fix

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Large saved chat backlogs can freeze Orca while journal cleanup runs a single SQLite operation on the desktop main thread or server request thread. A reporter-size run observed a cleanup page lasting 5.4 seconds and a separate commit lasting 4.5 seconds; pauses between pages cannot interrupt either operation.

Change

Move journal database execution to one background writer, with separate bounded readers for history, restore and cleanup discovery. Keep chat state, ordering and publication in the existing host, and publish accepted changes only after their commit is known. Cleanup shares that writer in finite units so foreground actions can run between units. Preserve existing saved formats, chat content, receipts, accepted-write durability and restart behavior.

This is the follow-up repair to merged #36053, tracked in STA-13374. The separate streaming cadence and checkpoint policy work remain outside this PR.

Validation

Author checks: 238 named suites passed, one skipped; 2,208 tests passed and five skipped. Scoped formatting and lint pass across the changed files; the node typecheck and changed-code quality checks pass. The remaining consumer selection passed 13 suites initially; all four repaired suites now pass their 55 tests. Node, web and CLI typechecks pass. The fresh E2E typecheck has zero test-file diagnostics, with existing cloud/mobile dependency diagnostics outside that ratchet. The general changed-check runner selects tests implicitly; scoped checks and explicit named test files are used under the repository scoped-selection exception, with final CI still owed.

Full review, head CI, reporter-size comparisons against freshly pinned current main in both vacuum modes, the four sustained streaming cells, actual older-reader and downgrade/re-upgrade contracts, and real Claude and Codex lifecycle QA are still pending. The historical attribution experiment was incomplete and is not a performance pass. This PR is not ready to merge.

Intended behavior: native database execution has no serving-thread fallback because that execution causes the measured freeze; existing accepted-write durability and streamed-save exception are retained; existing checkpoint policy and saved-format boundaries remain unchanged.

Files Added Deleted Net
Test 305 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​8295 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2151 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​6144
Prod 274 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​13061 $\color{#cf222e}{\Huge{\mathbf{−}}}$​4414 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​8647

brennanb2025 added a commit that referenced this pull request Nov 3, 2026
Revert the live-history compaction and incremental vacuum added by #36053 to remove their serving-thread stall risk for the release. Preserve retired-history cleanup, saved formats/readers/writers and already-compacted sparse histories; add sparse reopen/write/reopen coverage.

Temporary: redundant live history can grow until the separate repair tracked in #37802 is ready. Older synchronous saves remain.

Tracked in STA-13374 and STA-13375. Six focused suites / 40 tests, independent correctness/architecture/final comparison and final-head CI passed.
audichuang pushed a commit to audichuang/orca that referenced this pull request Nov 4, 2026
…7873)

Revert the live-history compaction and incremental vacuum added by stablyai#36053 to remove their serving-thread stall risk for the release. Preserve retired-history cleanup, saved formats/readers/writers and already-compacted sparse histories; add sparse reopen/write/reopen coverage.

Temporary: redundant live history can grow until the separate repair tracked in stablyai#37802 is ready. Older synchronous saves remain.

Tracked in STA-13374 and STA-13375. Six focused suites / 40 tests, independent correctness/architecture/final comparison and final-head CI passed.

(cherry picked from commit 25c6757)
…p retries

Attachment claim cleanup no longer holds one database snapshot across every
filesystem check. Claims gain a never-reused AUTOINCREMENT identity through an
atomic rebuild at writable open; each cleanup pass captures the highest
identity once and reads 32-row identity pages in short released scans before
any filesystem work or write admission. Pages recheck pair and identity under
the existing admission, and the native prune stays pair-only.

Local structured session-tab sync now registers its disposal and retry owner
before the first await, so a failed initial capability read or a rejected
stale inventory schedules the existing bounded retry instead of leaving no
subscription.
Restore the live-history cleanup that #37873 temporarily removed, now on the
off-thread native writer, and port main's retained-input, logical context,
queue and ownership changes onto the asynchronous journal boundary.
Apply main's single-client frame projection fix (#38336) where this PR moved
mobile session tab delivery.
Prepare logical rewind rows and receipts in yielding pieces under the existing
reservation, read historical input evidence in bounded indexed pages, and
restore multirow projection rollback and retry coverage.
Build the replacement state, input owner, queue order, claim settlement and
returned rows in yielding pieces on a detached copy, switch to it once after the
native commit, and finish status and request-failure projections in awaited,
freshness-checked pieces. Route journal SQL workers through the managed worker
spawn and restore the main tests' work-count assertions on the async paths.
Assert per-page cleanup and claim-sweep operation counts at N and 10N with
foreground progress between maintenance units, cover format-1 survival,
refusals and the previous two stable releases' reads, writes and claim
identity continuity against the migrated database, and await the async
journal APIs in the released-chat upgrade test.
Route concurrent status reads during a replacement refresh through the finite
ordered preparation, prepare subscriber reset hydration and public view
normalization in yielding pieces, publish Stop settlement and process death
immediately during ordinary writes, and count real subscriber delivery in the
replacement bound test.
Load the real subscription module once in beforeAll, explain the older-build
tests' timeout, and shrink the baseline for the three findings this PR removed.
…ng replacement

Guard current snapshots, hydration, subscriptions, history pages, batch indexes
and current-work reads at one shared derived-read boundary while a journal's
replacement refresh is pending, and keep Stop and steering gates on the last
installed status projection during that refresh.
Accept main's removal of the queued public-read test; this PR only adapted it
to the async journal API.
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Superseded by #39256.

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