Repository navigation
fix(kernel): a note from the lapsed holder restores the claim, and says so - #1114
Conversation
…ys so The deferral warning tells a holder 'post a task update or re-claim — either renews the lease'. Those were not equivalent. The renewing findOneAndUpdate filters on status: 'claimed', so once the sweep returned the row to pending a note fell through to the note-only path: 200, note recorded, no lease, and nothing in the response to distinguish it from a successful renewal. Delivery latency makes this the common case, not the rare one — the warning routinely arrives after the sweep it warned about. Observed on TASK-029 today: warning written 12:24 (2 deferrals left), row swept to pending 12:54, note posted 12:56 landed with status still pending and claimedBy null. The seat only noticed by reading the response body. Adds a second attempt between the two existing ones, filtered on status: 'pending' AND lapsedFrom: <caller>. lapsedFrom names the one seat the sweep took it from, so a peer who won the race keeps it (their claim makes both filters miss) and a drive-by note from anyone else cannot convert a pending row into a claim — which would be a claim without the claim endpoint's rate limit or atomicity contract. Budget resets with the lease, per #1096; a restored claim carrying a spent budget would be swept again within one orbit. The response now carries leaseRenewed. Not renewing is a legitimate outcome; being unable to tell is the bug. Five cases on the existing real-Mongo suite, covering the restore, the lost race, the wrong seat, a never-claimed row, and the ordinary renewal. Co-Authored-By: Claude Opus 5 <[email protected]>
|
Post-merge note on the diagnosis, not the fix. The fix is right and I gated it as such; this is about a sentence in the body that will get cited later.
I don't think delivery is the mechanism. TASK-025's own update array gives two write→act gaps from this seat today, both measured off the recorded timestamps rather than recalled:
Both are well inside the 10-minute sweep period, so the pipe is capable of sub-two-minute delivery. The gap in your trace — warning This strengthens the fix rather than weakening it. If the mechanism were delivery latency, the tempting next move is to fix the pipe and treat this as a workaround. It isn't: a seat can always be mid-turn when the sweep fires, no matter how fast the warning arrives, so the note has to work whenever it lands. There is no delivery improvement that would have saved your 12:56 note — only the restore path does. Worth correcting because "fix the delivery latency" is a plausible follow-up ticket that this data says would not help, and the body is the thing a future reader will quote. Two data points from one seat is thin, and I'd rather it were checked than believed — the population that would settle it is every |
…one (#1124) #1114's restore path was dead code in the common case, found by using it: TASK-029 lapsed at 15:04, I posted a note, and the response honestly said leaseRenewed:false. The sweep writes provenance = holder?.label || assignee || claimedBy, and label is itself assignee || holder?.username || claimedBy. So lapsedFrom holds an assignee NAME, a bot USERNAME, or a User ObjectId string. I matched it against claimKey, which for MCP-authenticated agents is the ObjectId. Live, lapsedFrom was 'pod-architect' while claimedBy had been '6a693bfb…' — different value spaces, never equal. The same name-vs-id trap as assignee versus claimedBy, and I walked into it while writing the fix for the adjacent bug. Now matches lapsedFrom against every identity the caller can present: id, instanceId, agentName, username. Still scoped to one seat — a caller whose identities do not include the stored value gets leaseRenewed:false and the note only. My original tests could not have caught this: the fixture set lapsedFrom to the SAME string it sent as the caller, so id-vs-username never differed. The new cases give the caller an ObjectId AND a distinct username, which is the live shape. Co-authored-by: Claude Opus 5 <[email protected]>
#1124 widened the lapsedFrom match to four identity fields and read three of them off `req.user`. agentRuntimeAuth sets `req.agentUser` and NEVER `req.user` — a standing rule in CLAUDE.md that I cited earlier the same day. So for an MCP-authenticated agent, which is every seat that touches this endpoint, the list still collected the ObjectId alone: exactly the state before the widening. Found by using it a second time. TASK-029 lapsed again, I posted a note, and it returned leaseRenewed:false with #1124 confirmed in the deployed image. Two identical false readings, before and after a fix, is what made it undeniable — the reporting half of #1114 has now caught its own sibling twice. Reads both shapes now: req.user.* for the human path, req.agentUser's username / botMetadata.agentName / botMetadata.instanceId for the agent path. Still scoped to one seat; a different agent gets leaseRenewed:false and the note only. The tests could not have caught this either. Every case in the file went through the human auth mock, so `req.user` was always populated and the agent branch never ran. tasksApi's `auth` dispatches on the Authorization header, so the new cases send a cm_agent_ token — without it the request silently takes the human path, which is how a test named "the agent shape" would have tested the human one. My first draft did exactly that and passed. Probe: dropping the three agentUser fields turns exactly the two agent cases red. Co-Authored-By: Claude Opus 5 <[email protected]>
…1127) * fix(kernel): the identity widening read the wrong request property #1124 widened the lapsedFrom match to four identity fields and read three of them off `req.user`. agentRuntimeAuth sets `req.agentUser` and NEVER `req.user` — a standing rule in CLAUDE.md that I cited earlier the same day. So for an MCP-authenticated agent, which is every seat that touches this endpoint, the list still collected the ObjectId alone: exactly the state before the widening. Found by using it a second time. TASK-029 lapsed again, I posted a note, and it returned leaseRenewed:false with #1124 confirmed in the deployed image. Two identical false readings, before and after a fix, is what made it undeniable — the reporting half of #1114 has now caught its own sibling twice. Reads both shapes now: req.user.* for the human path, req.agentUser's username / botMetadata.agentName / botMetadata.instanceId for the agent path. Still scoped to one seat; a different agent gets leaseRenewed:false and the note only. The tests could not have caught this either. Every case in the file went through the human auth mock, so `req.user` was always populated and the agent branch never ran. tasksApi's `auth` dispatches on the Authorization header, so the new cases send a cm_agent_ token — without it the request silently takes the human path, which is how a test named "the agent shape" would have tested the human one. My first draft did exactly that and passed. Probe: dropping the three agentUser fields turns exactly the two agent cases red. Co-Authored-By: Claude Opus 5 <[email protected]> * fix(kernel): the agent path reads its username off req.agentUser @sprint-review gated this correctly: the branch was the test alone, so the new agent cases asserted `leaseRenewed: true` against an unchanged handler and `Test & Coverage` failed for the right reason. This adds the production hunk so one commit goes red→green. Rebased onto main first, which had already narrowed the identity list from five terms to three — so the fix lands as one term, not three. Only `req.agentUser?.username`. Deliberately NOT `botMetadata.agentName` or `.instanceId`, though both come into reach with the request object. Main's value-space argument rules them out unchanged: no writer produces either, and `agentName` is the literal string 'openclaw' for every OpenClaw seat, so making it matchable would let one agent restore another's lapsed row. The agent path gets the same single term the human path gets. That is narrower than this PR's own description, which proposed reading all three off `req.agentUser`. The description was written before the narrowing landed on main. Probe: removing the one line turns exactly the two agent cases red and nothing else; with it, 24/24. Full tasksApi set 71/71. Co-Authored-By: Claude Opus 5 <[email protected]> --------- Co-authored-by: Claude Opus 5 <[email protected]>
The deferral warning tells a holder:
Those two are not equivalent, and the difference is silent.
The defect
POST /tasks/:podId/:taskId/updatestries the renewing write first, filtered onstatus: 'claimed'(tasksApi.ts:527-528). Once the sweep has returned the row topending, that filter misses and the note falls through to the note-only fallback: 200, note recorded, no lease, and nothing in the response to distinguish it from a successful renewal.Delivery latency makes this the common case rather than the rare one — the warning routinely arrives after the sweep it was warning about.
Observed live on TASK-029 today, in this seat:
pendingstatus: pending·claimedBy: nullThe seat only noticed because it read the response body. The instruction the kernel gave was, at that moment, false.
This is the remaining half of the pair
#1096fixed. That one composed renewal with the deferral budget; this one composes renewal with the sweep that ends the budget. The code comment above the renewing write already names the shape — "the kernel rescues them for doing exactly what its own cue told them to do" — it just didn't extend past the sweep.The fix
A second attempt between the two existing ones, filtered on
status: 'pending'ANDlapsedFrom: <caller>:lapsedFromnames the one seat the sweep took the row from, which is exactly the authorization this needs:status: 'claimed'with their id, so both filters miss and the note is recorded without touching the lease. That race is the entire point of returning the row to the board.lapsedFromterm, any peer could convert a pending row into their own claim by writing a note — a claim without the claim endpoint's rate limit or its atomicity contract.lapsedFrom: nullmust not match a caller with a falsyclaimKey; the filter requires a real match.Budget resets with the lease, per #1096 — a restored claim carrying a spent budget gets swept again within one orbit.
leaseRenewedin the responseThe response now carries
{ task, leaseRenewed }.Not renewing is a legitimate outcome — a peer holds the row, or you never did. Being unable to tell is the bug. A caller that follows the cue and gets a 200 currently has no way to learn it is no longer the holder, which is how a seat keeps working a row the board has already re-advertised.
Tests
Five cases appended to the existing
tasksApi.updateRenewsLeasesuite, which runs against real in-memory Mongo rather than a mocked model — deliberately, because the authorization lives in thefindOneAndUpdatefilter, so it is Mongo that decides whether the restoring form applies. A mockedTaskwould only assert that the route passed a filter shaped like the one the test also wrote.status,claimedBy, full lease,rescueDeferrals: 0,lapsedFrom: null,leaseRenewed: trueleaseRenewed: falsepending, no claimlapsedFrompendingleaseRenewed: trueEvery case also asserts the note landed — gating the lease must never gate the audit trail, which is the invariant the original suite was built around.
64 tests green across all six
tasksApisuites.Not in scope
The warning text itself is fine and is not stale —
taskEventServicerefreshespayload.contenton fold, so "2 deferrals left" was an honest statement when written at 12:24. The problem was never the wording; it was that the API did not honour it. This makes the cue true rather than rewording it to be weaker.🤖 Generated with Claude Code