Skip to content

fix(dispatcher): end a lease when its session waits on a prompt #268

Open

Description

@Ardnived

Summary

A loop session that hits a permission prompt doesn't fail: it waits until its lease expires, writes nothing, and the sweep then re-fires it into the same wall, up to dispatch.maxAttempts (3). docs/why.md#a-blocked-run-cannot-see-that-it-is-blocked records this as a known gap, and asserts that the routines API reports such a session as worker_status: requires_action within about 90 seconds. The dispatcher never asks.

It has now cost a full lease again. The set build for sydevs/SahajCloud#1078 ran 16:39–22:39Z on 2026-11-16, its whole 360 minutes. It left no branch, no PR, no journal entry, and an unmoved lease.

Validated 2026-11-23: this ticket is not ready for implement. Step 1 cannot be done by a loop run, and the request parts 2 and 3 poll with is not settled — no endpoint documented today returns a prompt-waiting status. Both readings are attended work, listed as step 1 and asked as question 1. The measurements behind that are in ## Notes.

Joined: a session that never started is charged an attempt too. When the account hit its usage limit on 2026-11-19/20, every fire still succeeded, but the sessions sat queued for hours. #285's review fired at 09:55Z and began at 15:11Z, past its deadline, so payload.mjs refused it. The sweep counted each such dispatch as timed out and re-fired it into the same queue. Today's journal, #286, holds 36 anomalies, and about a dozen items reached attempts-exhausted with no session having done any work. Both cases come down to one missing check: the sweep reading a session's status before it charges a timeout.

Open questions

  • 1. Build the poll on an undocumented field of a research-preview API?
    • A — Measure first, then build (recommended): in an attended session, record here the request that returns a session's prompt-waiting state — URL, headers, and a sample body showing the field and its value — and whether ROUTINE_TOKEN_<REPO> may make it or a new secret is needed. The poll is then built from measured fact. Cost: one attended session. Risk: an undocumented field can change under us, which criterion 5's fallback contains.
    • B — Build part 3 from timing alone: not viable. The record holds firedAt and the session id (dispatcher/apply.mjs:589-593), never a start time, so "never started" is not derivable without the same status read.
    • C — Harden only the first line of defence: extend start-run's prediction and leave the dispatcher alone. Needs no API and closes nothing — a run that cannot predict its prompt still burns the lease, which is the failure this ticket exists for.

Approach

  1. Attended: confirm the cause, and settle the request. A loop run can do neither (## Notes), so this step is a person's, and parts 2 to 4 wait on it.
    • Read cse_01Mg9rjXNTqeCAHtsoP4AK2q's log and record here the prompt and the path it named. The cause space is wider than Protected Paths, so do not assume one: a cloud run starts in auto mode, and the routines docs say repeated classifier blocks escalate to a prompt that waits for a person. This ticket had already excluded .claude/workflow.json, the one protected path it would otherwise have touched. A cause other than a prompt still leaves parts 2 and 3 worth building; name the real one here.
    • Answer question 1 with the request and the token scope.
  2. Poll for it. For every item whose rec.current carries a session (dispatcher/apply.mjs:589-593 writes it), the sweep (expiredLockTargets in dispatcher/sweep.mjs) reads that session's status.
    • On a prompt-waiting status:
      • Record the dispatch as outcome: 'blocked on a prompt', not timed out.
      • Release the lease and the lock exactly as the timeout path does (dispatcher/apply.mjs:398-411).
      • Do not re-fire: the next attempt would stop on the same prompt.
      • Hand the item back to a person with one comment naming the session. Where the API returns the session's events, quote the tool and the path that prompted, so a maintainer who cannot open the session still sees why.
    • Any other status, an unexpected response shape, or an API error leaves the item to today's deadline path.
  3. A session that never started. In the same poll, when a lock is past its deadline and the session never began work:
    • Do not count an attempt, and do not re-fire at once: a new session would queue behind the old one.
    • Record rec.pending with reason the session never started and a retryAfter from dispatch.fireRetry.default429Seconds, as a failed fire does (dispatcher/apply.mjs:599-608), and release the lease and lock.
    • Where the API allows it, stop the stale session, so it cannot wake later and spend usage refusing an expired payload.
    • Post one journal anomaly, never-started, apart from the timed-out one at dispatcher/apply.mjs:413-419.
  4. Count it. The journal tally counts blocked on a prompt apart from timed out, and counts never started too, so improve-loop can tell a stall or a queue from a slow run.
  5. Docs. Rewrite docs/why.md#a-blocked-run-cannot-see-that-it-is-blocked: the gap is closed, start-run's protected-path check stays as the first line of defence, and auto mode's repeated-block escalation is named as the second way in.

Acceptance criteria

  • This ticket records the request that returns a session's prompt-waiting state, and whether ROUTINE_TOKEN_<REPO> may make it.
  • This ticket records the cause of cse_01Mg9rjXNTqeCAHtsoP4AK2q's stall, read from the session itself, or says why it stays unread.
  • A dispatched session waiting on a prompt is reclaimed by the next sweep: lease and lock released, outcome blocked on a prompt, no re-fire.
  • The hand-back comment names the session, and the prompting tool and path where the API returns them.
  • A session in any other state is untouched, and an API failure or an unexpected response shape falls back to the deadline path.
  • A lock past its deadline whose session never started is released to Pending with a retry time, with no attempt counted and no immediate re-fire.
  • The journal tally reports prompt-blocked and never-started dispatches separately.
  • docs/why.md describes the new behaviour, and names auto mode's repeated-block escalation beside Protected Paths.

Verification checklist

  • node --test dispatcher/test/*.test.mjs passes.
  • A sweep test with a stubbed prompt-waiting status yields a release and a hand-back comment, and no fire.
  • A sweep test with a lock past its deadline and a stubbed not-started status yields a release, rec.pending with retryAfter, the same attempt, and no fire.
  • Sweep tests with a stubbed running status, with a 404 or 500, and with a body missing the status field, each yield no new action.
  • claude plugin validate ./workflow --strict && node --test workflow/lib/*.test.mjs passes.

Notes

Prior art: 82b1559 (#108). Six consecutive WeMeditateWeb#97 runs each stalled on a .npmrc write and burned a 150-minute lease. That commit added start-run's protected-path check, which only works when a session predicts the path before writing.

Why step 1 is attended. Measured in this revise run on 2026-11-23:

  • RemoteTrigger, the tool docs/routine-setup.md:753 names for list_runs → get_run_log, is absent from a routine session. ToolSearch returns no routines tool, and no /schedule skill is loaded. Reading a run's log through /schedule needs Claude Code v2.1.227 or later (routines docs); this session reports v2.1.42.
  • The routines REST API needs ROUTINE_TOKEN_<REPO>, a GitHub Actions secret. No ROUTINE_TOKEN_* exists in a session's environment, and dispatcher/fire.mjs only POSTs /fire.
  • No endpoint documented today returns worker_status or requires_action. GET /v1/sessions returns status ∈ rescheduling | running | idle | terminated, none of which is a prompt-waiting state, and the routines page documents no runs or status endpoint and calls the surface a research preview whose API may change. worker_status is attested only by docs/why.md and by the upstream issue below.

Upstream, not reproduced here: anthropics/claude-code#111791, opened 2026-11-23, reports that cloud routines ignore allowed_tools and that every gh call stops on a permission prompt at worker_status: requires_action. start-run names gh api -X GET search/issues as its search fallback, so if that holds for this account the loop's own sanctioned fallback is a stall source. Against it: gh api repos/sydevs/claude-workflow/issues/268 ran with no prompt in this routine session at 22:45Z, as did the 2026-11-08 re-measurement in docs/why.md#a-routine-cannot-reach-the-github-api. Deliberately not tested further — a gh call that does prompt burns the lease it is testing from, so that experiment is attended.

Stale file:line references in this ticket's earlier Approach, corrected above: the timeout path is dispatcher/apply.mjs:398, not :343, and the retryAfter pending write is :599-608, not :569-572. dispatcher/apply.mjs moved under #299 and #300 after this ticket was filed.

Activity

  1. added theissue type on Nov 17, 2026
  2. Ardnived commented on Nov 23, 2026

    @Ardnived
    ContributorAuthor

    @sydevs-bot revise - validate this ticket by attempting step 1

  3. added
    bot:working
    on Nov 23, 2026
  4. sydevs-dispatcher commented on Nov 23, 2026

    @sydevs-dispatcher

    🤖 no session running

    recent dispatches
    • 22:22Z revise · attempt 1 · session · done
    • 22:22Z revise · attempt 1 · session

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

  5. sydevs-bot commented on Nov 23, 2026

    @sydevs-bot
    Contributor

    Validated: a loop run cannot do step 1. RemoteTrigger (list_runs → get_run_log) is absent from a routine session, no /schedule skill is loaded, and its log read needs Claude Code v2.1.227 — this session is v2.1.42. The routines REST API needs ROUTINE_TOKEN_<REPO>, a secret no session holds. So the stall's cause is still unread.

    Worse for parts 2 and 3: no endpoint documented today returns worker_status or requires_action. GET /v1/sessions returns status ∈ rescheduling|running|idle|terminated. The poll would rest on an undocumented field of a research-preview API, so that is now question 1.

    Also corrected in the body: the cause space is wider than Protected Paths — auto mode escalates repeated blocks to a waiting prompt — and two file:line refs had drifted. The timeout path is apply.mjs:398, the pending write :599-608.

    Incidental finding filed as #311: ~17 unused MCP servers attach to every dispatch, which docs/routine-setup.md says cannot happen.

    Answer question 1, then @sydevs-bot implement starts the build.

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


    Generated by Claude Code

  6. removed
    bot:working
    on Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Fields

    Priority

    High

    Hold Until

    None yet

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions