Skip to content

perf(persistence): persist a matching terminal binding without re-applying it - #31033

Merged
AmethystLiang merged 3 commits into
mainfrom
perf-binding-design
Oct 20, 2026
Merged

AmethystLiang merged 3 commits into
mainfrom
perf-binding-design

Conversation

@AmethystLiang

@AmethystLiang AmethystLiang commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​289 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​288
Prod 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​73 $\color{#cf222e}{\Huge{\mathbf{−}}}$​26 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​47

ELI5

When a terminal reattaches and Orca already knows the right answer, it was still making two full backup copies of your whole saved session "just in case it had to undo", then saving. Now it skips the pointless copies and just saves.

What Changed

Before: a terminal reattach whose binding already matched memory, but whose session had not yet reached disk (for example, right after an unrelated settings edit), was treated like a real change. It scanned for conflicts, cloned the whole selected-host session, re-applied equal values, and cloned it again to keep for rollback.

After: that case is recognised as "already correct, only needs saving". It marks the selected session domain dirty and lets the existing writer persist it. No apply, no conflict scan, and no binding snapshots. Anything that actually changes a binding takes the old path unchanged.

Mechanism:

  • pty-binding-fast-lane.ts: new defaults_not_applied miss, so a binding without the defaults guard still goes through the repair path (clean and dirty requests alike).
  • pty-binding-persistence.ts + new pty-binding-durability-only.ts: when the only miss is not_durable, mark workspaceSession (local) or workspaceSessionsByHostId (SSH/runtime) dirty and return a success result with a no-op rollback. The no-op rollback keeps the writer's failure publication to listeners without restoring anything.
  • pty-binding-owner-conflict-report.ts: the existing report-only conflict scan, moved out unchanged to keep pty-binding-persistence.ts under the line limit.
  • pty-binding-span.ts: bounded binding.path attribute (durable_match, durability_only, mutation); successful dirty matches share the existing sampling budget with clean fast-lane hits.

Unchanged: the writer, queue, generation semantics, serializers, notification order and scope, finalization, and actual-mutation rollback.

Why

The cost scales with total session size, not with the one terminal being reattached, because both snapshots clone every workspace and every saved scrollback buffer, and both stay alive for the whole disk wait.

Alternatives not taken: awaiting pendingWrite (it swallows errors and may cover older work, so it could acknowledge a binding that was never saved) and enqueueing a flush from inside the operation (it would wait behind itself). Reusing the existing in-operation capture keeps the writer's failure and acknowledgement result.

Measured impact

Final A/B on a real profile. A copy of one developer's current profile: a 7.4 MB local session with 1080 workspaces, plus 7 remote host partitions (2.4 MB). It runs through the real persistPtyBinding, writer worker and SQLite. Baseline is the merge-base 99e91c16aef against this PR at 9265cd5, as 6 alternating pairs of 40 trials each; numbers are medians across runs. The later commits only rebase the branch and move the dirty-marking helper and the real-mutation rollback's owner check, neither of which the measured save-only path runs.

Local reattach, binding already correct, unrelated settings dirty:

Before After
Main-thread time in the binding operation 124 ms (runs 67–161) 0.06 ms
Of which, copying the whole session 121 ms (2 copies) 0 (no copies)
Reattach completion, p50 180 ms 62 ms
Reattach completion, p95 250 ms 76 ms
100 reattaches back to back 197 ms 63 ms
Temporary memory per reattach about 239 MB about 34 MB
Writes / data written 1 / 7.1 MB 1 / 7.1 MB

Reattach on one of that profile's real SSH partitions: the partition is small, so main-thread time goes from 2.6 to 0.04 ms, and completion time does not change (about 18 ms either way).

So the gain is about 120 ms less main-thread blocking and about 120 ms faster completion per local reattach on a large session. The disk write is unchanged and is what remains. Small sessions and small remote partitions see little difference.

Real use. The same machine, read from local persistence.pty-binding trace spans. Span time includes the disk write and queue waits behind other pending writes.

Already-correct reattach that needs saving Spans p50 p90 Worst
Older builds, previous 6 days 441 295 ms 639 ms 4.9 s
Same day, official hourly build without this change 6 196 ms 261 ms 261 ms
Same day, builds with this change 24 172 ms 249 ms 311 ms
  • Routing: every reattach took the save-only path or the existing no-write path, and only genuinely new terminals took the full mutation path.
  • Sample size: the real-use samples are too few to confirm the controlled result. In live use these spans also wait behind other writes, so their absolute times are higher than the A/B's.
  • Excluded: one 690 s new-terminal span that began one second before macOS slept the machine.

Not measured: Electron-hosted runs. Event-loop delay could not be sampled from the vitest worker, so main-thread time is measured directly around the binding operation instead. The benchmark harness is not part of this PR.

Linked Issue

N/A. Maintainer performance work, no pre-existing issue.

Visual Proof

N/A. No UI or interaction change; this is persistence-internal.

Testing

  • pnpm tc:node, pnpm lint, and pnpm run check:code-quality:changed pass.

  • Tests pass for the fast-lane predicate, flush and save scheduling, durable writes (including the new matching-durability suite), maintenance contracts, host-partitioned SSH bindings, SSH replay, and the binding span.

  • New coverage: defaults-guard miss on clean and dirty requests; a dirty match on local and SSH hosts clones nothing and ends up durable; getter edits with settings-only dirty intent are captured under paused acknowledgement; later state and failure publication are preserved; span sampling keeps failures and refusals.

  • Platforms: persistence logic only, with no path or process handling, so it is platform-independent. SSH and runtime partitions are covered by tests. I did not launch the app.

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

Notes

  • Security: no new data leaves the process; span attributes stay low-cardinality with no ids or paths.
  • Remote SSH / folder workspaces: host partitions stay separate; folder-workspace ids are matched exactly.
  • Backwards compatibility: no persisted-schema, wire, or RPC change.

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered
  • pnpm lint, pnpm typecheck, and the relevant tests pass locally

@coderabbitai

coderabbitai Bot commented Oct 20, 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: 4b164b83-4fa3-40eb-bafb-c4f3dbba8558
📥 Commits

Reviewing files that changed from the base of the PR and between 9265cd5 and 57ebeb2.

📒 Files selected for processing: 2
  • src/main/persistence/loading-store/pty-binding-persistence.ts
  • src/main/persistence/loading-store/pty-binding-write-rollback.ts

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

📝 Walkthrough

PTY binding persistence now distinguishes durable matches, durability-only matches, and mutations. It checks that terminal defaults were applied before allowing fast-lane eligibility. Durability-only matches mark the relevant session domain dirty without changing the binding. Persistence spans classify the path and apply sampling to frequent outcomes. Rollback checks current ownership and binding metadata against staged values. Tests cover host-specific persistence, deferred writes, failure publication, and span sampling.

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to 57ebe

The reviewed persistence path writes matching bindings and reports write failures. No identified issue blocks merging after normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

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 12 functions across 12 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the primary optimization: persisting an already matching terminal binding without reapplying it.
Description check Passed The description is detailed and covers the user impact, mechanism, rationale, measurements, testing, compatibility, security, and platform considerations. It marks visual proof as not applicable and e…
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.
Full details: Description check

Explanation

The description is detailed and covers the user impact, mechanism, rationale, measurements, testing, compatibility, security, and platform considerations. It marks visual proof as not applicable and explains why. The Linked Issue field uses the documented maintainer exception, and omitted AI Disclosure and Agent skill boundary sections are non-critical in this context.

✨ 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.

…lying it

A reattach whose binding already matches memory but is not yet on disk now
only marks the selected session domain dirty and relies on the writer to
persist it, instead of cloning the whole session twice for rollback and
re-applying equal values. Adds a defaults-guard miss to the fast-lane
predicate and a binding.path span attribute.
@AmethystLiang
AmethystLiang merged commit 177acb8 into main Oct 20, 2026
47 checks passed
brennanb2025 added a commit that referenced this pull request Oct 20, 2026
Main's layout-owner groundwork (#31130, #31171, #31187, dark) and the binding
fast lane (#31033) touched the same files. Binding retirement keeps this
branch's incarnation fence and uses main's dirty marking; a failed start keeps
its pane for main's keep-on-failure starts and for owner contention; the fresh
launch path takes main's pane start status arguments.
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