Repository navigation
refactor(agent-status): isolate legacy status ingress behind one admission point - #20716
Conversation
📝 WalkthroughWalkthroughThe pull request adds a legacy agent-status adapter with admission rules, immutable storage, listing-order tracking, pane moves, and cleanup operations. Listener state and main server status paths now use the adapter instead of direct map mutation. Remote ingestion checks peer capabilities. Relay caching uses centralized admission and eviction. New tests cover adapter behavior, ingress enforcement, capability gating, and adapter-backed test seeding. Priority: ⬇️ Low Merge Risk: ⚪ Minimal · up to Production pane moves preserve the correct destination identity. Only a minor regression-test gap remains, so the change is mergeable after normal checks. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Description checkExplanation The description explains the purpose, scope, behavior-preservation goal, and verification results. However, it omits several required template sections, including What Changed, Linked Issue with a completed issue reference, Visual Proof or an explicit N/A statement, Testing checkboxes, AI Disclosure, Review, Agent skill upstream boundary, Notes, and Checklist. Resolution Complete the required template sections. Add a linked issue after “Fixes #”, add Visual Proof with attachments or exactly “N/A” and a reason, document testing platforms and test commands, complete the required checkboxes, and address the remaining Review, Agent skill upstream boundary, Notes, and Checklist sections.
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: aa4fae1d-cdba-4da7-8b9b-b58aee351df9
📒 Files selected for processing (27)
src/main/agent-hooks/manual-compact-hook-stream.test.tssrc/main/agent-hooks/server-authority-evidence.test.tssrc/main/agent-hooks/server-ingest-remote.test.tssrc/main/agent-hooks/server/server-authority-aliases.tssrc/main/agent-hooks/server/server-cleanup.tssrc/main/agent-hooks/server/server-hydration.tssrc/main/agent-hooks/server/server-ingest-remote.tssrc/main/agent-hooks/server/server-reaping.tssrc/main/agent-hooks/server/server-status-update.tssrc/main/agent-hooks/terminal-handle-row-identity.test.tssrc/main/agent-hooks/wsl-hook-relay-deps.tssrc/main/claude/compact-status-registration.test.tssrc/main/ssh/ssh-relay-session.tssrc/relay/agent-hook-server.tssrc/shared/agent-hook-listener-extraction-characterization.test.tssrc/shared/agent-hook-listener-test-harness.tssrc/shared/agent-hook-listener/listener-state.tssrc/shared/agent-hook-status-cache.test.tssrc/shared/agent-hook-status-cache.tssrc/shared/agent-status-legacy-adapter.test.tssrc/shared/agent-status-legacy-adapter.tssrc/shared/agent-status-legacy-ingress-manifest.tssrc/shared/agent-status-legacy-ingress-ratchet.test.tssrc/shared/agent-status-legacy-relay-cache.tssrc/shared/agent-status-legacy-source-scan.tssrc/shared/agent-status-serving-readiness.test.tssrc/shared/agent-status-serving-readiness.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 2 remain after this review.
| if (isCanonicalPaneKey(movedKey)) { | ||
| continue | ||
| } | ||
| entries.set(movedKey, value) |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
Update the stored event identity during pane moves.
move() stores value under movedKey, but value.paneKey still contains the old key. After an alias transfer, the view contains a row whose map key and event identity disagree. Relay replay forwards event.paneKey, so it can replay the row under the retired pane identity.
Clone the event with paneKey: movedKey. Freeze the clone before insertion.
Proposed fix
- entries.set(movedKey, value)
+ const movedValue = { ...value, paneKey: movedKey }
+ freezeStatusEntry(movedValue)
+ entries.set(movedKey, movedValue)📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| entries.set(movedKey, value) | |
| const movedValue = { ...value, paneKey: movedKey } | |
| freezeStatusEntry(movedValue) | |
| entries.set(movedKey, movedValue) |
There was a problem hiding this comment.
ℹ️ No critical issues — a couple of minor cleanup notes inline. The behavior-preserving claim looks sound: the new and existing suites pass, no production path mutates a now-frozen row, and the relay refactor has no reachable divergence.
Reviewed changes
- Legacy ingress adapter —
lastStatusByPaneKeybecomes aReadonlyMapview over aWeakMap-attached adapter, and every write now goes throughadmitLegacyAgentStatuswith an explicit caller id and admission mode. - Ingress manifest + serving gate — a frozen manifest enumerates each writable legacy caller with its destination gate and allowed modes; the 2A serving-readiness constant keeps run-serving unadvertised, so all current-producer admissions remain allowed.
- Writer migration — main status/cleanup/hydration/reaping/pane-alias, the shared bounded status cache, and the relay cache admit through the adapter instead of mutating the map directly.
- Relay cache helper — inline delete/set +
evictCachedPanesOverCapreplaced bycacheRelayLegacyAgentStatus(admitmoveToEnd, then evict overMAX_CACHED_PANES). - Remote peer gate —
ingestRemotegains an advertised-capabilities parameter and a fail-closed pre-gate that refuses the legacy writer for run-capable peers. - Ratchet guards — new source-scan tests pin every admission call to the manifest, forbid mutable-map bypasses and indirect admission, and require remote ingress to name its capability source.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
| ) { | ||
| return false | ||
| } | ||
| while (state.lastStatusByPaneKey.size > maxPanes) { |
There was a problem hiding this comment.
This loop duplicates evictCachedPanesOverCap (src/relay/agent-hook-cached-pane-status.ts:48), whose only caller and import this PR removed from agent-hook-server.ts — it is now dead, and its doc comment still describes the old delete-then-set recency. Since src/shared/ cannot depend on src/relay/, the fix is to delete the orphaned helper rather than keep two copies of the same eviction loop.
Technical details
# Remove the orphaned relay eviction helper
## Affected sites
- `src/relay/agent-hook-cached-pane-status.ts:48` — `evictCachedPanesOverCap` now has zero callers (grep finds only its definition).
- `src/shared/agent-status-legacy-relay-cache.ts:25-31` — reimplements the identical `while (size > maxPanes) drop(first)` loop.
## Required outcome
- No exported-but-unused eviction loop, and no stale doc comment claiming writers delete-then-set.
## Suggested approach
- Delete `evictCachedPanesOverCap`; keep the loop here, since `shared/` cannot import from `relay/`.| legacyStatusAdapter(state).move(fromPaneKey, toPaneKey) | ||
| } | ||
|
|
||
| export function getLegacyStatusListingOrder( |
There was a problem hiding this comment.
getLegacyStatusListingOrder and the adapter's listingOrderByPaneKey bookkeeping have no production reader in this PR — only the adapter unit test exercises them. If an upcoming PR in the stack is the first consumer, a short JSDoc naming it would make that explicit; otherwise this is dead surface for 2A.
…nvelope ingestRemote() gained a third positional argument in this PR (advertisedAgentStatusCapabilities) to satisfy a new ratchet requiring every legacy-ingress call site to name its capability source. Both production callers pass the same constant every time, so the argument carries zero runtime information — but Vitest's toHaveBeenCalledWith matches argument count exactly, so the pre-existing SSH relay integration test (which asserts a 2-argument call) started failing even though nothing about the actual admission decision changed. Capabilities are a property of the producing peer/connection, not an orthogonal call parameter, so move the field onto the envelope object instead of adding a third positional argument: ingestRemote reads envelope.advertisedAgentStatusCapabilities (defaulting to the unadvertised-legacy-peer set), and both call sites stamp the constant onto their envelope literal. Call arity stays at two arguments, so the pre-existing evidence test needs no change. The envelope never crosses the wire in either caller: SSH rebuilds it field-by-field from the RPC params, and the WSL path copies (never mutates) the wire-deserialized notification before stamping the field on, so this is purely an internal main-process shape change. Also strengthens the ingress ratchet test that required this: it previously only checked that the capability constant's name appeared somewhere in each caller's source, which a stray unused import could satisfy. It now asserts the actual `advertisedAgentStatusCapabilities: AGENT_STATUS_LEGACY_UNADVERTISED_PEER_CAPABILITIES` key:value binding is present.
There was a problem hiding this comment.
ℹ️ No new issues in this delta. The capability source moved from a third positional argument to a field on the ingest envelope, call arity is back to two, and the ratchet now demands the actual binding rather than a bare name — behavior is unchanged.
Reviewed changes
- Capability source moved onto the envelope —
ingestRemotenow readsenvelope.advertisedAgentStatusCapabilities(defaulting to the unadvertised-legacy-peer set) instead of a third call parameter, restoring 2-argument arity so the pre-existing SSH relay evidence assertion still matches. - Both callers stamp the frozen constant — the WSL path spreads the wire notification into a copy before stamping (never mutating the wire object); the SSH path adds the field to its field-by-field envelope literal.
- Ratchet tightened — the remote-ingress guard now requires the
advertisedAgentStatusCapabilities: AGENT_STATUS_LEGACY_UNADVERTISED_PEER_CAPABILITIESbinding, which a stray bare import can no longer satisfy. - Fail-closed test added — a new
ingestRemotecase admits the older peer's row and drops the run-capable peer's envelope, so the gate is exercised through the envelope field it now reads.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 6d8851cc-736a-4629-b609-b1214cff436a
📒 Files selected for processing (6)
src/main/agent-hooks/server-ingest-remote.test.tssrc/main/agent-hooks/server/server-ingest-remote.tssrc/main/agent-hooks/wsl-hook-relay-deps.tssrc/main/ssh/ssh-relay-session.tssrc/shared/agent-status-legacy-adapter.tssrc/shared/agent-status-legacy-ingress-ratchet.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- src/shared/agent-status-legacy-adapter.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 6 remain after this review.
| expect(stripComments(caller.source)).toMatch( | ||
| /advertisedAgentStatusCapabilities\s*:\s*AGENT_STATUS_LEGACY_UNADVERTISED_PEER_CAPABILITIES\b/ |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win
Bind the capability assertion to the ingestRemote argument.
The test selects callers by .ingestRemote(...) but searches the entire source file. Both callers can retain the same key-value text outside the actual envelope and still pass after removing the field from that envelope. Resolve identifiers such as capped to their object initializers, or use an AST check, then assert the binding on the value passed to ingestRemote.
Re-review of the fix commit (
|
…ssion point (stablyai#20716) * refactor(agent-status): isolate legacy status ingress * fix(agent-hooks): move advertised-capability source onto the ingest envelope ingestRemote() gained a third positional argument in this PR (advertisedAgentStatusCapabilities) to satisfy a new ratchet requiring every legacy-ingress call site to name its capability source. Both production callers pass the same constant every time, so the argument carries zero runtime information — but Vitest's toHaveBeenCalledWith matches argument count exactly, so the pre-existing SSH relay integration test (which asserts a 2-argument call) started failing even though nothing about the actual admission decision changed. Capabilities are a property of the producing peer/connection, not an orthogonal call parameter, so move the field onto the envelope object instead of adding a third positional argument: ingestRemote reads envelope.advertisedAgentStatusCapabilities (defaulting to the unadvertised-legacy-peer set), and both call sites stamp the constant onto their envelope literal. Call arity stays at two arguments, so the pre-existing evidence test needs no change. The envelope never crosses the wire in either caller: SSH rebuilds it field-by-field from the RPC params, and the WSL path copies (never mutates) the wire-deserialized notification before stamping the field on, so this is purely an internal main-process shape change. Also strengthens the ingress ratchet test that required this: it previously only checked that the capability constant's name appeared somewhere in each caller's source, which a stray unused import could satisfy. It now asserts the actual `advertisedAgentStatusCapabilities: AGENT_STATUS_LEGACY_UNADVERTISED_PEER_CAPABILITIES` key:value binding is present.

ELI5
Pulls every status write behind one front door. No behavior changes — same rows, same readers, same
output. It just stops the store being written to from many places at once, so the next PR can put a
real contract on that door.
Why this exists
The agent-status store is being re-keyed so a row identifies the agent rather than the pane it
sits in. That migration needs a single admission point before it can enforce anything. This PR
creates it and moves existing writers onto it, deliberately without changing what they write.
What a reviewer should check first
That it really is behavior-preserving. The honest test is the existing suite, not the new one:
server-ingest-structured-status.test.tspasses 12/12 here, which is the check that matters, becausean earlier version of this exact refactor silently dropped every native-chat row from the host
snapshot while its own new tests still passed. That regression is why this PR is scoped the way it is
— the adapter stays compatible with today's producers, and the rejection of legacy-shaped structured
rows is deferred to the PR that actually moves ownership.
Verification
pnpm tcclean and the existing structured-ingress suite 12/12 — both run independently by thecoordinator on this branch alone, not inherited from the stack. Per-branch ablation, changed-code
quality and formatting gates run by the author.
Scope
First of three. Stack: this → canonical store contract → structured routing. Nothing here is
user-visible.
Note:
mainis currently red onaudit:code-quality:nativefrom three pre-existingno-conditional-testswarnings in mobile test-support files, fatal under--deny-warnings. Inheritedby every PR linted against the merge ref; this branch touches no mobile files.