Skip to content

refactor(agent-status): isolate legacy status ingress behind one admission point - #20716

Merged
brennanb2025 merged 2 commits into
mainfrom
brennanb2025/pr2a-1-legacy-ingress-isolation
Sep 15, 2026
Merged

brennanb2025 merged 2 commits into
mainfrom
brennanb2025/pr2a-1-legacy-ingress-isolation

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 10 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​431 $\color{#cf222e}{\Huge{\mathbf{−}}}$​24 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​407
Prod 17 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​704 $\color{#cf222e}{\Huge{\mathbf{−}}}$​45 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​659

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.ts passes 12/12 here, which is the check that matters, because
an 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 tc clean and the existing structured-ingress suite 12/12 — both run independently by the
coordinator 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: main is currently red on audit:code-quality:native from three pre-existing
no-conditional-tests warnings in mobile test-support files, fatal under --deny-warnings. Inherited
by every PR linted against the merge ref; this branch touches no mobile files.

@coderabbitai

coderabbitai Bot commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

📝 Walkthrough

Walkthrough

The 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 beb63

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)

Check name Status Explanation Resolution
Description check ⚠️ Warning 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 com… 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 re…
Docstring Coverage ⚠️ Warning Docstring coverage is 11.76% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 34 functions across 27 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: isolating legacy agent-status writes behind one admission point.
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 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.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

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: aa4fae1d-cdba-4da7-8b9b-b58aee351df9

📥 Commits

Reviewing files that changed from the base of the PR and between 4a02762 and a1a7d05.

📒 Files selected for processing (27)
  • src/main/agent-hooks/manual-compact-hook-stream.test.ts
  • src/main/agent-hooks/server-authority-evidence.test.ts
  • src/main/agent-hooks/server-ingest-remote.test.ts
  • src/main/agent-hooks/server/server-authority-aliases.ts
  • src/main/agent-hooks/server/server-cleanup.ts
  • src/main/agent-hooks/server/server-hydration.ts
  • src/main/agent-hooks/server/server-ingest-remote.ts
  • src/main/agent-hooks/server/server-reaping.ts
  • src/main/agent-hooks/server/server-status-update.ts
  • src/main/agent-hooks/terminal-handle-row-identity.test.ts
  • src/main/agent-hooks/wsl-hook-relay-deps.ts
  • src/main/claude/compact-status-registration.test.ts
  • src/main/ssh/ssh-relay-session.ts
  • src/relay/agent-hook-server.ts
  • src/shared/agent-hook-listener-extraction-characterization.test.ts
  • src/shared/agent-hook-listener-test-harness.ts
  • src/shared/agent-hook-listener/listener-state.ts
  • src/shared/agent-hook-status-cache.test.ts
  • src/shared/agent-hook-status-cache.ts
  • src/shared/agent-status-legacy-adapter.test.ts
  • src/shared/agent-status-legacy-adapter.ts
  • src/shared/agent-status-legacy-ingress-manifest.ts
  • src/shared/agent-status-legacy-ingress-ratchet.test.ts
  • src/shared/agent-status-legacy-relay-cache.ts
  • src/shared/agent-status-legacy-source-scan.ts
  • src/shared/agent-status-serving-readiness.test.ts
  • src/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)

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.

🗄️ 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.

Suggested change
entries.set(movedKey, value)
const movedValue = { ...value, paneKey: movedKey }
freezeStatusEntry(movedValue)
entries.set(movedKey, movedValue)

@pullfrog pullfrog 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.

ℹ️ 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 — lastStatusByPaneKey becomes a ReadonlyMap view over a WeakMap-attached adapter, and every write now goes through admitLegacyAgentStatus with 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 + evictCachedPanesOverCap replaced by cacheRelayLegacyAgentStatus (admit moveToEnd, then evict over MAX_CACHED_PANES).
  • Remote peer gate — ingestRemote gains 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.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

) {
return false
}
while (state.lastStatusByPaneKey.size > maxPanes) {

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.

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(

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.

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.

@pullfrog pullfrog 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.

ℹ️ 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 — ingestRemote now reads envelope.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_CAPABILITIES binding, which a stray bare import can no longer satisfy.
  • Fail-closed test added — a new ingestRemote case 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.

Pullfrog  | Fix it ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@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: 6d8851cc-736a-4629-b609-b1214cff436a

📥 Commits

Reviewing files that changed from the base of the PR and between a1a7d05 and beb63ee.

📒 Files selected for processing (6)
  • src/main/agent-hooks/server-ingest-remote.test.ts
  • src/main/agent-hooks/server/server-ingest-remote.ts
  • src/main/agent-hooks/wsl-hook-relay-deps.ts
  • src/main/ssh/ssh-relay-session.ts
  • src/shared/agent-status-legacy-adapter.ts
  • src/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.

Comment on lines +122 to +123
expect(stripComments(caller.source)).toMatch(
/advertisedAgentStatusCapabilities\s*:\s*AGENT_STATUS_LEGACY_UNADVERTISED_PEER_CAPABILITIES\b/

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.

🗄️ 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.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Re-review of the fix commit (beb63eefca)

This PR pulls every legacy agent-status write behind one admission point (ingestRemote) so a later PR can put a real contract on that door — deliberately behavior-preserving, no user-visible change. The original review declared the design clean at a1a7d05584. That commit turned out to be self-contradictory: it added a third positional argument to ingestRemote (advertisedAgentStatusCapabilities) to satisfy a new ratchet requiring every call site to name its capability source explicitly, but doing so changed call arity, which broke a pre-existing SSH integration test that asserted a 2-argument call via toHaveBeenCalledWith (Vitest matches argument count exactly). No combination of {that test, the new ratchet, lint} was satisfiable at once.

beb63eefca fixes this by moving the capability source off the call signature and onto the envelope object instead: ingestRemote now reads envelope.advertisedAgentStatusCapabilities, defaulting to AGENT_STATUS_LEGACY_UNADVERTISED_PEER_CAPABILITIES when absent, and both production callers (SSH relay session, WSL hook relay) stamp that constant onto their envelope literal rather than passing it positionally. Call arity returns to two arguments, so the pre-existing SSH test needed no change. The commit also strengthens the ingress ratchet: it previously only checked that the capability constant's name appeared somewhere in a caller's source (satisfiable by a stray unused import), and now asserts the actual advertisedAgentStatusCapabilities: AGENT_STATUS_LEGACY_UNADVERTISED_PEER_CAPABILITIES key:value binding is present, with comments stripped first.

What I verified, with results

  • Scope: the fix commit touches exactly 6 files (+31/−17), and the diff from the original review commit to the current head (a1a7d05584..beb63eefca) is exactly those same 6 files — nothing else landed on top. Confirmed via git diff on the merge-base range. None of the touched files are the canonical store contract, the child-work record, or the epoch/activation seam that later PRs in this stack own.
  • Only two production callers: grepped the whole tree for .ingestRemote( outside test files — only ssh-relay-session.ts and wsl-hook-relay-deps.ts call it in production code, matching exactly what the ratchet enforces. Every other call site is a test, and all pass the (unaffected) 2-argument form.
  • WSL path doesn't mutate or leak onto the wire: wsl-hook-relay-deps.ts's ingest callback spreads the wire-deserialized notification into a new object (const capped = { ...envelope, advertisedAgentStatusCapabilities: ... }) before stamping the field — the original object is never touched. Traced the call chain up through wsl-hook-relay-link.ts: the raw notification (params) is handed to ingest once and never re-serialized or written back to the mux afterward. No wire exposure, no mutation of the source object.
  • The type assertion is genuinely required, not decorative: this repo runs a dedicated casting gate (config/oxlint-code-quality-casting.json, assertionStyle: "never") that bans every as type assertion repo-wide unless it carries an oxlint-disable-next-line with a SAFETY: rationale. I ran that gate against the new capped as IngestEnvelope line with the disable comment removed — it fails; with the comment present, it passes. I also ran it against the pre-existing cast this replaces (envelope as Parameters<...>[0], present on origin/main before this whole stack, with no disable comment) — it fails the same gate too, but was never caught because the gate only scans changed lines and that line predates it. This PR's edit is the first to touch that line since the gate existed, which is why the new comment had to appear now.
  • The strengthened ratchet actually closes the gap it claims to: it's a plain Vitest test under src/shared/ (not .e2e.), part of the default test/CI run. I ablated the exact bypass it's meant to close — left the capability constant imported and referenced elsewhere (satisfying the old bare substring check) but replaced the real stamped field with a literal [] — and the strengthened assertion correctly failed. Restored, and it's back to 7/7 green.
  • Behavior preservation: canAdmitLegacyAgentStatus / olderPeerAgentStatusLegacyMode themselves are untouched by the fix commit (only a doc comment changed in agent-status-legacy-adapter.ts). Both production callers pass the identical frozen empty-array constant either explicitly or via the default, so the admission decision is identical to origin/main for every input, including the default-vs-explicit path.
  • Test suites: ssh-relay-session-agent-hooks.integration.test.ts + agent-status-legacy-ingress-ratchet.test.ts + server-ingest-structured-status.test.ts together: 29/29 passing (the structured-status file alone is 12/12, as the PR description claims). Full src/main/ssh/ + src/main/agent-hooks/ suites: 247 test files / 3109 tests passing, 3 files / 27 tests skipped, zero failures.
  • Typecheck: pnpm tc (all project typechecks run in parallel) is clean.
  • Changed-code quality gate: check:code-quality:changed — which includes the casting scan and its SAFETY-rationale check — reports 0 new findings across all 27 changed files in the PR.
  • Lockfiles: pnpm-lock.yaml and mobile/pnpm-lock.yaml show no diff against origin/main at this head.

What I could not verify

  • No live SSH or WSL relay session was exercised end-to-end; verification leaned on the unit/integration suites above, which is the surface the PR's own description points at.
  • I ran the specific gates called out by the PR and this fix (changed-code-quality including casting, typecheck, the named suites) rather than the entire pnpm lint pipeline, which also runs unrelated audits.
  • Did not re-check audit:code-quality:native — the PR body already discloses it's red on origin/main from three pre-existing, unrelated warnings in mobile test-support files, and this branch touches no mobile files.

Where to look first

The two-line semantic move in server-ingest-remote.ts — envelope.advertisedAgentStatusCapabilities ?? AGENT_STATUS_LEGACY_UNADVERTISED_PEER_CAPABILITIES replacing the old positional default — and the copy-not-mutate pattern in wsl-hook-relay-deps.ts are the two spots where a subtle behavior change could hide. Both checked out.

Verdict

Ready to merge as far as this pass can tell. The fix resolves the arity/ratchet self-contradiction cleanly, preserves admission behavior exactly, stays inside this PR's stated scope, and every gate I ran — the specified suites, the full ssh/agent-hooks suites, typecheck, and the changed-code-quality gate including casting — is green.

@brennanb2025
brennanb2025 merged commit 9ab0a18 into main Sep 15, 2026
34 checks passed
ivanvykopal pushed a commit to ivanvykopal/orca that referenced this pull request Sep 20, 2026
…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.
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