Skip to content

fix(cli): the poller claims one event, because the fetch IS the claim - #1166

Merged
lilyshen0722 merged 2 commits into
mainfrom
fix/poller-claims-only-what-it-can-start
Aug 23, 2026
Merged

lilyshen0722 merged 2 commits into
mainfrom
fix/poller-claims-only-what-it-can-start

Conversation

@lilyshen0722

Copy link
Copy Markdown
Contributor

TASK-051, root cause. A seat ran ~11.5 hours behind — every wake carried a stamp from the previous evening, 260 events queued, 18% acked against 96–100% for every peer (@sprint-review's measurement, 57638).

The bug

AgentEventService.list() does not hand back a preview. It marks every candidate delivered with $inc: { attempts: 1 } before returning. The run loop then processes them serially, one full model turn each.

So limit: 10 claimed ten and started one.

The nine it couldn't start were reclaimed out from under it. The backend requeues delivered rows older than requeueDeliveredMinutes (default 10, swept on */10), and turns routinely outlast that. Measured on this seat over 11.5h from its own log:

spawns 115 (10.0/hour)
median turn 128s
p90 turn 669s
turns over 600s 13
max turn 1153s

Each sweep returned the untouched siblings to pending at attempts + 1. That is sprint-review's otherwise-unexplained 12 at attempts:1 / 9 at attempts:2 — a re-claim, not a redelivery.

Why it's more than latency

attempts >= attemptCap (default 3) retires an event to status: 'failed' — terminal, invisible to list(). That cap exists to bound poison events: three deliveries, no ack, presumed undeliverable. Fed claims no model ever saw, it drops mentions unread, silently. Its own comment says it's there so a poison event can't "silently reproduce the exact Task #67 symptom — stuck, unretried, unsurfaced"; over-claiming turns the remedy into the disease.

The fix

limit: 1. It costs nothing — capacity is one turn at a time regardless and the poll interval is 5s. It only stops the loop claiming work it has no way to begin.

Pinned as its own assertion rather than folded into the existing objectContaining, because 10 read as a harmless batch size, which is exactly why it survived review.

Probe: reverting to 10 fails that one test and nothing else. Full CLI suite: 334 passed, 24 suites.

What this does NOT fix

The other half isn't a bug: this pod produces events ~3× faster than one serial seat retires them. The existing 260-event backlog needs an operator decision (clear, re-ack, or accept ~14h of drain), and per-seat queue depth is surfaced nowhere — 922 events are pending instance-wide, oldest 2026-08-18, and nothing alerts on any of it.

🤖 Generated with Claude Code

lilyshen0722 and others added 2 commits August 22, 2026 22:31
TASK-051. A seat ran ~11.5 hours behind: every wake carried a stamp from
the previous evening, 260 events queued, 18% acked against 96-100% for
every peer.

`AgentEventService.list()` does not preview. It marks every candidate
`delivered` with `$inc: { attempts: 1 }` before returning. The run loop
then processes them SERIALLY, one full model turn each. So `limit: 10`
claimed ten and started one.

The nine it could not start were reclaimed out from under it. The backend
requeues `delivered` rows older than `requeueDeliveredMinutes` (10,
swept on `*/10`), and turns routinely outlast that — measured on this seat
over 11.5h: 115 spawns, median 128s, p90 669s, 13 over 600s, max 1153s.
Each sweep returned untouched siblings to `pending` at `attempts + 1`.
That is @sprint-review's otherwise-unexplained 12-at-1 / 9-at-2 split: a
re-claim, not a redelivery.

The part that makes it more than latency: `attempts >= 3` retires an event
to `failed`, terminal and invisible to `list()`. That cap exists to bound
POISON events — three deliveries, no ack, presumed undeliverable. Fed
claims no model ever saw, it drops mentions unread and says nothing.

`limit: 1` costs nothing. Capacity is one turn at a time regardless and the
poll interval is 5s; this only stops the loop claiming work it cannot begin.

Pinned as its own assertion rather than folded into the existing
`objectContaining`, because 10 read as a harmless batch size — which is
exactly why it survived. Probe: reverting to 10 fails that test alone.
Full CLI suite 334 passed.

Does not address the other half, which is not a bug: this pod produces
events ~3x faster than one serial seat retires them. Backlog needs an
operator decision, and per-seat queue depth is surfaced nowhere.

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

Copy link
Copy Markdown
Contributor Author

Merging this does not reach a single seat. Verified independently after @sprint-review flagged it, from this machine:

/opt/homebrew/bin/commonly
  -> ../lib/node_modules/@commonlyai/cli/src/index.js
  -> …/commonly/.claude/worktrees/sprint-2026-05-24-installable-projection/cli/src/index.js

branch: live/main-tracking   HEAD: 88495fd6
git rev-list --left-right --count origin/main...HEAD  ->  119  0

119 commits behind main, 0 ahead. Every seat's commonly agent run resolves through that symlink into that worktree, so the code they execute is 88495fd6, and the line this PR changes still reads limit: 10 there.

The delivery chain is three steps, not two:

  1. merge this
  2. update live/main-tracking to include it
  3. restart the seats

Step 2 is the one that gets skipped, because the branch name says it's self-maintaining and it isn't — 119 behind and 0 ahead means nothing is tracking anything. That's the repo's standing "verify at the consumer, not at the registry or the workflow" rule with a third indirection: not npm, not the deploy, but a git worktree behind a symlink.

Until step 2 happens the over-claim keeps running, attempts keeps inflating on rows no model saw, and the poison cap keeps retiring them. That is not hypothetical — 71 events have already been retired to failed with requeue cap exhausted after 3 delivery attempts without an ack, across four seats (pod-architect 48, sprint-review 12, ux-lead 6, commonly-bot 5), every one at attempts: 3. Four were chat.mentions to a live seat, including two asking for a gate on #1157 that never arrived.

So the PR body's "what this does NOT fix" list needs a fourth item, and it's the first one: this does not deploy itself.

@lilyshen0722
lilyshen0722 merged commit 2bf173d into main Aug 23, 2026
10 checks passed
@lilyshen0722
lilyshen0722 deleted the fix/poller-claims-only-what-it-can-start branch August 23, 2026 05:56
samxu01 pushed a commit that referenced this pull request Aug 25, 2026
@sprint-review gating #1215: `[^.\n]{0,40}?` reads as "stay inside one
sentence" and silently also means "no model names", because every model we
run is dotted. So the strings the possessive matcher exists to catch —

    You've reached your Haiku 4.5 limit
    you've hit your gpt-5.4-mini limit

fell through to RUNTIME, which is the shortest backoff of the three rungs.
A quota-blocked seat therefore got probed hardest, which is the exact failure
this PR's own header narrates: `session limit` was one word away from
`usage limit`, and this was one model name away.

The paragraph above the regex already said the variable part is "a BILLING
PERIOD or a MODEL NAME". The character class was excluding one of the two
things the comment names. Enumeration failing three times is what motivated
the shape match; the shape match then reintroduced the enumeration bug in
its terminator.

Fix is sprint-review's: `(?:[^.\n]|\.(?=\d))` admits a dot only ahead of a
digit, so a version number passes and a sentence-ending period still stops
the match. Rate-limit exclusion is untouched — QUOTA is tested first, so the
negative lookahead stays load-bearing.

Six tests, including the sentence-boundary case and a ladder-cost assertion
(QUOTA opens the circuit at n=1; RUNTIME would retry in 5s). Probe: reverting
the carve-out reddens exactly the four new cases, 27 others still green.
Full spawn-retry suite 31 passed.

Version 0.1.18 -> 0.1.19: main moved to 0.1.18 after #1166, so the branch's
existing bump had gone stale and the `Source changed => version bumped` guard
was red on identity rather than on omission.

Co-Authored-By: Claude Opus 5 <[email protected]>
samxu01 pushed a commit that referenced this pull request Sep 1, 2026
Sam asked for the 71-count line verbatim in the AX audit. Re-derived it
rather than quoting it, and the re-derivation changed the entry: 169 now,
and #1166 did not slow the rate.

Daily shape rather than a before/after split on the fix cutover. The split
gives 71/98 and reads as "worse after"; the 31-hour gap between them is the
fleet being DOWN, spanning the restart. The honest reading is that the rate
is unchanged, so over-claiming was never the dominant cause.

What it is: `attempts` increments on CLAIM, and the requeue pass returns any
`delivered` row older than 10 minutes to `pending` — so a long turn is
reclaimed from the agent currently running it, three times, then retired.
The threshold's own comment names a workload (3-5 min codex exec) that is
not the workload it governs; #1166 measured this seat at p90 669s.

Also the origin of this session's ~50-hour stale redeliveries: the requeue
loop, seen from inside the agent.

Co-Authored-By: Claude Opus 5 <[email protected]>
samxu01 pushed a commit that referenced this pull request Sep 1, 2026
Sam asked for the 71-count line verbatim in the AX audit. Re-derived it
rather than quoting it, and the re-derivation changed the entry: 169 now,
and #1166 did not slow the rate.

Daily shape rather than a before/after split on the fix cutover. The split
gives 71/98 and reads as "worse after"; the 31-hour gap between them is the
fleet being DOWN, spanning the restart. The honest reading is that the rate
is unchanged, so over-claiming was never the dominant cause.

What it is: `attempts` increments on CLAIM, and the requeue pass returns any
`delivered` row older than 10 minutes to `pending` — so a long turn is
reclaimed from the agent currently running it, three times, then retired.
The threshold's own comment names a workload (3-5 min codex exec) that is
not the workload it governs; #1166 measured this seat at p90 669s.

Also the origin of this session's ~50-hour stale redeliveries: the requeue
loop, seen from inside the agent.

Co-Authored-By: Claude Opus 5 <[email protected]>
lilyshen0722 added a commit that referenced this pull request Sep 1, 2026
#1221)

Sam asked for the 71-count line verbatim in the AX audit. Re-derived it
rather than quoting it, and the re-derivation changed the entry: 169 now,
and #1166 did not slow the rate.

Daily shape rather than a before/after split on the fix cutover. The split
gives 71/98 and reads as "worse after"; the 31-hour gap between them is the
fleet being DOWN, spanning the restart. The honest reading is that the rate
is unchanged, so over-claiming was never the dominant cause.

What it is: `attempts` increments on CLAIM, and the requeue pass returns any
`delivered` row older than 10 minutes to `pending` — so a long turn is
reclaimed from the agent currently running it, three times, then retired.
The threshold's own comment names a workload (3-5 min codex exec) that is
not the workload it governs; #1166 measured this seat at p90 669s.

Also the origin of this session's ~50-hour stale redeliveries: the requeue
loop, seen from inside the agent.

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