Skip to content

fix(dispatcher): reclaim dead sessions without waiting on the cron - #300

Merged
sydevs-bot merged 19 commits into
mainfrom
claude/fix-288-reclaim-dead-sessions
Nov 22, 2026
Merged

sydevs-bot merged 19 commits into
mainfrom
claude/fix-288-reclaim-dead-sessions

Conversation

@sydevs-bot

@sydevs-bot sydevs-bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • An event run now reclaims an expired lock and drains a missed unlock, so a dead session holds its item for minutes rather than hours.
  • This repo's sweeper cron moves off :00/:30, where GitHub drops the most schedule runs.
  • Joined: sweep-timeout now re-reads the record before it kills a lock — this change is what makes that window wide enough to matter.
  • Joined: apply writes nothing to an issue that has moved, which a plan behind a transfer made reachable.
  • Joined: the stale "about eight runs a day" figure in docs/routine-setup.md and journalTick, and two comment promises the measured cadence never kept.

Change outline

Both defects had one cause: the half-hourly sweep was the only reader of a lock nobody will unlock. It asks for 48 runs a day and lands 3.4.

Flow — what an event run resolves

 resolve(event)                                   dispatcher/resolve.mjs
   eventTargets(event)                            # the item the event names
   schedule or workflow_dispatch → stop here
   cheapView(repo)                                # 2 GraphQL pages, fetched once
+  expiredLockTargets(the view's locked items)    dispatcher/sweep.mjs
+    minus the journal's, minus the event's own
+    one record read each, `reconcileMaxPerEvent` of them at most
+    a read that throws → skip that item
+    no `current` → sweep-timeout                 # a lock with no record
+    `current.deadline` passed → sweep-timeout
-  driftTargets(view)                             # what is left of the cap
+  driftTargets(view)                             # what the cap and the reclaim leave

Flow — the cron, which now leaves the journal out

 listSweepTargets(repo)                           dispatcher/sweep.mjs
-  locked items by label → a record read each → sweep-timeout
+  locked items by label → expiredLockTargets     # same facts, and the journal out
   listLeases → sweep-lease
   open PRs → sweep-pr, sweep-orphan
   cheapView → driftTargets

Its locked set still comes from REST, not from the cheapView below it: that view answers [] on one GraphQL failure, and the cron is the backstop that must still reclaim then. Said in a comment, because two sources read as an oversight.

Behaviour — one plan for an item whose unlock was lost

 decide(target, snapshot)                         dispatcher/decide.mjs
   route(target)                                  # the event's own rule
+  its plan already carries unlocked/timeout/releaseLease → no drain
+  no `current`, or ownUnlock → no drain
+  else the drain: route(unlock, { missed })
+    releases the lease, archives `current`, drops a refused `pending`
+    a continue or a relay the lost session asked for
+    derives nothing — see below
+  the drain started something → route the event against a held item instead
   withPushRoute → syncStatus
 case 'unlock'                                    dispatcher/decide.mjs
   a fresh continue request → continueNext
   a PR with a fresh relay request → relayPlan
-  a PR → evaluatePr
+  a PR → evaluatePr, unless `missed`: every PR event derives that anyway
   an issue → re-dispatch its pending verb        # `act` drops it where the event is that comment
   …the rest of the issue's residue, unchanged
 case 'sweep-timeout'                             dispatcher/decide.mjs
-  timeout
+  the lock is off → the unlock path owns it
+  no record → timeout
+  the deadline has passed → timeout
+  else → a note: it was re-fired since the sweep found it

Behaviour — a plan that outlives its issue

 apply(plan)                                      dispatcher/apply.mjs
   for each action
+    the issue has moved → skip it: `t.number` is not this issue any more
     …
   the hand-over comment, the Status, the record save   # already read `moved`

Preview

No preview surface.

Test results

  • Lean gate: ✓ claude plugin validate ./workflow --strict && node --test workflow/lib/*.test.mjs — 156 tests, from this worktree
  • Targeted specs: ✓ node --test dispatcher/test/*.test.mjs — 414 tests, 11 new
  • Build: N/A

Every new test was watched failing first, against main or against the commit it fixes. Two are regression guards that pass either way, named in the Detail block.

Manual verification

  1. With BOT_DISPATCH=dry, comment on any issue in a repo that has another item locked, and read the resolve job's log: it should list that item's sweep-timeout target beside the comment's own.
  2. Confirm the moved cron fires: gh run list -R sydevs/claude-workflow -w "Workflow state" -e schedule should show runs near :07 and :37.
  3. The drain itself needs a lost unlock run to observe for real. The honest check is the next time one happens: the item's status comment should show the session archived, and the event's own work done, in one act leg.

Notes for reviewer

  • The drain derives nothing, and that is the load-bearing decision. Routing the unlock and the event both derive the same snapshot, and parts of evaluatePr run ahead of its lock guard on purpose — so the first version of this planned ['unlocked','proxyApprove','proxyApprove'] and ['unlocked','dismissStale:7','dismissStale:7'], the second of which answers 422 and kills the act leg. The review pass caught it; b0c8e87 has the trace.
  • What the drain gives up: on a PR, nothing — every PR event funnels into evaluatePr. On an issue it gives up nothing either: it re-dispatches the pending verb under issue_comment, which is the draining leg's own reason, so act's seen drops it.
  • reconcileMaxPerEvent now bounds record reads as well as drift targets — the $comment in loop-config.json says so. Worst case is 10 loadRecord calls per event run, and loadRecord pages comments, so a long thread is more than one call. The free alternative, if the cost shows: cheapView could carry the lock's LABELED_EVENT age at no extra round trip, and skip any lock younger than the longest timeoutsMinutes.
  • Not taken, deliberately: reclaiming on the lease's 422 in apply.mjs instead. It would make all three residue shapes self-healing at first contact, with no dependence on an event — but it adds a write path at the compare-and-swap, which is the one place in this system where being wrong is worst. Worth its own ticket if you want it.
  • Noticed, not changed: apply.mjs's timeout and retry arms fire a handler from the record without the enabledHandlers check that case 'fire' applies. Pre-existing, and it needs write access to the bot's status comment.
  • Each commit is separately revertable, in this order: the reclaim, the drain, the cron, the docs, then the review-pass commits — five from the build's own pass, eight answering the critic's seven threads.
  • Only this repo's workflow-state.yml changes. Each product repo's copy is a one-line follow-up there, as the ticket says.
Detail

Fixture pre-mortem. The new tests build three fixtures, each checked against the real thing:

  • the status comment is written by renderRecord({ ...emptyRecord(), current }) from dispatcher/record.mjs, so the fake cannot drift from the writer;
  • the cheap view's GraphQL nodes, against the ISSUES query in dispatcher/reconcile.mjs — trimmed to the two fields the assertions turn on, since cheapView optional-chains the rest;
  • labels.lock, labels.journal, projects.number and identity.expectedLogin are read from the real loop-config.json, as sweep.test.mjs does.

A locked item is given board Working, so allowedStatuses finds no drift and the reclaim is the only reason a target can appear; the shared-cap case adds one unlocked item on Working, which is the drift half it shares the cap with. The moved-issue test extends lifecycle.test.mjs's existing board fake with GitHub's transferIssue answer.

The two regression guards pass on main by design — ownUnlock and an empty record read exactly as before, and a cheap view that throws reclaims nothing. They hold the acceptance criteria that say "exactly as before".

Review passes that ran. /simplify (four lenses: reuse, simplification, efficiency, altitude) and /code-review high; no routine has pr-review-toolkit. The conditional security review ran — dispatcher/ and .github/workflows/ match this repo's securityReview.triggerPattern — and found nothing at reportable confidence, having traced eventLabel's inputs, the target's repo/kind/number, the drain's facts, the { ...s, locked: true } snapshot against every s.locked read, and whether the drain opens the unlock route to a non-member. comment-lint is clean.

Dismissed findings. A shared dispatcher/test/helpers.mjs for the two near-copy cheap-view fakes: the ticket requires sweep.test.mjs to pass unchanged, and a new module for two test files is a layer this PR cannot justify — the record fake was folded onto renderRecord instead, which is the part that could drift silently. Folding the three record-reading reasons into one lostUnlock rule: it would change sweep-lease's and reconcile's existing behaviour, and the guard is derived from the plan now, so nothing is hand-maintained. Promise.all over eventTargets and cheapView: pre-existing sequencing, no call-count change, and every loop in this file is serial await.

Rejected: a reliable outside clock. Decided on the ticket (A, 2026-11-21): no new service and no new secret. A quiet night waits for the cron, where few sessions run.

Rejected: re-queueing the event behind a synthesized unlock target in act's queue. act keys seen on repo#number:reason, so the event's own reason would be dropped — which is also what makes the drain's own re-dispatch of that comment harmless.

The cross-repo window is unchanged. sweep-lease's caveat still holds: no concurrency group spans repositories. Events for one item in one repo are already serialized by dispatch-<repo>-<n>, which is what makes draining here safe.

Closes #288

🤖 Generated with Claude Code

https://claude.ai/code/session_01Mg9rjYpfDPpvEvyFZAbfNn

Each repo's `workflow-state.yml` asks for a sweep every half hour and gets
about 3.4 a day, with gaps past ten hours (measured 2026-11-13 to
2026-11-20, all five repos). That cron was the only reader of a lock past
its deadline, so a dead session held its item for up to ten hours and three
attempts could take more than a day. On 2026-11-20 the SahajCloud locks that
expired at 17:26Z were still held at 22:16Z, and a manual
`workflow_dispatch` cleared them.

An event run now reclaims what it can already see. `listSweepTargets`'s lock
loop becomes `expiredLockTargets`, taking the locked items instead of
querying for them: the cron reads them by label as before, and `resolve`
passes the ones the cheap view it already fetched shows carrying the lock.
The `sweep-timeout` targets go before the drift ones, under the one
`reconcileMaxPerEvent` cap and the same `skip` set, so the event's own item
is never swept.

The new cost is one record read per locked item. CI events arrive many times
an hour across the five repos, so while the loop is busy an expired lock
clears within minutes; a cheap view that cannot answer reclaims nothing, and
the cron is still the backstop for a quiet night.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjYpfDPpvEvyFZAbfNn
A session that removes its own lock leaves `current` in the record and its
lease ref on the item. The `unlock` run is what releases both, and when that
run fails the ref stays: every later fire for the item is refused as
contention until a sweep reads it. `reconcile` and `sweep-lease` already
read the record that way; nothing else did.

sydevs/WeMeditateWeb#326 lost two events to it. sydevs-bot's REST quota ran
out from 23:00Z to 23:10Z on 2026-11-20, taking the
`pull_request_target.unlabeled` run for a review-pr session that had just
unlocked. A Cloudflare comment at 23:10Z then set the board to Pending, so
no drift target came either, and the member's `address` at 23:32Z was
refused with "another pass holds the lease". A manual dispatch at 23:56Z
cleared it.

`decide` now reads that unlock before the event's own rule, for every reason
but the three that read the record themselves. It takes the residue only —
the lease, the archive, a continue, a relay — because re-deriving the item
is the event's own job, and the unlock's PR derivation would be the second
`evaluatePr` of the same pass. Where the residue starts a session, the event
records a recheck instead and is re-derived on that session's unlock, which
is what an event arriving under a lock does.

`ownUnlock` is unchanged: a lock the dispatcher took off itself, and an item
with no `current`, read exactly as before. The cross-repo window named in
`sweep-lease` is unchanged too, since events for one item in one repo are
already serialized by the `dispatch-<repo>-<n>` concurrency group.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjYpfDPpvEvyFZAbfNn
GitHub drops or delays `schedule` runs most at `:00`, and this file asks for
a sweep at `:00` and `:30`. Four crons here land about 6.5 runs a day
between them, against the 48 the sweeper alone asks for.

`7,37` is the same half-hourly ask, away from the minute every public
repository's cron crowds into. Nothing matches this cron string: only the
`20 13 * * *` dependency check is read by name, in dispatcher.yml.

Only the `claude-workflow` copy changes. Each product repo's own
`workflow-state.yml` is a one-line follow-up there.

The `pull_request_review_thread` note promised a resolved thread within 30
minutes, which the measured cadence never delivered.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjYpfDPpvEvyFZAbfNn
Three figures and one rule were stale.

`#the-reconciler-replaces-the-drift-window` described the cron as the only
reader of an expired lock. It now carries the 2026-11-13 to 2026-11-20
measurement — 3.4 runs a day per product repo, 6.5 here, gaps past ten hours
— the event-driven reclaim that answers it, and why this repo's cron asks
for `7,37`.

`#a-lease-past-its-deadline-is-reclaimed` named only the 503 between the
lease and the label. A lost unlock run leaves the same residue, as
sydevs/WeMeditateWeb#326 did on a spent REST quota, so it names the event
that reads it and what the event takes from it.

`#the-journal-tally-needs-a-writer-that-cannot-stop` and the same figure in
`docs/routine-setup.md` and `journalTick`'s comment read "about eight a day"
from the 2026-10-06 window. The cadence has halved since, which is the
argument for re-counting yesterday, so each figure is replaced with the
current one and the trend.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjYpfDPpvEvyFZAbfNn
Three findings from this branch's review pass.

**The cap bounded the targets, not the reads.** A lock inside its deadline
yields no target, so `out.length >= limit` never tripped on the common path
and one event run read a record for every locked item in the repo — the
maximum I/O for no output, on the same 5,000/hr REST bucket whose exhaustion
is half of what this branch is fixing. The loop now counts reads, so an event
run pays at most `reconcileMaxPerEvent` of them. The docstring's "one record
read per item" was wrong too: `loadRecord` pages comments, and pages all of
them when the item has no record, which is one of the two things this
function looks for.

**The journal was in the worklist.** `driftTargets` excludes `labels.journal`
one line away; the new selection did not, so a journal issue carrying the
lock would have cost a record read and a dispatch leg before `decide` threw
it away. AGENTS.md asks for that exclusion in every query added.

**`skip` left the helper.** Its one caller already filters the same view a
line earlier, so the event's own item goes out with the journal's, and the
`now` and `event` defaults go with it — both callers pass both, and the cron
now spells `event: 'schedule'` as its other reasons do.

The cron still reads its locked set by REST rather than from the cheap view
fetched below it. That is deliberate: the view answers `[]` on one GraphQL
failure, and the cron is the backstop that must still reclaim then. Said in a
comment, because the two sources read as an oversight otherwise.

`eventLabel` also replaces `resolveTargets`' inline copy, which had neither
the optional chaining nor the trailing-dot strip, so a `status` or `schedule`
run logged `status.` beside a target carrying `status`.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjYpfDPpvEvyFZAbfNn
Three findings from this branch's review pass, all about how the missed
unlock was placed rather than where.

**The exclusion list is gone.** Naming the three reasons that read the record
themselves was a hand-maintained set nothing pinned: a fourth such case would
have planned two `unlocked` actions and a doubled fire, with no test to catch
it. The guard now reads the plan instead — a reason that read the record
already carries `unlocked`, `timeout` or `releaseLease` — so the membership is
derived from what a case does.

**`facts.missed` is gone, and with it a PR/issue asymmetry.** It suppressed
the unlock case's `evaluatePr` but not its issue derivation, so the drain on
an issue ran the whole thing — `withdraw`, `anomaly('silent')`, the roadmap
bookkeeping, even a `transfer` that apply runs last on purpose because the
issue's number changes. Both halves now run, and the event's own rule is what
is guarded: when the drain started something — a session, a relay that lands
commits, a transfer — the event is not routed on top of it.

**And it is not routed by a second definition of "held".** The event is
derived against `{ ...s, locked: true }`, so the fifteen rules that already
say what a locked item means answer this too, including the ones that record a
`verifyDue` or a partial plan beside the recheck. `queue-failed` derives
against an amended snapshot the same way. A bare `[recheck()]` would have
thrown those away.

The new `TURN_TAKEN` set is deliberately not `MOVES`: `MOVES` answers whether
a sweep found anything worth saying, which is a different question, and
`relay` and `transfer` are not in it.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjYpfDPpvEvyFZAbfNn
The figure this branch re-measured had three homes before it and was heading
for five. AGENTS.md puts the story in `docs/why.md` behind an anchor, and
befe210 exists because the three copies went stale together.

So the yml comment, `journalTick`'s comment and `routine-setup.md` keep the
rule — the schedule does not keep to its cron — and cite the anchor for the
numbers. `docs/why.md` holds them.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjYpfDPpvEvyFZAbfNn
…nyway

Four findings from this branch's review pass, three of them real defects in
the drain as committed.

**Two derivations planned two of everything.** Every PR event funnels into
`evaluatePr`, so the drain and the event's own rule derived the same snapshot
and each planned its output. Proven by running `decide`:
`['unlocked','proxyApprove','proxyApprove']` — two approving reviews on the
owner's PR — and `['unlocked','dismissStale:7','dismissStale:7']`, whose
second call answers 422 and, through `handOver`, kills the `act` leg before
the record is saved. `rerunJobs` would double a POST and count one
infrastructure failure twice. `armAutoMerge` and `markReady` are idempotent in
`apply`; those three are not. `TURN_TAKEN` did not cover it, because
`stalePlan` and the disarm run ahead of `evaluateOpenPr`'s lock guard on
purpose.

So the drain no longer derives: `missed` suppresses the PR half outright, and
on an issue it suppresses the re-dispatch of the very comment that drained it
(`act` keys on `repo#number:reason` and would drop it, and the event's own
rule has the verb in hand). The event's facts ride along for that comparison.
The rest of the issue half — a continue, a relay, `withdraw`, the roadmap's
bookkeeping, the silent-end anomaly — is residue the event's rule cannot do,
so it stays.

**A record the reclaim cannot read must not cost the event its target.**
`expiredLockTargets` ran unguarded next to `cheapView`, which swallows by
design, and `installRetry` retries only 5xx. One 403 — the spent-quota
condition this branch cites — or one 404 on an unrelated locked item would
have failed the `resolve` job, dropping the member's verb silently. A read
that throws now skips that item, as `cheapView` and `listLeases` answer
nothing on a read failure.

**`sweep-timeout` killed whatever lock it found.** It never re-read the
record, unlike `sweep-lease` and `reconcile`. `resolve` decides in another job
and outside the per-item concurrency group, so a lock that expires and is then
legitimately re-fired could have its *new* session timed out, its lease
deleted and its handler fired again — two concurrent sessions and a false
`timed-out` anomaly. On the cron that window was a few runs a day; this branch
opens it to every event run, which is what makes it this PR's to fix.

`reconcileMaxPerEvent`'s comment in `loop-config.json` described drift targets
only; it bounds the reclaim's record reads first.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjYpfDPpvEvyFZAbfNn
…le set

`case 'unlock'` reads `facts.handler` as well as the `commentId` the drain
needs, and that handler is the dispatcher's own value — `expiredLockTargets`
takes it from the record it just read. No event arm mints a `handler` fact
today, so passing the event's facts through was safe, and a reason that
started minting one would have decided which handler the drain archived and
could continue.

Naming the one fact the drain uses closes the question instead of resting on
the absence.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjYpfDPpvEvyFZAbfNn
`apply` reads `moved` before the hand-over comment, the Status write and the
record save, because after a transfer `t.number` names whatever now holds that
number in the old repo — or nothing. The action loop did not, and did not need
to: `route` planned a transfer last, so nothing followed it.

A drained unlock changes that. Its residue can carry the transfer, and the
event's own rule is planned behind it, so a `label` or a `react` would land on
the wrong issue. The loop now reads `moved` too, which states the rule where
it belongs rather than resting on one plan's ordering.

Found while weighing whether to ask the reviewer about that ordering. The
guard is cheaper than the question.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjYpfDPpvEvyFZAbfNn
@sydevs-bot sydevs-bot added the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Nov 21, 2026
@sydevs-bot

sydevs-bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 no session running

recent dispatches
  • 18:31Z resolve-conflicts · attempt 1 · session · done
  • 18:31Z resolve-conflicts · attempt 1 · session
  • 04:22Z address-review · attempt 1 · session · done
  • 04:22Z address-review · attempt 1 · session
  • 04:07Z review-pr · attempt 1 · session · done

Written by the sydevs dispatcher. Sessions never edit this comment.

@sydevs-bot sydevs-bot moved this from Pending to Working in SYDevelopers Technical Roadmap Nov 21, 2026

@sydevs-bot sydevs-bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧐 Adversarial review

The diff matches the ticket: two defects with one cause, fixed at the cause. The reclaim reuses the cron's own loop and rides a cheapView the run already fetched, so only the record reads are new.

Both load-bearing decisions hold. Re-reading the record in case 'sweep-timeout' is what makes a target found outside the per-item concurrency group safe, and why a locked item that drifts too cannot time out twice: act re-gathers per reason. No contractSync surface is touched.

Findings

  • should-fix — resolve.mjs:87: drift does not skip what the reclaim targeted, so an unplaced expired lock is targeted twice.
  • should-fix — Streamline resolve.mjs:84: the candidate rule belongs in the helper the diff built, and the cron path lacks the journal exclusion.
  • should-fix — Streamline decide.mjs:1428: itsOwnComment guards what act's seen already drops.
  • should-fix — Streamline apply.mjs:119 and resolve.mjs:68: both comments narrate the change.
  • consider — test/resolve.test.mjs:131: the shared-cap case never exercises drift.
  • consider — docs/why.md:1593: the cadence has two homes in this file.

What was checked

Read on the branch: resolve.mjs, sweep.mjs, decide.mjs's four changed arms, apply.mjs's loop and doFire, index.mjs's act, reconcile.mjs's two readers, all four tests. doFire saves the record one call after the label, so the widened "lock without a record" window stays inside one call.

  • No dependency added. Only deps matches a cron string in dispatcher.yml, so 7,37 changes nothing.
  • Every lock reader in decide.mjs reads s.locked, never the label, so { ...s, locked: true } cannot diverge.
  • .claude/workflow.json on main declares no preview surface, as ## Preview says.
  • Streamliner: 5 pieces, 5 kept; 4 of 6 sketches held.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

Comment thread dispatcher/resolve.mjs Resolved
Comment thread dispatcher/resolve.mjs Resolved
Comment thread dispatcher/resolve.mjs Resolved
Comment thread dispatcher/decide.mjs Resolved
Comment thread dispatcher/apply.mjs Resolved
Comment thread dispatcher/test/resolve.test.mjs Resolved
Comment thread docs/why.md Resolved
@sydevs-bot sydevs-bot added bot:working Lock: a cloud session is running on this item. Removed when it ends. and removed bot:working Lock: a cloud session is running on this item. Removed when it ends. labels Nov 21, 2026
`skip` never gained the reclaimed numbers, so an expired lock that is also
drift — off the board, or behind a Status write that failed — was targeted
twice in one event run: a `sweep-timeout` and a `reconcile`, each spending a
drift slot and a full `gather` on an item already handled.

`allowedStatuses` answers `['working']` for a locked item and `driftTargets`
counts `board === undefined` as drift, so the overlap is not hypothetical: any
lock the board never received reaches both.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjWxyxuQfViTbKLZ5DX
`expiredLockTargets` was built as the owner of the reclaim, and the rule that
picks its candidates sat in `resolve` instead — so the cron, its other caller,
never had the journal exclusion at all. A locked journal issue was a
`sweep-timeout` target there, and `untouched` then dropped every write the plan
asked for.

The helper now takes the locked items with their labels and a `skip` set, and
drops the journal's and the caller's own targets before it reads a record.
`resolve` hands it the cheap view's locked items; the cron maps the label read's
names across. Line-neutral, and one rule with one home.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjWxyxuQfViTbKLZ5DX
The cadence story belongs to the `why.md` anchor two lines below, and "until
now was the only thing that reclaimed a lock" narrates the diff rather than the
code. What is left is the one fact a reader cannot derive here: an empty cheap
view reclaims nothing, so the cron is still the backstop.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjWxyxuQfViTbKLZ5DX
`docs/code-comments.md` puts change context in the commit message, and a
comment must read correctly to someone who never saw the diff. "`route` used to
put the transfer last" is a note to a diff reviewer, and the post-loop writes
show that they read `moved` themselves. The guard is unchanged.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjWxyxuQfViTbKLZ5DX
`itsOwnComment` was true only when `facts.commentId` matched the pending
verb's comment — so this event is that comment, so the leg's reason is
`issue_comment`, which `act` has in its `seen` set before the plan is applied.
The target it guarded was dropped either way (`index.mjs` `act`).

So the condition, its comment and the `commentId` the drain threaded for it all
go, and the drain carries `missed` alone. The test now holds the invariant the
deletion rests on: every target the drain emits on this path carries the leg's
own reason.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjWxyxuQfViTbKLZ5DX
All three nodes carried board `Working`, so `driftTargets` answered `[]`
whatever limit it was given and `limit - expired.length` stayed unproven. A
fourth node with no lock on `Working` is a drift target: at a cap of two the
reclaim spends it and the drift target is absent, and at four it is the one
`reconcile` the remaining slot admits.

Watched failing with `limit` in place of `limit - expired.length`.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjWxyxuQfViTbKLZ5DX
Two paragraphs in this file carried it: the journal-tally section gave 6.5 runs
a day here, 3.5h median and 8.7h worst, and the reconciler anchor gave 3.4 a
day per product repo and 6.5 here. `documentation.md` reads a fact restated
elsewhere as a deletion.

Every figure now sits under the reconciler anchor, which gains this repo's own
gaps and the October window it only alluded to, and the journal-tally paragraph
keeps its consequence — no tick is guaranteed near midnight — and links there.
Rewraps the routine-setup paragraph the earlier commit left long.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjWxyxuQfViTbKLZ5DX
This branch already took "within 30 minutes" out of `routine-setup.md` and the
`pull_request_review_thread` note, because the measured cadence never kept it.
The duplicate-day sweep carried the same promise one section above the cadence
figures. It runs on the same `schedule` event, so it keeps the same rule: the
next run, not a clock.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjWxyxuQfViTbKLZ5DX
@sydevs-bot

sydevs-bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor Author

Seven critic threads, all adopted.

Gates ✓ 156 + 414, 11 new. Security review: clean.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

@sydevs-bot sydevs-bot removed the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Nov 21, 2026
@sydevs-bot sydevs-bot moved this from Working to Pending in SYDevelopers Technical Roadmap Nov 21, 2026
@sydevs-bot

Copy link
Copy Markdown
Contributor Author

This draft has had no CI activity for hours and no session holds it. A mention (@sydevs-bot) or a push from you starts me again.

🤖 sydevs dispatcher

@sydevs-bot sydevs-bot moved this from Pending to Awaiting in SYDevelopers Technical Roadmap Nov 21, 2026
@sydevs-bot sydevs-bot added the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Nov 22, 2026
@sydevs-bot sydevs-bot moved this from Awaiting to Working in SYDevelopers Technical Roadmap Nov 22, 2026
main split decide.mjs into actions.mjs, predicates.mjs and approvals.mjs,
which collided with both files this branch touches.

- resolve.mjs: `isBot` now comes from predicates.mjs, and this branch's
  `expiredLockTargets` import from sweep.mjs stays. Both sides kept.
- decide.mjs `case 'sweep-timeout'`: this branch's record re-read is kept,
  written with main's `timeout()` and `note()` constructors instead of the
  `{ type: 'timeout' }` literals the file no longer uses.

The drain's `missed` guard still earns its place after the split: `evaluatePr`
calls into approvals.mjs ahead of its lock guard, so deriving twice would
still plan two approvals.

Lean gate: 161 tests. dispatcher specs: 414 tests. Both pass from this
worktree, and the merged tree's diff against main is this branch's 14 files
unchanged.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjWZQNxkHBWwffrDUhv
@sydevs-bot

Copy link
Copy Markdown
Contributor Author

Merged main in. Its split of decide.mjs into actions.mjs, predicates.mjs and approvals.mjs hit both files this branch touches.

  • resolve.mjs: isBot now comes from predicates.mjs, and this branch's expiredLockTargets import stays. Both sides kept.
  • decide.mjs case 'sweep-timeout': this branch's record re-read is kept, written with main's timeout() and note() constructors.

Neither hunk had a second defensible reading, so nothing here needs your confirmation.

The drain's missed guard still earns its place after the split. evaluatePr calls into approvals.mjs ahead of its lock guard, so deriving twice would still plan two approvals.

Lean gate: 161 tests. Dispatcher specs: 414 tests. Both pass from the worktree. The merged tree's diff against main is this branch's 14 files, unchanged.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

@sydevs-bot sydevs-bot removed the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Nov 22, 2026
@sydevs-bot
sydevs-bot marked this pull request as ready for review November 22, 2026 18:36
@sydevs-bot
sydevs-bot requested a review from Ardnived November 22, 2026 18:36
@sydevs-bot
sydevs-bot enabled auto-merge November 22, 2026 18:36
@sydevs-bot sydevs-bot moved this from Working to Awaiting in SYDevelopers Technical Roadmap Nov 22, 2026
@sydevs-bot
sydevs-bot added this pull request to the merge queue Nov 22, 2026
@sydevs-bot sydevs-bot moved this from Awaiting to Pending in SYDevelopers Technical Roadmap Nov 22, 2026
Merged via the queue into main with commit 1755264 Nov 22, 2026
29 of 30 checks passed
@sydevs-bot
sydevs-bot deleted the claude/fix-288-reclaim-dead-sessions branch November 22, 2026 23:51
@sydevs-bot sydevs-bot moved this from Pending to Done in SYDevelopers Technical Roadmap Nov 22, 2026
sydevs-bot pushed a commit that referenced this pull request Nov 22, 2026
…cher-rate-limit

main's #300 gave the event run a reclaim pass — `expiredLockTargets`, which
reads a record per locked item — and this branch gave the same function a
budget floor and a wider trusted set. Both sides are kept.

# Conflicts:
#	dispatcher/index.mjs
#	dispatcher/resolve.mjs
#	dispatcher/sweep.mjs
#	dispatcher/test/resolve.test.mjs
#	loop-config.json

`dispatcher/sweep.mjs` is the one hunk git merged cleanly and wrongly.
main's new `expiredLockTargets` reads `config.identity.expectedLogin`, a
string, and passes it to `loadRecord`; on this branch `isLogin` throws
unless the trusted set is a list, and the caller swallows that throw with
`catch { continue }`. The textual merge therefore reclaims nothing, for
ever, in silence. The declaration becomes `dispatcherLogins(config)`, and
the one in `listSweepTargets` goes: main moved the only read of it into the
new function. Three of main's own tests fail without this.

`dispatcher/resolve.mjs` keeps both passes behind one floor check, so an
event run under `dispatch.rateLimitFloor` keeps only its own targets and
the cron covers both the reclaim and the drift. Each side had written the
shed as covering what it knew about; the merged comment says what it now
covers. A review thread asks whether the reclaim should be exempt.

`dispatcher/index.mjs` keeps the `try`/`finally` that logs what a resolve
leg spent, with main's `eventLabel(context)` inside it.

`dispatcher/test/resolve.test.mjs` keeps both suites. main's fixture gains
a readable REST budget above the floor: without one it reclaims only
because `resolve` cannot read a budget at all, which would hide a floor
regression rather than test the reclaim.

`loop-config.json` keeps main's sentence on what `reconcileMaxPerEvent`
caps and this branch's two on `githubRetry` and `rateLimitFloor`.

Gates from the worktree: `claude plugin validate ./workflow --strict` ✓,
`node --test workflow/lib/*.test.mjs` 162 ✓, `node --test
dispatcher/test/*.test.mjs` 440 ✓, `claude plugin validate .` ✓,
`comment-lint.mjs --base origin/main` ✓.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjYdN4RMqb2w2cA3xjY
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

fix(dispatcher): reclaim dead sessions without waiting on the cron

3 participants