Repository navigation
fix(agent-status): one revision rule for every teardown marker - #20967
brennanb2025 wants to merge 3 commits into
Conversation
The store's child marker was checked with a plain `has`, so a torn-down child id stayed refused only until compaction evicted the marker and then silently started re-admitting. The verdict depended on store volume, not on the work. The parent side already moved to a revision compare; this brings child, alias and fact onto the same rule. `agentStatusTombstoneFences` is now the only spelling of that rule, called by both admission and state validation for all four entities: a marker fences only writes at or below its own revision, so an absent marker and an older one answer the same and compaction can never change a verdict. What actually fences a delayed observation survives compaction on its own: the lock-step revision envelope refuses any out-of-order mutation, and the live-row lookup answers `unknown-child` for a removed id. The new test ablates the marker and shows both still hold. This also stops a marker latching a reusable provider name. A child work id is minted; a `task_id` is a name later work will use again. The next legitimate occupant of a name is admitted and gets a fresh identity, so it can never be confused with the work that held that name before. No wire or persistence change: snapshot version, mutation shape and tombstone record are untouched, and the same markers are written at the same revisions.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
This PR collapses six hand-written spellings of the teardown-marker rule into one revision-compare helper and fixes the child guard that had drifted to a plain tombstones.has(...).
- Unified rule — new
agentStatusTombstoneFencesinagent-status-store-state.tsreturns true only when a marker exists andmarker.revision >= revision; it is now the only spelling of the rule. - Admission aligned —
upsertParent/upsertChildren/upsertAliases/upsertFactsall call the helper. Parent is behavior-preserving; child moves fromhasto revision compare; alias/fact gain a check that validation already applied, so their outcome is unchanged. - Validation aligned — all four entity loops in
validateAgentStatusStoreStatenow call the helper; parent/alias/fact are equivalent, child is corrected. - Docs — adds a "Teardown markers are bounded records, not authorities" section stating the rule and its two corollaries (a marker is not what fences a delayed observation; a marker may never latch a reusable name).
- Tests — replaces
'never resurrects an exactly removed child id within tombstone retention'with three tests, including one that ablates the marker via compaction and asserts the envelope and live-row lookup still refuse.
I independently reproduced the ablation: restoring main's child admission rule makes exactly one test fail at agent-status-store.test.ts:379 (expected null not to be null), matching the PR description. The focused suites pass (6 files, 38 passed, 1 expected fail), and createAgentStatusStore has no production callers, so the mixed-version replica delta the PR discusses is dormant.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (4)
🚧 Files skipped from review as they are similar to previous changes (1)
Included review availability: Your plan provides up to 10 included reviews per hour; 2 remain after this review. 📝 WalkthroughWalkthroughThe change adds a shared revision-based tombstone fence for parents, children, aliases, and facts. Mutations and state validation use the shared helper. Tests cover child re-addition, tombstone compaction, replica rejection, and fresh identities for reused provider aliases. Documentation defines the bounded tombstone behavior and its revision rules. Priority: ⬇️ Low Merge Risk: ⚪ Minimal · up to The tombstone-compaction documentation and test accurately describe the protections that remain after marker eviction. No unresolved merge-readiness risk remains. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Description checkExplanation The description explains the behavior change, rationale, implementation, compatibility impact, and tests. However, it omits the required Linked Issue section and issue reference, the required checklist sections, and an explicit Visual Proof section with N/A if applicable. Resolution Add the required template sections and complete them. Include a valid issue reference under Linked Issue, state N/A with a reason under Visual Proof if no UI or interaction change exists, complete the testing and checklist items, and address AI Disclosure, Review, Agent skill upstream boundary, Notes, and cross-platform considerations. Full details: Docstring CoverageExplanation Docstring coverage is 12.50% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 3 files. (1 skipped: 1 unsupported.)
✨ 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: 5df40fe4-63ed-4912-994e-9276a59d1f50
📒 Files selected for processing (4)
docs/reference/agent-status-store.mdsrc/shared/agent-status-store-mutation.tssrc/shared/agent-status-store-state.tssrc/shared/agent-status-store.test.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.
| stops working the moment the marker is evicted. | ||
| - **A marker may never latch a name.** A child work id is minted; a provider alias | ||
| (`task_id`, `tool_use_id`) is a reusable name that later, unrelated work will use | ||
| again. Under the revision rule a marker cannot outlive its own revision, so the next |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Correct the marker-compaction terminology.
A tombstone can remain stored after its revision, but it cannot fence a write with a newer revision. After compaction, delayed child reuse remains rejected by revision ordering and live-row lookup, not by a surviving identity fence.
docs/reference/agent-status-store.md#L286-L286: replace the marker-lifetime claim with a statement about the fencing effect ending for newer writes.src/shared/agent-status-store.test.ts#L362-L362: rename the test to describe delayed-admission protection after marker compaction.
📍 Affects 2 files
docs/reference/agent-status-store.md#L286-L286(this comment)src/shared/agent-status-store.test.ts#L362-L362
# Conflicts: # src/shared/agent-status-store-mutation.ts
There was a problem hiding this comment.
Important
The origin/main merge integrates #20718's binding-key rework, and the PR's reused-alias test now fails against it — the store suite is red at head.
Reviewed changes
This run reviewed the incremental delta since the prior pullfrog review: the origin/main merge that adopts #20718's canonical binding keys.
- Binding-key rename absorbed —
upsertAliasesand alias validation now key onserializeAgentChildWorkBindingKeyinstead of the alias-onlyserializeAgentChildWorkAliasKey, matching main's alias-map key. The revision rule and the newagentStatusTombstoneFenceshelper are otherwise unchanged. - Reused-alias test now red — main's new
resolveAgentStatusChildBindingsrefuses the scenario this PR's test expects to be admitted (details inline).
ℹ️ Production consumer invalidates the PR body's dormancy argument
The PR body argues the mixed-version-replica delta is dormant because createAgentStatusStore "has no production callers yet". The merge makes that false: src/main/agent-hooks/server/server-state.ts:65 now constructs a canonical store in authority mode, and server-ingest-structured.ts / server-listeners.ts drive it. The conclusion still holds — no production path uses mode: 'replica' or applyTransportEnvelope, so no live replica consumes these envelopes — but the stated reason needs updating.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
| observedAt: 80, | ||
| fence: { invocationId: 'invocation-2', generation: 1 } | ||
| }) | ||
| ).toMatchObject({ accepted: true, childWorkId: 'minted-2', created: true }) |
There was a problem hiding this comment.
This assertion is red at head. Merging origin/main brought in #20718's resolveAgentStatusChildBindings, which resolves a retired alias binding by alias identity alone and returns the tombstoned record; announceAgentChildWork then sees a non-exact binding and rejects with stale-invocation. A reused alias announced with lifetime: 'current' is deliberately refused on main — proven-new work must declare lifetime: 'proven-new'.
Technical details
# Reused-alias test stale after the #20718 merge
## Affected sites
- `src/shared/agent-status-store.test.ts:455` — expects the second announce to be admitted with `minted-2`.
- `src/shared/agent-status-store-child-queries.ts:24-32` — matches tombstones by `serializeAgentChildWorkAliasKey` (alias identity only), so the retired binding is returned regardless of `childWorkId`/`fence`.
- `src/shared/agent-status-child-work-admission-operations.ts:72-74` — `bindings.length > 0 && exact.length === 0` → `stale-invocation`.
## Evidence
- `npx vitest run src/shared/agent-status-store.test.ts` → 1 failed / 15 passed, failing at line 455 (`expected accepted:false to match { accepted:true, childWorkId:'minted-2', created:true }`).
- Full `agent-status-*` run → 1 failed / 246 passed / 1 expected fail; this is the only failure.
## Required outcome
- The scenario the test names ("a reusable provider name may not latch its slot") stays covered, and the suite is green at head.
## Suggested approach
- Announce the reused alias with `lifetime: 'proven-new'` (main's intended path for new work under a reused alias — see `agent-status-child-work-admission.test.ts`, "mints a distinct id for proven reuse ..."), or otherwise reconcile the test with #20718's binding-lookup semantics.|
Closing: internal refactor with no user-facing change. |

Before / after
The store writes a marker when a parent, child, alias or fact is removed, so a later write can be refused. The rule for how that marker refuses was hand-written six times. Two of the six asked the wrong question.
What changes, measured on
main:task_idwhose previous holder was torn downParent behaviour is unchanged — its existing predicate is what got extracted.
Why
Look at the first two rows. That is the same operation returning opposite answers, decided by how much unrelated traffic the store had seen.
Markers are evicted under
AGENT_STATUS_STORE_LIMITS.tombstones(1024) andAGENT_STATUS_STORE_TOMBSTONE_RETENTION_REVISIONS(4096). So a check written as "a marker exists" silently stops guarding the moment its marker ages out. The guarantee was never enforceable — it just looked enforceable until the store got busy. A guard whose verdict depends on volume is worse than no guard, because nothing signals when it stops working.The fourth row is the same defect with a sharper edge. A
childWorkIdis minted and unique; a provider alias (task_id,tool_use_id) is a name that later, unrelated work will reuse. A marker keyed on a reusable name latches the slot, so the next legitimate occupant of that name is refused permanently. Under the revision rule a marker cannot outlive its own revision, so the next occupant is admitted and gets its own identity — it can never be confused with, or corrupt, the work that held the name before.What actually fences a delayed observation
Not the marker. Two mechanisms that survive compaction do that job:
unknown-childfor a removed id —adopt/resume/reparentshort-circuit there and never consulted a marker at all.The new test ablates the marker and shows both still hold. That is the point of the rule: an absent marker and an older marker give the same answer, so compaction cannot change a verdict.
Because
applyMutationassignsstate.revision + 1andapplyTransportEnveloperequires strictly consecutive revisions, what remains fenced is exactly one thing: a teardown and a re-add inside the same envelope. That is deliberate, and it is what the parent guard has always done.Wire and persistence
No change.
AGENT_STATUS_STORE_SNAPSHOT_VERSIONstays1;AgentStatusStoreSnapshot,AgentStatusStoreMutation,AgentStatusTombstoneRecordandAgentStatusTombstoneEntityare untouched; the same markers are written at the same revisions. Rules 1 and 2 ofdocs/reference/remote-wire-compatibility.mddo not apply — no new field, no new opcode.Rule 3 is the one that could bite, so it is checked directly. The only behavioural delta on the wire is row 1 above: a mutation re-adding an exactly-removed
childWorkIdat a later revision is now admitted where an older replica would refuse it.That is not a live hazard, because no admission path can emit that mutation:
announcemints a fresh id, andadopt/resume/reparentrefuse a removed id at the live-row lookup before any mutation is built. Constructing it requires hand-writing the mutation, which only tests do.(An earlier revision of this description also argued the store had no production callers. That is no longer true — #20718 wired it for structured sessions — so the argument above is the one that holds.)
Tests
're-admits a torn-down child at a later revision while identity fences survive marker compaction', modelled on the parent-side'bounds tombstones while revision envelopes reject stale replay after reacquisition and compaction':main);adoptstill answersunknown-child.Step 2 is the failing-first assertion. Steps 3 is the ablation — it removes the marker and proves the guarantee does not depend on it.
Plus
'admits new child work announced under a reused alias after a parent drop and reopen', pinning row 4.