Skip to content

fix(agent-hooks): let the last-status throttle apply to routine hook events - #39826

Merged
nwparker merged 2 commits into
mainfrom
nwparker/last-status-write-throttle
Nov 8, 2026
Merged

nwparker merged 2 commits into
mainfrom
nwparker/last-status-write-throttle

Conversation

@nwparker

@nwparker nwparker commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

Orca saves a small file about running agents. It's meant to save at most every 5 seconds while agents are busy, but it was saving after every single tool call. This makes the 5-second limit work as intended.

Files Added Deleted Net
Test 0 0 0 0
Prod 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​18 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​16

What Changed

  • RevisionedMap.setIfChanged stores the new value but bumps the revision only when the value actually differs.
  • recordCurrentAuthorityObservation now uses it, comparing with the existing authorityCommitmentsMatch (launch token, connection, tab, worktree). observedAt still updates in place, so hydration's TTL check sees fresh timestamps.

Why

#26822 added a 5s leading-edge throttle for last-status.json, with an immediate write when pane authority changes. "Authority changed" is detected through a fingerprint built from the revision counters of persistedAuthorityCommitmentsByPaneKey and hydratedLaunchTokenHashByPaneKey. Every hook event re-set both maps, so the revisions moved on every event, every write counted as urgent, and the throttle never applied.

In one local profile with many agents running, the file (~186 KB) was being rewritten about twice a second. Real authority changes (new launch, rebind, cleanup) still write immediately.

Linked Issue

N/A (found while profiling disk writes locally)

Visual Proof

N/A: no UI change; only how often a file is written.

Testing

  • Review reproduced two timer-racy write-count assertions in the added tests; removed those assertions/tests under the repository test policy.
  • Existing persistence throttle, nonblocking quit flush, pane authority, and hydration confirmation/validation coverage: 21 tests passed across 5 files on macOS.
  • pnpm check:changed: all 20 non-test checks passed. Stopped its overbroad related-test selection after ~3 minutes; focused tests above passed. Full PR CI is required before merge.

…events

Each hook event re-recorded the pane's authority evidence, which bumped the
revision counters behind the "urgent persist" fingerprint even when only
observedAt moved. Every event then skipped the 5s throttle and rewrote
last-status.json. Update the stored evidence without bumping the revision when
the authority itself (launch token, connection, tab, worktree) is unchanged.
@coderabbitai

coderabbitai Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

RevisionedMap adds setIfChanged, which stores a value without advancing its revision when the existing value matches. Authority observations use this method for authority commitments and hydrated launch-token hashes. Tests check snapshot-writer calls for repeated hooks, synchronous flush behavior, and a changed launch token.

Merge Risk: Minimal · up to 4ebc0

No material merge-blocking regression is established in the changed authority-observation path.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Description check Warning The description has a clear ELI5, a What Changed section, and a Why section that explains the throttle bypass and the local profiling result. Visual Proof is marked N/A with a reason. Testing lists wh… Add a Risk section with a level (Low, Medium, or High), the riskiest part of the change, what users would see if it failed, and how to back it out (revert, plus any data the revert would not undo). Add a Linked Issue, or confirm the author …
Passed Passed checks: 4 passed

Check name Status Explanation
Title check Passed The title names the mechanism and the scope of the change: it makes the existing last-status throttle apply to routine hook events. The changeset matches this. setIfChanged in RevisionedMap and its us…
Docstring Coverage Passed No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
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: Title check

Explanation

The title names the mechanism and the scope of the change: it makes the existing last-status throttle apply to routine hook events. The changeset matches this. setIfChanged in RevisionedMap and its use in recordCurrentAuthorityObservation stop routine hook events from bumping the revision counters that drive the urgent-write fingerprint. The title uses the fix(scope) convention and is 75 characters long, which is within a normal length. It does not name the specific mechanism (revision counters), but it is accurate and specific.

Full details: Docstring Coverage

Explanation

No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 0 functions across 3 files.

Full details: Description check

Explanation

The description has a clear ELI5, a What Changed section, and a Why section that explains the throttle bypass and the local profiling result. Visual Proof is marked N/A with a reason. Testing lists what ran (21 tests on macOS, pnpm check:changed) and admits removed assertions, but the template's checkbox items are not ticked and there is no Linked Issue (marked N/A, which the template says must be an actual issue for outside contributors). There is no Risk section with a level or a rollback note, no Cross-platform or SSH note, no Review or Agent skill upstream confirmation, and no AI Disclosure. The description covers the core intent, but several required sections are missing.

Resolution

Add a Risk section with a level (Low, Medium, or High), the riskiest part of the change, what users would see if it failed, and how to back it out (revert, plus any data the revert would not undo). Add a Linked Issue, or confirm the author is a maintainer who needs no issue. Replace the N/A with an actual issue reference if one exists. State cross-platform and remote SSH impact; the PR is macOS-only, so say whether Linux and Windows were considered. Fill in the AI Disclosure section if AI tools were used, or confirm the author is an internal contributor. Address the Agent skill upstream boundary checkbox. Tick the testing checkboxes that apply, and confirm the new tests fail without the change. Clarify the testing section: the removed timer-racy assertions mean the new burst and launch-token cases lack a stated pass result on their own, so say whether they pass with the change.

Finishing Touches

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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c6337892-4c0a-4227-82b2-24490ab047d9
Commits

Reviewing files that changed from the base of the PR and between b4a522d and 4ebc0f8.

Files selected for processing: 3

  • src/main/agent-hooks/server-status-persist-nonblocking.test.ts
  • src/main/agent-hooks/server/revisioned-map.ts
  • src/main/agent-hooks/server/server-authority-evidence.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.

@nwparker
nwparker merged commit 00d3e44 into main Nov 8, 2026
42 checks passed
audichuang pushed a commit to audichuang/orca that referenced this pull request Nov 8, 2026
…events (stablyai#39826)

* fix(agent-hooks): let the last-status throttle apply to routine hook events

Each hook event re-recorded the pane's authority evidence, which bumped the
revision counters behind the "urgent persist" fingerprint even when only
observedAt moved. Every event then skipped the 5s throttle and rewrote
last-status.json. Update the stored evidence without bumping the revision when
the authority itself (launch token, connection, tab, worktree) is unchanged.

* test(agent-hooks): remove timer-racy persistence count assertions

(cherry picked from commit 00d3e44)
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