Skip to content

fix: batch status recovery snapshots at bounded intervals - #26735

Closed
1aifanatic wants to merge 1 commit into
stablyai:mainfrom
1aifanatic:fix/batch-status-recovery-writes
Closed

1aifanatic wants to merge 1 commit into
stablyai:mainfrom
1aifanatic:fix/batch-status-recovery-writes

Conversation

@1aifanatic

Copy link
Copy Markdown
Contributor

ELI5

Frequent status updates no longer rewrite the entire restart-recovery file after every short pause. Orca saves the latest snapshot at most once per five-second window during normal activity, and still saves immediately when shutting down.

What Changed

Keep the first scheduled write deadline instead of resetting a 250 ms timer on each event. The five-second window batches updates without letting continuous activity postpone the snapshot indefinitely. Serialization, atomic replacement and identical-snapshot suppression stay in the existing persistence path.

Why

Restart recovery does not need a disk write for each status event. A bounded timer fixes the write amplification without introducing a journal, changing the file format, or adding asynchronous-write/shutdown races. Live status notifications are still immediate.

Linked Issue

Fixes #26720

Visual Proof

N/A — background recovery-file scheduling only; no visual or interaction change.

Testing

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

Windows, Node 24.21.0, ORCA_BACKGROUND_LAUNCH=1: 82 tests pass across nine persistence, hydration and hook-control suites. The new regression fails before the change. It sends real HTTP hook events every 500 ms, verifies no intermediate snapshot replacement, checks that the latest state is persisted at five seconds, and checks a subsequent window. Shutdown coverage verifies the pending state is written and the timer is cancelled.

Command: node node_modules/vitest/vitest.mjs run --config config/vitest.config.ts --maxWorkers=2 src/main/agent-hooks/server-last-status src/main/agent-hooks/server-status-persist-scheduling.test.ts src/main/agent-hooks/managed-agent-hook-controls.test.ts.

Formatting and pnpm run check:code-quality:changed pass. Full lint/typecheck/test/build are not verified locally: the native Windows build toolchain is missing and full typechecking exceeded available resources during earlier validation. CI and native macOS/Linux coverage remain outstanding.

AI Disclosure

GPT-6 was used to investigate, implement, test and review this change.

Review

The timer remains owned by each execution-host server instance and uses platform-neutral timers. Local and remote status producers still write through the same store; clients and wire formats are unchanged. No integration-specific logic, UI changes, Git-worktree assumptions, dependencies, or additional periodic wakeups. Identical snapshots still skip disk I/O, and atomic writes and existing file permissions remain intact. Unexpected termination can lose up to one pending five-second window; normal shutdown flushes immediately.

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

The five-second interval bounds the scheduled delay while the event loop is responsive. Synchronous snapshot writes remain; this change reduces their frequency.

Author

X: @1aifanatic

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • 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 (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@coderabbitai

coderabbitai Bot commented Oct 9, 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: c0ee12a7-f8ac-41eb-b623-cedc7f0c3d9a
📥 Commits

Reviewing files that changed from the base of the PR and between 13c9f1f and d82491b.

📒 Files selected for processing (4)
  • src/main/agent-hooks/server-status-persist-scheduling.test.ts
  • src/main/agent-hooks/server/server-constants.ts
  • src/main/agent-hooks/server/server-persistence.ts
  • src/main/agent-hooks/server/server-state.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

Walkthrough

The persistence interval changes from a 250 ms trailing-edge debounce to a fixed five-second interval that is not reset during continued activity. Tests check that the latest status is saved at the interval boundary, that later updates are saved on a subsequent interval, and that shutdown saves pending status and clears scheduled timers.

Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to d8249

Status snapshots are batched into five-second windows while shutdown still flushes pending state. Abrupt termination may lose one pending window, as described for this change; no actionable merge-blocking risk is established by the supplied evidence.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 4 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: batching status recovery snapshots at bounded intervals.
Description check Passed The description includes the required sections, linked issue, behavior changes, rationale, testing details, limitations, AI disclosure, and checklist context. It clearly states that full validation re…
Linked Issues check Passed The PR addresses the active direct issue [#26720]. It replaces the resetting 250 ms debounce with a fixed five-second recovery-write deadline, so ongoing hook activity does not postpone persistence in…
Out of Scope Changes check Passed The reported changes stay within [#26720]. The constant update, scheduler change, state comment, and scheduling tests directly support bounded status persistence and shutdown behavior. No unrelated pr…
  • Fix all pre-merge checks with AI
  • Autopilot · 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.

@nwparker

Copy link
Copy Markdown
Contributor

Closing as not planned. This reduces writes by extending the recovery deadline from 250 ms to five seconds, so an isolated completion/prompt/authority update can remain undurable twenty times longer. Normal shutdown flushing does not preserve crash recovery. We require behavior-preserving performance improvements, so this intended durability trade-off fails the bar. The underlying write-amplification observation remains valid.

@nwparker nwparker closed this Oct 11, 2026
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.

[Bug]: agent-hooks/last-status.json is rewritten whole on almost every hook event (about 53 times a minute)

2 participants