Skip to content

perf(native-chat): flush send transactions without flushing every streamed revision - #28966

Merged
brennanb2025 merged 8 commits into
mainfrom
brennanb2025/nc-perf-sync
Oct 16, 2026
Merged

brennanb2025 merged 8 commits into
mainfrom
brennanb2025/nc-perf-sync

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

Every saved update to a streamed reply currently forces a disk flush on Orca’s main thread. On a slow or busy disk, that work delays the app while the agent is writing. This change lets existing reply text update with less main-thread blocking. Sends, approvals, Stop and other actions keep their existing protection against a crash.

What Changed

The chat database keeps SQLite’s strongest save setting, FULL, by default. A save uses NORMAL only to revise existing assistant reply text, with text-only content both before and after the change. Changing who owns the reply, which turn or agent it belongs to, or saving an action alongside it keeps the strongest setting. The next FULL save also makes earlier reply text durable. No saved format or message exchanged between devices changes.

Accepted crash case: after an operating-system crash or power loss on the machine running the agent, recent reply text can be missing from the saved chat. A second device that stayed connected can keep that extra text or miss the turn’s recovered ending until the chat is reopened. There is no new time limit on how much text can be lost. An app crash or force-quit preserves committed updates.

Why

The same flush policy previously covered both replaceable reply text and actions that must be saved before an agent acts. Keeping the strong setting by default and allowing only verified text updates to use the lighter setting reduces repeated flushes without another queue, background process or recovery mechanism.

The common pattern uses NORMAL for every save. Intended difference: Orca keeps the strongest setting for sends, approvals, Stop and other actions, preserving their current guarantees. Intended scope limit: first saves, thinking updates, images and tools keep their existing flushes, and existing periodic database flushes stay as before. This change reduces one source of disk stalls. The existing crash-recovery mechanism remains in use.

Linked Issue

Maintainer work from the native-chat performance investigation; no separate issue.

Visual Proof

Main-versus-final signed-in Claude Electron screenshots on M4Air are attached to the review status comment: streamed reply, send while streaming, approval, Stop, restart and a folder workspace. Codex drove the hidden app after Grok was unavailable.

Testing

  • Integrated production-journal test verifies NORMAL for a later text revision, FULL for image completion and removal and for adding or removing message metadata, and restoration of FULL after success and rollback.
  • Narrow fix and the single main merge committed with the normal hooks; final diff adds 97 production lines and 81 test lines.
  • Windows high-spec timing against main: mean time spent committing each streamed revision fell from 0.935–0.953 ms to 0.057–0.061 ms across 100/1,000 prior items and 1/10 chats. Sends and approval controls retained FULL. Both targeted test files passed, 87 tests total. This measures database work, not visible UI latency.
  • Final-head signed-in Claude Electron comparison passed: streaming, queued send, actual Write approval, Stop, restart and a folder workspace. The saved rows survived restart unchanged; sends, approvals and control rows stayed FULL. Screenshots are in the review status comment.
  • Full PR workflow passes on c527fefe8a2, including the PR checks passed aggregate.

Linux timing was not run: the shared Linux box had memory available but no prepared checkout and dependencies for one light job. No power-loss test or real Codex eligibility measurement is claimed.

Review

The journal runs on the machine executing the agent, including SSH hosts. Folder workspaces use the same implementation. Existing clients and servers exchange unchanged saved rows and messages. The accepted crash case for a paired device is described above. Replies with much thinking and pauses during periodic database flushes can retain their current cost.

Agent skill upstream boundary

  • Not applicable; no upstream skill-installer material copied.

Notes

Author: @BrennanKB5

Checklist

  • Focused change with the user-facing before/after, mechanism and alternatives explained.
  • Cross-platform, SSH, folder workspaces and mixed-version clients considered.
  • Review loop, final-head QA, timing and CI complete.

@brennanb2025

brennanb2025 commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor Author

Saving every streamed reply update used to force a disk flush on Orca’s main thread, delaying the app on slow or busy disks. This change reduces that blocking for revisions of existing reply text while sends, approvals, Stop and other actions keep their existing save guarantees.

The review loop finished on c527fefe8a2db5a89d1a309834131ce7310e63e7: independent correctness and architecture reviews, three design verdicts, the readiness checklist, and bounded verification of the fixes and single main merge. The fixes keep image transitions and message metadata changes on the stronger save setting; ownership and turn attribution must also stay unchanged. No saved format or messages exchanged between devices change.

Accepted limit: after an operating-system crash or power loss on the machine running the agent, recent reply text can be missing from the saved chat. A second device that stayed connected can keep extra text or miss the recovered ending until the chat is reopened. There is no new time limit on possible text loss. An app crash or force-quit preserves committed updates. Intended difference from the common pattern: Orca keeps the strongest save setting, FULL, for sends and control facts. Thinking updates, tools, first saves and existing checkpoint pauses retain their current cost.

Windows high spec (native Node 24, Samsung NVMe) compared main be033c2ab22d with this exact final head, using the production journal and unchanged fixture: 100/1,000 prior items per chat, 1/10 chats, 256 growing text revisions per chat.

Prior items / chats Mean COMMIT, main → final p99 COMMIT, main → final
100 / 1 0.938 → 0.060 ms 1.258 → 0.121 ms
100 / 10 0.953 → 0.057 ms 1.803 → 0.766 ms
1,000 / 1 0.939 → 0.060 ms 1.792 → 1.096 ms
1,000 / 10 0.935 → 0.061 ms 1.784 → 0.758 ms

Total production append time improved 88.1–91.1% by mean. These tight-loop measurements on a shared machine do not measure visible UI latency. Send, pending dispatch and pending/resolved approval controls all remained FULL; streamed revision controls used FULL on main and the lighter setting, NORMAL, here. Both targeted files passed, 87 tests. All 125 evidence hashes and eight timing/control cells were verified after collection.

The full PR workflow passed on this exact head, including its PR checks passed aggregate, all five test shards, Windows packaging and cross-version compatibility. Main was merged once after review fixes. The PR is out of draft, has no unresolved review threads, and GitHub reports CLEAN.

Real signed-in Claude Electron QA passed on M4Air, with Codex driving hidden renderers after Grok was unavailable. The same main/final prompts covered streaming, sending while streaming, an actual Write approval, Stop, restart, setup/default tabs and a plain folder workspace. No functional difference was observed in those flows. Main retained all 69 saved rows unchanged across restart; final retained all 72. The final app recorded 30 lighter reply-text saves and 53 FULL saves; all 80 observed main saves were FULL. These counts are evidence from this Claude run, not a prediction for other agents or workloads.

Test isolation kept real Claude settings and Codex hook hashes unchanged. All recorded test apps and transfer processes exited; both remote worktrees and this run’s scratch profiles were removed after evidence collection. One initial final-head launch incorrectly continued at load 55.26 because the scratch preflight only printed resources; it was stopped before any final flow and contributed no saved rows. A rejecting guard was added before the valid launch (load 11.42, 64% memory free) and restart (5.96, 48% free). Preparation notices and existing naming/notification warnings were recorded; no unrelated source change was made.

No open blocking review finding remains. Deferred: performance of thinking updates and periodic database flushes, plus measuring how often real Codex output qualifies for the lighter save setting. These keep their existing behavior.

Not measured: power loss, real Codex eligible-save fraction, reasoning-heavy or many-block workloads, or Linux timing. The shared Linux box had memory headroom but no prepared dependencies for one light run; no installation or timing job was added. Thinking and checkpoint performance are unchanged and remain outside this change.

For Brennan’s review

Whole-window main/final comparisons. Generated wording and elapsed labels differ naturally; the final run also shows an existing education prompt in some frames.

Flow Main Final
Setup and default tabs Main: Setup and default tabs Final: Setup and default tabs
Streamed reply Main: Streamed reply Final: Streamed reply
Send while streaming Main: Send while streaming Final: Send while streaming
Queued send completed Main: Queued send completed Final: Queued send completed
Write approval Main: Write approval Final: Write approval
Approval completed Main: Approval completed Final: Approval completed
Stop → Interrupted Main: Stop → Interrupted Final: Stop → Interrupted
Restart retained history Main: Restart retained history Final: Restart retained history
Folder workspace Main: Folder workspace Final: Folder workspace

Judgment points:

…ant text

Every chat-journal commit ran a full fsync on the main thread. Replace the earlier allowlist of FULL rows (which missed control facts riding generic rows) with the inverse: FULL stays the default, and a transaction commits at NORMAL only when every row is a later revision of an assistant message that changes nothing but its content. An OS crash can lose only that streamed text; the next FULL commit makes it durable.
@brennanb2025
brennanb2025 marked this pull request as ready for review October 16, 2026 21:31
@coderabbitai

coderabbitai Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 98b5d8d2-ed33-4311-aa4f-2486e1e19f79
📥 Commits

Reviewing files that changed from the base of the PR and between 272082a and c527fef.

📒 Files selected for processing: 2
  • src/main/native-chat/agent-session-journal/journal-streamed-text-revision.test.ts
  • src/main/native-chat/agent-session-journal/journal-streamed-text-revision.ts
🚧 Files skipped from review as they are similar to previous changes: 2
  • src/main/native-chat/agent-session-journal/journal-streamed-text-revision.test.ts
  • src/main/native-chat/agent-session-journal/journal-streamed-text-revision.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.

📝 Walkthrough

The journal adds a predicate that identifies eligible streamed-text revisions. The row writer uses the predicate and hook or receipt conditions to select streamed transactions. Streamed transactions set SQLite synchronous mode to NORMAL and restore FULL when no transaction remains open. Tests check synchronous-mode changes, restoration after rollback, and commit-time synchronous levels.

Priority: ➖ Normal

Merge Risk: 🟡 Moderate · up to c527f

After an OS crash, a reconnecting client can miss replacement reply text and remain stale. Preserve replay positions across recovery or retain FULL durability before merging.

Pre-merge checks: Passed 3 · Failed 2

Failed Failed checks: 2 warnings

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 5 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check Warning The description is detailed and covers the main template sections, but it does not provide the required linked issue. It also reports validation results that conflict with the objectives, which state … Add a valid linked issue, or document the maintainer exception if applicable. Reconcile the testing and readiness claims with the current head, conflicts, and outstanding checks described in the review record.
Passed Passed checks: 3 passed
Check name Status Explanation
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Title check Passed The title clearly identifies the main change: reducing flushes for streamed text revisions while preserving send transaction behavior.
Full details: Description check

Explanation

The description is detailed and covers the main template sections, but it does not provide the required linked issue. It also reports validation results that conflict with the objectives, which state that current-head checks and review remain outstanding.

Resolution

Add a valid linked issue, or document the maintainer exception if applicable. Reconcile the testing and readiness claims with the current head, conflicts, and outstanding checks described in the review record.

  • Fix all pre-merge checks with AI
✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 19ba9cfa-eb16-48f9-a922-f70334c83ef1
📥 Commits

Reviewing files that changed from the base of the PR and between d717798 and 097673e.

📒 Files selected for processing: 5
  • src/main/native-chat/agent-session-journal/journal-host-database.ts
  • src/main/native-chat/agent-session-journal/journal-row-writer.ts
  • src/main/native-chat/agent-session-journal/journal-store-collaborators.ts
  • src/main/native-chat/agent-session-journal/journal-streamed-text-revision.test.ts
  • src/main/native-chat/agent-session-journal/journal-streamed-text-revision.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 94d52911-df91-4812-9b2b-1eb716a1b683
📥 Commits

Reviewing files that changed from the base of the PR and between 097673e and 272082a.

📒 Files selected for processing: 3
  • src/main/native-chat/agent-session-journal/journal-store-collaborators.ts
  • src/main/native-chat/agent-session-journal/journal-streamed-text-revision.test.ts
  • src/main/native-chat/agent-session-journal/journal-streamed-text-revision.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.

@brennanb2025
brennanb2025 merged commit b7f6e71 into main Oct 16, 2026
31 checks passed
brennanb2025 added a commit that referenced this pull request Oct 16, 2026
main's #28966 lets a journal transaction commit streamed rows without the per-commit fsync;
this PR's background writes ride the same transaction. The two are one options object
(`{ background?, streamed? }`), so a background streamed write is both.
@brennanb2025
brennanb2025 deleted the brennanb2025/nc-perf-sync branch October 17, 2026 00:47
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