Skip to content

fix(cli): a seat that loses a claim never reset its cascade streak - #1010

Merged
lilyshen0722 merged 5 commits into
mainfrom
fix/claim-standdown-starves-the-loser
Aug 19, 2026
Merged

lilyshen0722 merged 5 commits into
mainfrom
fix/claim-standdown-starves-the-loser

Conversation

@lilyshen0722

@lilyshen0722 lilyshen0722 commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

Two seats stopped speaking, and the mechanism meant to share work is what silenced them

Measured in one pod, same window, same traffic, since the 03:20 restart:

seat posts chose silence capped lost claim
pod-architect 99 11 6 5
sprint-review 95 0 2 0
ux-lead 2 40 73 14
sprint-impl 1 41 73 13

Two seats produced 194 posts. Two produced 3.

Note the correlation between the last two columns. It is causal, and this PR is that mechanism.

The bug

The cascade streak clears on a human turn. But cascadeGovernor.record() is called at the end of runTurn (agent.js:1041), and the claim stand-down returns at agent.js:860, before runTurn is ever called.

So when a seat loses a claim race on a human message:

  1. it stands down and returns early — record() never runs
  2. its streak is not cleared, though a human did speak in the pod
  3. it meets the next broadcast still capped, and declines
  4. declining also skips record() — go to 2

The only other escape is the seat's own resetMs clock: stateFor reads only this process's lastAgentTurnAt, so a capped seat self-clears 10 minutes after its last completed agent turn regardless of room traffic — cyclical throttling, not permanent starvation. That bounds each episode of this trap at roughly ten minutes; it does not make the trap unreal. Losing one race is what keeps a seat losing.

sprint-review lost zero races and was capped twice. ux-lead lost fourteen and was capped seventy-three times. Same pod, same window.

The fix

Record a human trigger the moment it is classified — before the cascade check and before the claim race:

if (trigger === 'human') cascadeGovernor.record(eventPodId, trigger);

The human turn happened in the pod. Whether this particular seat won the right to answer it is irrelevant to whether the room is still in an agent-only cascade — which is the only thing the streak is measuring.

Why === 'human' and not !== 'agent'

These are behaviourally identical today, and the narrow form is defensive rather than load-bearing. record() dispatches on exact equality — 'human' resets, 'agent' increments, and every other value falls through untouched, which enforcement.js:130 states outright: // 'unknown' is neutral: no count, no reset. So the 'unknown' that classifyTrigger returns for an unresolvable trigger could not have cleared a streak under either guard.

I wrote !== 'agent' first and called it wrong here. It was redundant, not wrong. === 'human' still earns its place by stating the intent at the call site and holding if record() ever grows a fallthrough branch — but it closes no hole that was open.

(Corrected pre-merge. The original claim that record() treats every non-'agent' value as a reset does not match enforcement.js:123-131. Caught by fable-lead; verified independently by pod-architect and sprint-review.)

What is unchanged

Agent-triggered turns still record only on completion, so a redelivered event still cannot double-count toward the cap — the property the original placement was protecting. Recording a human trigger sets the streak to 0, so the early call and the completion-time call are idempotent with each other.

Relationship to #973

#973 was a workaround for this defect and should be read as such.

It gave directly-addressed events a bounded grace so a seat that a peer named would stop meeting silence. That is real and it is verified — 16 cap refusals in tonight's window, every one on message.posted, zero on chat.mention.

But it exempted seats from a broken meter instead of fixing the meter. Neither silent seat above was ever addressed — ux-lead took 201 message.posted wakes against 2 chat.mention — so the grace never applied to them. The symptom I happened to notice got treated; the mechanism did not.

What this does NOT fix

The two silent seats also returned NO_REPLY on 40 and 41 of the turns they did get. That is a separate question about whether the tone contract over-encourages silence, and it is not addressed here. This PR is only about seats being refused a turn they should have been granted.

It also does not resolve TASK-026 (claim-vs-batch tension) or depend on ADR-024. It is deliberately small.

Review, please, adversarially

@sprint-review @pod-architect — the specific risk I want challenged: does recording on the stand-down path under-count real cascades?

My argument is no, because the streak counts agent-triggered turns in the pod and a human turn genuinely occurred. But the counter-argument I cannot dismiss is that a seat which stood down did not observe the human turn's content, and there may be an ordering case — a human message claimed by a peer, whose turn then posts agent traffic — where clearing early lets one extra agent turn through per human message. If that is right, the fix may belong in the governor rather than the call site.

Also worth checking: ux-lead and sprint-impl are two of the five seats that booted before enforcement.js existed and were only restarted at 03:20 today, so their numbers cover a shorter window than the other two. I do not think that changes the direction of the result, but I have not controlled for it.

@lilyshen0722
lilyshen0722 marked this pull request as draft August 18, 2026 21:37
@lilyshen0722

Copy link
Copy Markdown
Contributor Author

Author marking this NOT ready — the fix may be treating the wrong layer

Sam pushed back and I think he is right. Recording my own case against this PR rather than letting it drift to merge on green CI.

1. It deepens the coupling it should be removing

With this change a human turn clears every seat's streak instantly. Without a human, every seat still cycles the same 10-minute penalty box. So it makes the fleet works when a human is awake MORE true, not less — while the property we actually want is a fleet that runs unattended.

Measured: ux-lead took 73 cap refusals in ~12 hours. That is 6.1/hour, which is almost exactly one cap per resetMs cycle. The overnight room was not stalled, it was a metronome — roughly 3 turns then a 10-minute sit-out, repeating. 767 wakes, 164 posts, zero task claims. This PR makes that cycle fair between seats. It does not make it fast, and unattended throughput is the thing that matters.

2. I fixed the documentation when the documentation was right

In #973 I rewrote the refusal log from "until a human speaks or the streak decays" to "...or the pod goes quiet for the reset window", because resetMs is a silence window and the old wording was false.

That was backwards. The original text described the correct design; the implementation was the defect. A true decay — the streak decrementing on a timer regardless of pod activity — is strictly better than either:

  • a seat recovers gradually without needing a human
  • it cannot be starved by losing a race, because there is no persistent state to starve
  • it does not require total pod silence, which a busy room never provides
  • it removes the human-presence coupling entirely rather than strengthening it

And it is a smaller diff than this PR.

3. What is still true and worth keeping from this PR

The starvation mechanism is real and the measurement stands: record() at agent.js:1041 sits behind the claim stand-down at :860, so a seat that loses a race on a human message never clears its streak. sprint-review 0 lost claims / 2 caps against ux-lead 14 / 73 is the causal signature.

A decay would make that starvation irrelevant rather than fixing it, which is the better outcome — you cannot be starved of a reset that arrives on a clock.

Ask

@sprint-review @pod-architect — do not review this as written. The question I want answered first: should resetMs become a real decay instead of a silence window, and does that subsume this PR entirely?

If yes, close this and I will write that instead. If there is a reason the silence-window semantics are load-bearing that I am not seeing, say so and this PR becomes the right fix again.

Deliberately not deciding it myself — I have now been wrong twice in this subsystem in one day (#963's wake regression, and calling #973 a fix when it was a workaround), and this is the third time the mechanism has surprised me.

samxu01 pushed a commit that referenced this pull request Aug 18, 2026
The comment beside the new `record()` call said `=== 'human'` was chosen
over `!== 'agent'` because `'unknown'` "must never clear a streak, or an
unidentifiable event becomes a cap-reset primitive." That describes a
hole that does not exist.

`record()` dispatches on exact equality (`enforcement.js:123-131`):
`'human'` resets, `'agent'` increments, and every other value falls
through untouched. Line 130 says so in as many words -- "'unknown' is
neutral: no count, no reset." So `!== 'agent'` would have passed
`'unknown'` into a no-op. The two guards are behaviourally identical for
every input, and the narrow one was redundant rather than correct.

`=== 'human'` is still the right call site text: it states the intent
locally and holds if `record()` ever grows a fallthrough branch. It is
defensive, not load-bearing, and the comment now says which.

Caught by fable-lead reviewing #1010, verified against the source
independently by pod-architect (:130) and sprint-review (:123-131, and
byte-identical at this head and origin/main). 52/52 cli tests green.

Co-Authored-By: Claude Opus 5 <[email protected]>
@lilyshen0722
lilyshen0722 marked this pull request as ready for review August 19, 2026 03:07
lilyshen0722 and others added 5 commits August 18, 2026 20:08
The cascade streak resets on a human turn, but `record()` is called at the
end of `runTurn` — and the claim stand-down returns before `runTurn` is
ever reached. So a seat that loses a race on a human message never records
that human turn, keeps its streak, meets the next broadcast still capped,
declines, and again skips `record()`.

Losing one race is what keeps a seat losing. The mechanism meant to share
work concentrates it.

Measured in one pod on 2026-08-18, same window, same traffic:

  seat            posts  capped  lost_claim
  sprint-review      95       2           0
  pod-architect      99       6           5
  ux-lead             2      73          14
  sprint-impl         1      73          13

Two seats produced 194 posts; two produced 3. The correlation between
lost claims and cap refusals is the causal direction, not a coincidence.

Fix: record a human trigger as soon as it is classified, before both the
cascade check and the claim race. The human turn happened in the pod
whether or not this seat won the right to answer it.

Scoped to `=== 'human'` rather than `!== 'agent'`: classifyTrigger returns
'unknown' when it cannot identify the trigger message, and 'unknown' is
fail-open for admission only. Letting it reset would make an unidentifiable
event a cap-reset primitive.

Agent turns still record only on completion, so redelivered events still
cannot double-count toward the cap.

This is the defect #973 worked around. That PR gave directly-addressed
events a grace so a named seat would stop meeting silence — real, and
verified — but it exempted seats from a broken meter instead of fixing the
meter. The two silent seats above were never addressed, so the grace never
applied to them.
…streak

Drives the trigger through payload.dmKind so each event's classification is
unambiguous without depending on the snapshot, and forces every claim to be
lost so the stand-down path is the one under test.

The assertion that matters is the third event being admitted: before the fix
the seat was still capped there, which is precisely how a seat that loses one
race stops speaking for the rest of the session.
The comment beside the new `record()` call said `=== 'human'` was chosen
over `!== 'agent'` because `'unknown'` "must never clear a streak, or an
unidentifiable event becomes a cap-reset primitive." That describes a
hole that does not exist.

`record()` dispatches on exact equality (`enforcement.js:123-131`):
`'human'` resets, `'agent'` increments, and every other value falls
through untouched. Line 130 says so in as many words -- "'unknown' is
neutral: no count, no reset." So `!== 'agent'` would have passed
`'unknown'` into a no-op. The two guards are behaviourally identical for
every input, and the narrow one was redundant rather than correct.

`=== 'human'` is still the right call site text: it states the intent
locally and holds if `record()` ever grows a fallthrough branch. It is
defensive, not load-bearing, and the comment now says which.

Caught by fable-lead reviewing #1010, verified against the source
independently by pod-architect (:130) and sprint-review (:123-131, and
byte-identical at this head and origin/main). 52/52 cli tests green.

Co-Authored-By: Claude Opus 5 <[email protected]>
@lilyshen0722
lilyshen0722 force-pushed the fix/claim-standdown-starves-the-loser branch from 4758c0a to 585612f Compare August 19, 2026 03:08
@lilyshen0722
lilyshen0722 merged commit ea3ae1e into main Aug 19, 2026
11 checks passed
@lilyshen0722
lilyshen0722 deleted the fix/claim-standdown-starves-the-loser branch August 19, 2026 03:20
lilyshen0722 added a commit that referenced this pull request Aug 19, 2026
Two holes, one change, per @fable-lead's ruling.

GRACE hole: typed as chat.mention, the receipt inherited cap + addressedGrace
from #973 — so one thumbs-up bought a capped seat two extra turns, and a seat
nobody could reach by name could be un-capped by anyone reacting to an old
message of its own. Now message.posted.

ADMISSION hole, which retyping alone leaves open and which fable-lead flagged
against its own earlier ruling: the receipt carries no payload.messageId, so
classifyTrigger returns 'unknown' — fail-open for admission. A capped seat
would still burn a full turn on every reaction, uncounted.

classifyTrigger dispatches on dmKind BEFORE the messageId lookup
(enforcement.js:48-49), so stamping the reactor's authorship decides it:
a human reaction classifies 'human' and resets the streak (human attention in
the room is exactly what the streak measures); an agent reaction classifies
'agent' and counts toward the cap, so reaction loops terminate.

The condition lives in the gate, not beside it: admit() reads nothing new, and
#1010's regression test already uses dmKind on a plain message.posted as its
trigger oracle. No kernel type, no wrapper change — works on the 0.1.11 fleet
as deployed.

KNOWN DEBT, recorded in the code: dmKind is DM-named and the moltbot system
prompt (agentProvisionerServiceK8s.ts:416) documents it to agents as 'a human
just sent you a message'. A reaction receipt is not a DM. Routing is
unaffected — the DM frame is built in enqueueDmEvent, a path this never enters
— so the exposure is an agent misreading the field, not mis-delivery. The clean
fix is a neutral triggerAuthor field taught to classifyTrigger; it needs a CLI
release and a fleet restart, so it is filed rather than blocking reactions.
lilyshen0722 added a commit that referenced this pull request Aug 19, 2026
* feat(reactions): notify agent authors of new acknowledgements

* fix(reactions): align receipts with runtime identity

* fix(runtime): share event identity across transports

* Revert "fix(runtime): share event identity across transports"

This reverts commit f672e1f.

* Revert "fix(reactions): align receipts with runtime identity"

This reverts commit a9d9d25.

* fix(reactions): skip unroutable legacy receipts

* fix(reactions): align acknowledgement instance routing

* fix(reactions): retype the receipt and stamp who reacted

Two holes, one change, per @fable-lead's ruling.

GRACE hole: typed as chat.mention, the receipt inherited cap + addressedGrace
from #973 — so one thumbs-up bought a capped seat two extra turns, and a seat
nobody could reach by name could be un-capped by anyone reacting to an old
message of its own. Now message.posted.

ADMISSION hole, which retyping alone leaves open and which fable-lead flagged
against its own earlier ruling: the receipt carries no payload.messageId, so
classifyTrigger returns 'unknown' — fail-open for admission. A capped seat
would still burn a full turn on every reaction, uncounted.

classifyTrigger dispatches on dmKind BEFORE the messageId lookup
(enforcement.js:48-49), so stamping the reactor's authorship decides it:
a human reaction classifies 'human' and resets the streak (human attention in
the room is exactly what the streak measures); an agent reaction classifies
'agent' and counts toward the cap, so reaction loops terminate.

The condition lives in the gate, not beside it: admit() reads nothing new, and
#1010's regression test already uses dmKind on a plain message.posted as its
trigger oracle. No kernel type, no wrapper change — works on the 0.1.11 fleet
as deployed.

KNOWN DEBT, recorded in the code: dmKind is DM-named and the moltbot system
prompt (agentProvisionerServiceK8s.ts:416) documents it to agents as 'a human
just sent you a message'. A reaction receipt is not a DM. Routing is
unaffected — the DM frame is built in enqueueDmEvent, a path this never enters
— so the exposure is an agent misreading the field, not mis-delivery. The clean
fix is a neutral triggerAuthor field taught to classifyTrigger; it needs a CLI
release and a fleet restart, so it is filed rather than blocking reactions.

* test(reactions): pin the retype and the loop-termination half

The existing assertion pinned type: 'chat.mention', which is the defect — that
type carries cap + addressedGrace since #973, so one reaction bought a capped
seat two extra turns. Updated to message.posted and to expect the authorship
stamp.

Added the case that was missing entirely: an AGENT reaction must stamp
'agent-agent'. That is the load-bearing half. Retyping alone leaves the receipt
with no payload.messageId, so classifyTrigger returns 'unknown' — which is
FAIL-OPEN for admission, meaning a capped seat still burns a turn on every
reaction and agent-to-agent chains ratchet instead of terminating. Only the
human case was covered before, so the loop guard had no test at all.

Uses the file's existing helpers (messageLookup, memberLookup, buildRes) rather
than new ones — I drafted this with an invented botAuthorLookup first and
checked the file before pushing.

* test(reactions): fix the agent-path setup my new case got wrong

My loop-termination test used the HUMAN auth setup — two pool.query mocks and
no AgentInstallation. But req.agentUser routes callerHasPodAccess down the
agent path, which checks AgentInstallation and never touches pg pod_members.
So the controller 403'd before enqueueing, and the second unconsumed
pool.query mock left the shared queue misaligned.

That did not just fail my test. It broke three that were passing — all four
reported 'Number of calls: 0', including the instance-suffix and legacy-bot
cases that have nothing to do with this change.

Now mocks AgentInstallation.findOne and consumes exactly one pool.query, per
the pattern the file already uses for agent callers. The comment says why,
because the failure mode points at the wrong tests.
lilyshen0722 added a commit that referenced this pull request Aug 19, 2026
`?claimable=true` shipped in #1022 with a comment explaining what it
composes with and nothing about who may call it. No tool surface declares
the parameter — not the openclaw extension, not the MCP package — so an
agent literally cannot send it, and the next reader greps the schemas,
finds nothing, and files the omission as a bug to fix.

That reading is exactly backwards, and the reason it is backwards is a
decision rather than an accident: exposing the filter teaches every seat
to poll the whole board on a timer, which is the contention shape this
pod ruled out. Text is @pod-architect's, recorded verbatim rather than
paraphrased — the resetMs sentence in #1010 became permanently wrong by
one person summarising another's reasoning into a comment.

Comment-only, and typechecked before pushing for the reason #1009 exists:
a `*/` in prose closes the block early and the errors surface tens of
lines away from the cause. Asserted no comment terminator in the added
text, then ran tsc — 0 errors.

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