Skip to content

feat(kernel): board changes reach agents, bounded on delivery (ADR-024 D1, re-land) - #1030

Merged
lilyshen0722 merged 8 commits into
mainfrom
feat/adr-024-d1-coalesced-board-wakes
Aug 19, 2026
Merged

lilyshen0722 merged 8 commits into
mainfrom
feat/adr-024-d1-coalesced-board-wakes

Conversation

@lilyshen0722

@lilyshen0722 lilyshen0722 commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

Re-lands D1 after #1029 reverted it. Same goal, correct bound.

Reland gate: diffed against the reverted squash

Per @fable-lead's ruling — "the reland diffs against the reverted squash before merge, and whatever is in one and not the other gets named in the PR body." Diffing dfa894c6 (the reverted #1020 squash) against this branch:

In the reverted version, deliberately NOT here:

  • The synthetic claim key task:<id>:<kind>:<rev> — removed, it deduped the wrong layer (see below).
  • The millisecond rev component. Obsolete under coalescing: it existed to keep successive changes from colliding on one claim key, and there is no claim key now. Confirmed obsolete by @pod-architect rather than assumed.
  • Per-task claim gating via payload.messageId.

In the reverted version and nearly lost — restored after review:

  • The self-skip. @pod-architect caught that my actorOf supplied only userId, which notifyPodAgents then compared to install.installedBy. A human-installed agent editing the board matches nothing, fails to skip, and wakes itself. Now keyed on (agentName, instanceId), which identifies the acting agent under both install paths.

Here and not in the reverted version: the delivery bound, the identity-keyed skip, dmKind re-pricing on fold, and three tests the old suite structurally could not fail (below).

What the reverted version got wrong

It bounded action, not delivery. A synthetic claim key meant one agent acted — but every opted-in seat was still enqueued and still woke, discovering it lost only after spawning.

@sprint-review put a number on it:

39 writes create 156 wakes. The wrapper cascade cap then silences the fleet the feature is meant to inform.

Each wake is agent-agent, so every seat hits the cascade cap of 3 within seconds and goes deaf for the reset window. D1 switched on would have produced the exact silence it exists to remove.

The fix

At most one pending board wake per (agent, instance, pod). A second change folds into the undrained first instead of appending. 39 writes → 1 wake; each seat looks at the board once rather than once per row.

No messageId, deliberately. Every seat should look. The per-task claim CAS already arbitrates who takes what, one layer down, where the contention actually is.

Folds match on payload.boardWake, never on event type. Board wakes ride message.posted alongside ordinary chat — folding on type would collapse a board change into someone's unread message and destroy it.

A human edit re-prices the batch. If a human edit lands on top of agent churn, the whole folded wake becomes user-agent, so one early agent write can't permanently mark a wake the human later contributed to.

Residual, stated rather than hidden: the fold is a findOneAndUpdate, so two writes in the same instant can both miss and both insert. The bound is "roughly one," never the 39 it replaces.

installedBy has now produced a bug from both directions

It holds the agent's own user id on a self-install and the human's id on a human-install. Comparing it against any actor silenced every agent for its own installer — the person most likely to be moving tasks. Scoping that comparison to agent actors fixed the human case and left the exact mirror image, which is what review caught. Identity is the key that works under both.

Rebuilt, not replayed

My original fix landed on the D1 branch 17 minutes after it had already merged, so it was orphaned. Rebuilding on current main mattered: my local tasksApi.ts was -100 lines against main, because it predated #1022's query coercion and #1023's leaseState. Replaying it would have silently reverted both.

Tests

103 passing across the six affected suites. Three are new and target cases the previous suite could not distinguish, because it only ever exercised a self-installed actor:

  • a human-installed agent editing the board skips itself
  • the match is case-insensitive
  • a different instance of the same agent name is still woken — scout has 115 identities, and a name-only match would have silenced its own siblings

🤖 Generated with Claude Code

https://claude.ai/code/session_01XeUH4HVDsDHYPsHJthXjB8

…4 D1)

Re-lands D1 after #1029 reverted it. The reverted version bounded the wrong
thing: a synthetic claim key deduped ACTION, so one agent acted while every
opted-in seat still woke. sprint-review put a number on it — 39 board writes
across 5 seats is 156 wakes, every seat hits the cascade cap of 3 within
seconds, and D1 silences the fleet it exists to inform.

The bound is now on delivery: at most one PENDING board wake per (agent,
instance, pod). A second change folds into the undrained first instead of
appending. 39 writes become 1 wake; each seat looks at the board once rather
than once per row.

No messageId, deliberately — every seat SHOULD look, and the per-task claim
CAS already arbitrates who takes what one layer down, where the contention
actually is.

Folds match on payload.boardWake, never on event type: board wakes ride
message.posted alongside ordinary chat, and folding on type would collapse a
board change into an unread message and destroy it.

A human edit landing on agent churn re-prices the batch as user-agent, so one
early agent write cannot permanently mark a wake the human later contributed
to.

Residual stated in code rather than hidden: the fold is a findOneAndUpdate, so
two writes in the same instant can both miss. The bound is 'roughly one', never
the 39 it replaces.
…pying it

The config is a Mongoose Map on some paths and a plain object on others —
exactly the detail a second copy gets subtly wrong.
Rebuilt on top of current main rather than replayed from the reverted branch:
that copy predated #1022's query coercion and #1023's leaseState, and pushing
it would have silently reverted both.

notifyAgents guards with try/catch AND .catch. A promise .catch cannot cover
the call throwing synchronously, which is what happens when notifyPodAgents is
undefined — and that turned every board write into a 500, strictly worse than
the silent fan-out this fixes.
Covers what the reverted version got wrong: folds into an undrained wake,
matches on boardWake rather than type, carries no messageId, and re-prices a
folded batch when a human edit lands on agent churn.

Also keeps the two bugs the first round caught — the self-skip keyed on
installedBy (which holds the agent's id on self-install and the HUMAN's on
human-install, silencing every agent for its own installer), and the require
pointing at a models path that does not exist.
A board write that reaches Socket.io and skips the fan-out still 200s, still
updates the Kanban, and only the agents learn nothing. Includes the
synchronous-throw case, which a rejection guard does not catch.
@lilyshen0722

Copy link
Copy Markdown
Contributor Author

The revert took two fixes with it and this branch reintroduces the defective version. Verified at feat/adr-024-d1-coalesced-board-wakes:

  • :160-172 is the installedBy-keyed self-skip — the pre-558486e4 code.
  • No identityOf / actorIdentity anywhere in the file.

Both were reviewed independently by two readers on #1020, fixed in 558486e4, and merged inside dfa894c6. git revert correctly removed them along with the fan-out; nothing has put them back.

1. Self-skip must key on identity, not installer

installedBy names the installer, never the agent: it holds the agent's own user id on self-install and the human's on human-install. Scoping to agent actors fixes the human case and leaves its mirror open — a human-installed agent (the normal path) never matches its own install and wakes itself on every board write.

In live data the field has no discriminating power at all: all five active installs in the Dev Team pod share one installedBy, so it cannot separate any of them even in principle.

Fix, as merged before: actorOf carries botMetadata.agentName / instanceId from req.agentUser, and the skip compares (agentName, instanceId) — the same pair agentMentionService uses for its own self-mention guard, and the same pair two lines below in this function.

Coalescing makes this more important, not less. A folded wake delivered to the actor is still a self-wake; it's just a cheaper one.

2. rev (if any per-task key survives coalescing)

String(task.updatedAt) renders to the second — String(…23.100Z) === String(…23.900Z) is true. Use new Date(task.updatedAt).getTime(). Stated bound: two writes inside one millisecond still collide, and __v isn't bumped by findOneAndUpdate, so ms is a chosen stop rather than exactness.

If the coalesce design drops the per-task key entirely, this one is moot — worth saying so explicitly in the PR body either way, so the next reader doesn't think it was forgotten.

Cherry-pick

Both fixes are in 558486e4, still reachable since the revert preserved history. Their tests came out too: tasksApi.agentNotify.test.js and taskEventService.notifyPodAgents.test.js carried four assertions pinning identity-keyed skip behaviour, including one case (skips a HUMAN-installed agent editing the board, where installedBy could not) that exists specifically to stop this regression.

pod-architect on review: a HUMAN-installed agent editing the board does not
match its installer's id, so it fails to skip and wakes ITSELF.

installedBy has now produced a bug from both directions. It holds the agent's
own user id on a self-install and the HUMAN's id on a human-install. Comparing
it against any actor silenced every agent for its own installer — the person
most likely to be moving tasks. Scoping that comparison to agent actors fixed
the human case and left the mirror image intact.

(agentName, instanceId) identifies the acting agent under BOTH install paths,
which is what this skip has always meant. Normalised the way
AgentInstallation stores them — lowercased name, 'default' for a missing
instance — so a case difference cannot quietly reintroduce the self-wake.
The self-skip downstream needs (agentName, instanceId). Both auth shapes carry
the same metadata: agentRuntimeAuth sets req.agentUser, the dual-auth path
leaves the bot on req.user.
…ress

Three cases the previous suite could not distinguish, because it only ever
exercised a self-installed actor:
- a human-installed agent editing the board skips itself
- the match is case-insensitive
- a DIFFERENT instance of the same agent name is still woken, so a per-user
  fan-out agent (scout has 115 identities) does not silence its own siblings
@lilyshen0722
lilyshen0722 merged commit 11b0326 into main Aug 19, 2026
12 checks passed
@lilyshen0722
lilyshen0722 deleted the feat/adr-024-d1-coalesced-board-wakes branch August 19, 2026 21:45
samxu01 pushed a commit that referenced this pull request Aug 21, 2026
…rface closing it

D1's evidence ("Nothing does both") was true on 2026-08-18 and is false now.
taskEventService emits AND enqueues on 13ee6df, and tasksApi calls the pair
adjacently — closed by #1020/#1030, #1055 and #1082, all merged after the ADR
was written.

Left undated, a reader concludes no producer enqueues and builds something
that already exists. Narrows the remaining gap to the four surfaces nobody
has read at call-site level, and marks them unaudited rather than confirmed.

Co-Authored-By: Claude Opus 5 <[email protected]>
lilyshen0722 added a commit that referenced this pull request Sep 2, 2026
…on claim result (#1083)

* docs(adr-024): D3a — resolve the claim/batch blocker by partitioning on claim result

TASK-026. D3 was blocked on claim-before-act being in tension with batching,
with three lossy candidates on the table. None is needed: the claim already
means two different things by event class, and only one is in conflict.

A lost claim on message.posted stands the seat down (agent.js:958). A lost
claim on chat.mention/dm.message already proceeds peer-aware with
peerHoldsFrame (agent.js:947-953). Heartbeats, summary.request, thread.mention
and every kernel board wake carry no messageId and never claim at all.

So: claim the binding sub-batch up front, unchanged and still strictly before
the turn, and let the result partition the batch into act-on (won) and
read-only context (lost). A batched turn never needed to know which item it
would act on, only which it is allowed to act on — which is what the CAS
already returns. ADR-018's invariant is preserved rather than weakened, and
both halves already exist in the code.

Measured, since the objection to claiming up front was contention: live-seat
batches are max 2 at the 5s poll interval and max 6 at 60s, and the binding
class is 9.5% of all events (2,152 of 22,614 over 7 days).

Two corrections recorded. The task spec cites cli/src/lib/poller.js, which is
`agent connect`'s loop and runs on no fleet seat; the real tick is
agent.js:1170/1174/1178. And pending backlogs of 62/35/35/33/33/17 are
heartbeat-only on parked seats — every live seat holds zero — so they are
#1050 residue, not evidence of batch depth.

Co-Authored-By: Claude Opus 5 <[email protected]>

* docs(adr-024): correct the Context section's citation to match D3a

D3a corrects the defect's location to cli/src/commands/agent.js:1174-1178,
but the Context section 140 lines above still named cli/src/lib/poller.js
in prose AND in a fenced code block. So the ADR carried the correction and
the uncorrected claim in two places, and the wrong one reads first.

A reader who greps for the defect finds poller.js, fixes it, ships green,
and reaches no seat — which is exactly the failure D3a exists to prevent.

Co-Authored-By: Claude Opus 5 <[email protected]>

* docs(adr-024): date D1's producer-parity audit and record the task surface closing it

D1's evidence ("Nothing does both") was true on 2026-08-18 and is false now.
taskEventService emits AND enqueues on 13ee6df, and tasksApi calls the pair
adjacently — closed by #1020/#1030, #1055 and #1082, all merged after the ADR
was written.

Left undated, a reader concludes no producer enqueues and builds something
that already exists. Narrows the remaining gap to the four surfaces nobody
has read at call-site level, and marks them unaudited rather than confirmed.

Co-Authored-By: Claude Opus 5 <[email protected]>

---------

Co-authored-by: Claude Opus 5 <[email protected]>
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