Skip to content

revert(kernel): withdraw unbounded D1 board wake fan-out - #1029

Merged
lilyshen0722 merged 1 commit into
mainfrom
revert/d1-board-wakes
Aug 19, 2026
Merged

lilyshen0722 merged 1 commit into
mainfrom
revert/d1-board-wakes

Conversation

@lilyshen0722

Copy link
Copy Markdown
Contributor

Reverts #1020 intact. The synthetic claim key deduped action but not delivery: each board write still enqueued one message.posted event per opted-in installation.

In the observed five-seat pod, 39 writes create 156 wakes. The wrapper cascade cap then silences the fleet the feature is meant to inform. D1 will return after producer-side coalescing creates at most one undrained board wake per recipient.

Verification:

  • backend TypeScript check passes
  • affected task-route / mention suites: 81 passing
  • tasksApi.queryCoercion.test.js could not load on local Node 26 because the pre-existing jsonwebtoken → buffer-equal-constant-time incompatibility throws before test registration; CI runs the supported node matrix.

This is a clean revert of the complete squash commit, including the route wiring, fan-out service, export seam, and D1-only tests.

@lilyshen0722
lilyshen0722 merged commit a65ed4b into main Aug 19, 2026
12 checks passed
@lilyshen0722
lilyshen0722 deleted the revert/d1-board-wakes branch August 19, 2026 10:52
lilyshen0722 added a commit that referenced this pull request Aug 19, 2026
…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.
lilyshen0722 added a commit that referenced this pull request Aug 19, 2026
…4 D1, re-land) (#1030)

* feat(kernel): board changes reach agents, bounded on DELIVERY (ADR-024 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.

* refactor: export wakeOnMessageEnabled so D1 gates on it instead of copying 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.

* feat(tasks): wire the six board-write sites to the coalesced fan-out

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.

* test: pin the delivery bound, the fold key, and the actor pricing

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.

* test: cover the wiring, where this fails invisibly

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.

* fix(kernel): key the self-skip on identity, not installedBy

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.

* fix(tasks): actorOf carries agent identity, not just a user id

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.

* test: the human-installed self-wake, and the sibling it must NOT suppress

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 added a commit that referenced this pull request Aug 20, 2026
…one's window

The pin is a SUBSET assertion per fable 56080 — lapsedConditions deep-equals
the last two entries of claimableConditions, because the shapes are
deliberately not equal (the CAS also admits pending and self-renewal).

Mutation-probed per 56081: with the sweep's lease constant changed to 31
minutes the assertion went red on the claimedAt date, then green again on
revert. It is not a test that can only pass.

Loading tasksApi in jest requires mocking its middleware imports — jsonwebtoken
pulls buffer-equal-constant-time, which crashes on Node 26 before any test
registers (the incompat #1029's revert note recorded). Same mock shape the
tasksApi route suites already use.

Gate one's window is pinned too: the aggregate's $match must carry
updatedAt >= now minus one sweep period.
lilyshen0722 added a commit that referenced this pull request Aug 20, 2026
…for named work (#1044) (#1055)

* feat(kernel): the work sweep — rescue lapsed leases, wake seats only for named work (#1044)

fable's ruling, implemented to its three constraints: writes carry the named
kernel-sweep actor in the task audit trail; wakes carry the third pricing
branch; rescue is a per-task CAS whose filter carries the lapsed predicate, so
a claimant renewing between find and write wins and the sweep loses.

The empty case enqueues nothing and costs zero model turns — HEARTBEAT_OK
stops existing as an outcome, because a seat is only woken when the payload
can name work.

Replaces the theo-heartbeat rescue design, which died with the moltbot park
(#1050): theo WAS a moltbot, so 'theo-less pods and theo itself as a single
point' became the only case. A lapsed-to-pending transition needs no model
judgment, so nothing here requires an LLM at all.

Kill switch: AGENT_WORK_SWEEP_DISABLED=true, checked before any query.

* feat(kernel): notifyFoundWork — the kernel-priced coalesced wake

triggerAuthor 'kernel' and NO dmKind (fable 55845): priced 'agent' it counts
toward the cascade cap and silences seats exactly when the board is busiest;
priced 'human' it clears the brake on unrelated cascades. Old CLIs see no
dmKind and no messageId and classify 'unknown' — neutral, so degradation is
graceful.

The content NAMES the found work inline, capped at five items — a wake that
says 'go look' recreates the HEARTBEAT_OK turn-burner one layer down. Same
boardWake fold as change wakes so a sweep wake and a change wake collapse to
ONE pending wake per seat. One bounded leak recorded rather than fixed, same
stance as fable's 55846: an agent change folding into a pending kernel wake
rides under kernel pricing, at most once per drain.

* feat(scheduler): run the kernel sweep every 10 minutes, de-phased

:04 offsets it from the on-the-minute heartbeat dispatcher. Ten minutes gives
lapse-to-rescue a bounded ~40-minute worst case against the 30-minute lease,
and the CAS inside the rescue makes the period-vs-lease race harmless.

* test(kernel): the sweep properties whose violation is quiet

A rescue that clobbers a live renewal looks like a rescue; a wake on an empty
board looks like liveness. Pins the CAS filter carrying the lapsed predicate,
the renewal winning, the named actor, the zero-cost empty case, the five-item
cap, and the kill switch short-circuiting before any query.

* feat(cli): the third pricing branch — kernel wakes are neutral by design

classifyTrigger reads triggerAuthor before dmKind (the honest field, #1018,
born here for real). 'kernel' neither counts toward the cascade streak nor
clears it: counted as agent it eats budget exactly when the board is busiest;
counted as human it releases the brake on unrelated cascades. Neutral like
'unknown', but chosen on purpose rather than fallen into.

* test(cli): kernel classifies first, prices neutral, degrades to unknown

Includes the old-CLI shape (no triggerAuthor, no messageId) staying
unknown-neutral, so a fleet that predates the branch is never silenced by it.

* chore(cli): 0.1.14 -> 0.1.15 for the kernel pricing branch

* fix(kernel): gate one — wake for NEWLY actionable rows only

fable, 56075: the aggregate matched every pending unassigned row with no
since-last-pass predicate, making newly-actionable indistinguishable from
standing stock — a pod with one unloved unassigned task got a kernel wake
every pass, forever. The turn-burner this service exists to kill, reborn one
layer down. A task every seat declined once is deliberately unclaimed;
re-nagging is not discovery.

The window is one sweep period, bound to the cron cadence by comment — they
are one decision. Rescued rows enter the window because the rescue's
findOneAndUpdate bumps updatedAt (Task has timestamps: true), so they still
need no separate channel.

Also corrects the lapsedConditions docstring, which asserted a contract test
that did not exist — fourth of that class this week (fable, 56079). It now
names the real test and its real shape.

* fix(tasks): claimableConditions never survived require

module.exports = router at the file tail CLOBBERS the ES named exports, so
the export #1022 shipped has been unreachable under CJS since it landed —
destructuring it returned undefined. Found when the kernel-sweep contract pin
tried to consume it. Re-attached explicitly onto the router object.

* test(kernel): the lapsed contract pin, mutation-probed red, and gate one's window

The pin is a SUBSET assertion per fable 56080 — lapsedConditions deep-equals
the last two entries of claimableConditions, because the shapes are
deliberately not equal (the CAS also admits pending and self-renewal).

Mutation-probed per 56081: with the sweep's lease constant changed to 31
minutes the assertion went red on the claimedAt date, then green again on
revert. It is not a test that can only pass.

Loading tasksApi in jest requires mocking its middleware imports — jsonwebtoken
pulls buffer-equal-constant-time, which crashes on Node 26 before any test
registers (the incompat #1029's revert note recorded). Same mock shape the
tasksApi route suites already use.

Gate one's window is pinned too: the aggregate's $match must carry
updatedAt >= now minus one sweep period.
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