Skip to content

fix(agent-status): one revision rule for every teardown marker - #20967

Closed
brennanb2025 wants to merge 3 commits into
mainfrom
brennanb2025/agent-status-child-marker-revision-rule
Closed

brennanb2025 wants to merge 3 commits into
mainfrom
brennanb2025/agent-status-child-marker-revision-rule

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​107 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​105
Prod 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​66 $\color{#cf222e}{\Huge{\mathbf{−}}}$​15 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​51

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.

// before — child, at admission and in validation: does a marker exist?
if (state.tombstones.has(agentStatusTombstoneMapKey('child', key))) return false

// after — every entity, one spelling: is this write older than the removal?
if (agentStatusTombstoneFences(state, 'child', key, revision)) return false

What changes, measured on main:

before after
re-add a removed child at a later revision, marker still present refused admitted
the same, after the marker was compacted away admitted admitted
remove and re-add inside one mutation (same revision) refused refused
announce under a task_id whose previous holder was torn down refused for the life of the store admitted, with a freshly minted id

Parent 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) and AGENT_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 childWorkId is 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:

  • the lock-step revision envelope, which refuses any out-of-order mutation;
  • the live-row lookup at admission, which answers unknown-child for a removed id — adopt / resume / reparent short-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 applyMutation assigns state.revision + 1 and applyTransportEnvelope requires 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_VERSION stays 1; AgentStatusStoreSnapshot, AgentStatusStoreMutation, AgentStatusTombstoneRecord and AgentStatusTombstoneEntity are untouched; the same markers are written at the same revisions. Rules 1 and 2 of docs/reference/remote-wire-compatibility.md do 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 childWorkId at 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: announce mints a fresh id, and adopt / resume / reparent refuse 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':

  1. seed parent + child, mirror to a replica, keep the seed envelope;
  2. remove the child, assert the marker is present, re-add the same id at a later revision — admitted (this assertion fails on main);
  3. fill past the tombstone cap, assert the marker is gone, then show the fences still hold: the replica refuses the stale seed envelope, and adopt still answers unknown-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.

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.

@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 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 agentStatusTombstoneFences in agent-status-store-state.ts returns true only when a marker exists and marker.revision >= revision; it is now the only spelling of the rule.
  • Admission aligned — upsertParent/upsertChildren/upsertAliases/upsertFacts all call the helper. Parent is behavior-preserving; child moves from has to revision compare; alias/fact gain a check that validation already applied, so their outcome is unchanged.
  • Validation aligned — all four entity loops in validateAgentStatusStoreState now 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.

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

@coderabbitai

coderabbitai Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview 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: 8bf068ac-8b2d-4117-a011-8357a51a7ba5

📥 Commits

Reviewing files that changed from the base of the PR and between 9fef530 and daaf375.

📒 Files selected for processing (4)
  • docs/reference/agent-status-store.md
  • src/shared/agent-status-store-mutation.ts
  • src/shared/agent-status-store-state.ts
  • src/shared/agent-status-store.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • docs/reference/agent-status-store.md

Included review availability: Your plan provides up to 10 included reviews per hour; 2 remain after this review.


📝 Walkthrough

Walkthrough

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

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)

Check name Status Explanation Resolution
Description check ⚠️ Warning 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 checklis… 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 addres…
Docstring Coverage ⚠️ Warning 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… 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 summarizes the main change: applying one revision-based rule to all teardown markers.
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 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 Coverage

Explanation

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.)

  • 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: 5df40fe4-63ed-4912-994e-9276a59d1f50

📥 Commits

Reviewing files that changed from the base of the PR and between feb04ec and 3316614.

📒 Files selected for processing (4)
  • docs/reference/agent-status-store.md
  • src/shared/agent-status-store-mutation.ts
  • src/shared/agent-status-store-state.ts
  • src/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

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.

📐 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

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

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 — upsertAliases and alias validation now key on serializeAgentChildWorkBindingKey instead of the alias-only serializeAgentChildWorkAliasKey, matching main's alias-map key. The revision rule and the new agentStatusTombstoneFences helper are otherwise unchanged.
  • Reused-alias test now red — main's new resolveAgentStatusChildBindings refuses 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.

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

observedAt: 80,
fence: { invocationId: 'invocation-2', generation: 1 }
})
).toMatchObject({ accepted: true, childWorkId: 'minted-2', created: true })

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

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Closing: internal refactor with no user-facing change.

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