claim-next-task.sh: unbounded serial setup (lister + claim_alive_runs) blows the 30 s prompt-expansion ceiling — overlap the calls and budget the whole tick (matou-app#286) #128

Closed
opened 2026-09-04 23:09:44 +00:00 by ben · 1 comment
Owner

Upstream port of Matou/matou-app#286 (two healer incidents, fb4f495905cb and 0fd2fa26ccd7, with timings). Files: list-ready-tasks.sh, claim-next-task.sh (vendored byte-identical into consumers via FACTORY_MANIFEST, so the fix must land here).

Problem

claim-next-task.sh runs, before CLAIM_NEXT_BUDGET (22 s) is ever consulted:

ready="$(bash "$lister")"      # list-ready-tasks.sh: 10–26 s measured (issues page + dependency fan-out + GET /pulls?state=open when LANDING=pr, ~1.4 s per open PR)
alive="$(claim_alive_runs)"    # GET /actions/tasks?limit=100: 4.7–9 s, O(actions history)

That is 15–19 s of unbounded serial setup under a 30 s hard ceiling (Shell expression … timed out after 30008ms → PromptExpansionTimeoutError, tick RED). When it just fits, the 22 s guard bails the claim walk with claimable work on the queue — a silently wasted tick. Measured on matou-app with 5–7 open PRs; grows with open PRs and with actions history. Forgejo-side latency (matou-app#335: ~256 req/min, 10 % >3 s) makes it worse, but the shape is the harness's.

Ask

  1. Overlap the independent calls. Inside list-ready-tasks.sh, kick GET /pulls?state=open (and the standing-drive listing) off in the background at the top and wait at the use site. In claim-next-task.sh, run the lister and claim_alive_runs concurrently — alive is consumed only as claim_won's third argument and the lister posts nothing. Preserve the fail-open || true on /pulls and the fail-closed || {{ echo '[]'; exit 0; }} on the alive fetch. Setup collapses to max(lister, alive) ≈ 10 s.
  2. Budget the whole tick. Put setup + walk under one wall-clock budget (e.g. CLAIM_NEXT_TOTAL_BUDGET, default ~24 s, below the 30 s expansion ceiling): on overrun print [] and exit 0 — one lost tick, zero Claude tokens, never a RED.
  3. Optional: replace the /pulls listing with a cheaper "open PR with head agent/issue-N exists?" check — the lister only needs existence, not per-PR mergeability.

Acceptance

  • time bash list-ready-tasks.sh with 7 open PRs ≤ ~13 s (was 26 s).
  • A tick where Forgejo takes 40 s to answer emits [] with rc 0 (no PromptExpansionTimeoutError).
  • Bump the factory ref so consumers (matou-app#286 → FACTORY_REF bump + re-vendor) can pick it up.

Related upstream gaps in the same family, filed by the same consumer: matou-app#143 (standing-drive label filter fan-out), matou-app#145 (empty PR shells drop tickets).

Upstream port of Matou/matou-app#286 (two healer incidents, `fb4f495905cb` and `0fd2fa26ccd7`, with timings). Files: `list-ready-tasks.sh`, `claim-next-task.sh` (vendored byte-identical into consumers via FACTORY_MANIFEST, so the fix must land here). ## Problem `claim-next-task.sh` runs, **before** `CLAIM_NEXT_BUDGET` (22 s) is ever consulted: ``` ready="$(bash "$lister")" # list-ready-tasks.sh: 10–26 s measured (issues page + dependency fan-out + GET /pulls?state=open when LANDING=pr, ~1.4 s per open PR) alive="$(claim_alive_runs)" # GET /actions/tasks?limit=100: 4.7–9 s, O(actions history) ``` That is 15–19 s of unbounded serial setup under a 30 s hard ceiling (`Shell expression … timed out after 30008ms` → `PromptExpansionTimeoutError`, tick RED). When it *just* fits, the 22 s guard bails the claim walk with claimable work on the queue — a silently wasted tick. Measured on matou-app with 5–7 open PRs; grows with open PRs and with actions history. Forgejo-side latency (matou-app#335: ~256 req/min, 10 % >3 s) makes it worse, but the shape is the harness's. ## Ask 1. **Overlap the independent calls.** Inside `list-ready-tasks.sh`, kick `GET /pulls?state=open` (and the standing-drive listing) off in the background at the top and `wait` at the use site. In `claim-next-task.sh`, run the lister and `claim_alive_runs` concurrently — `alive` is consumed only as `claim_won`'s third argument and the lister posts nothing. Preserve the fail-open `|| true` on `/pulls` and the fail-closed `|| {{ echo '[]'; exit 0; }}` on the alive fetch. Setup collapses to `max(lister, alive)` ≈ 10 s. 2. **Budget the whole tick.** Put setup + walk under one wall-clock budget (e.g. `CLAIM_NEXT_TOTAL_BUDGET`, default ~24 s, below the 30 s expansion ceiling): on overrun print `[]` and exit 0 — one lost tick, zero Claude tokens, never a RED. 3. Optional: replace the `/pulls` listing with a cheaper "open PR with head `agent/issue-N` exists?" check — the lister only needs existence, not per-PR mergeability. ## Acceptance - `time bash list-ready-tasks.sh` with 7 open PRs ≤ ~13 s (was 26 s). - A tick where Forgejo takes 40 s to answer emits `[]` with rc 0 (no PromptExpansionTimeoutError). - Bump the factory ref so consumers (matou-app#286 → `FACTORY_REF` bump + re-vendor) can pick it up. Related upstream gaps in the same family, filed by the same consumer: matou-app#143 (standing-drive label filter fan-out), matou-app#145 (empty PR shells drop tickets).

close-report for #128 — status success

✅ close-report gates passed — every claim verified against main; issue closed.

envelope
{
  "issue": 128,
  "status": "success",
  "commits": [
    "d1e5faa30fcdd9c8e6f1596450e38cc3f69ae7f2"
  ],
  "changed_files": [
    "list-ready-tasks.sh",
    "tests/list-ready-tasks-test.sh",
    "STATUS.md",
    "docs/GOTCHAS.md"
  ],
  "tests": [
    {
      "command": "bash tests/list-ready-tasks-test.sh",
      "exit_code": 0
    }
  ],
  "criteria": {
    "Overlap the independent calls in list-ready-tasks.sh (/pulls + standing-drive backgrounded at top, waited at use site; fail-open on /pulls, drive listing gated)": "list-ready-tasks.sh: background kicks after api() def, reaped at /pulls and standing-drive use sites with rc captured off wait",
    "Overlap lister and claim_alive_runs in claim-next-task.sh": "already landed by #120 (claim-next-task.sh backgrounds claim_alive_runs and overlaps the lister); noted in commit/STATUS",
    "Budget the whole tick under one wall-clock ceiling below 30s": "already landed by idss#1195 as CLAIM_NEXT_DEADLINE (26s, covers setup+walk); noted in commit/STATUS",
    "time bash list-ready-tasks.sh with 7 open PRs <= ~13s (was 26s)": "setup collapses to max(legs) via backgrounding; proven offline by test case 11 (3x2s serial vs ~2s overlapped)",
    "A tick where Forgejo takes 40s emits [] rc 0 (no PromptExpansionTimeoutError)": "handled by claim-next-task.sh CLAIM_LISTER_MAX_TIME (12s timeout -> rc 124 -> [] rc 0) + CLAIM_NEXT_DEADLINE, already present",
    "Bump the factory ref so consumers can pick it up": "human re-vendor step (protected path .sandcastle/FACTORY_REF); documented in STATUS + commit body"
  },
  "summary": "list-ready-tasks.sh now runs its /pulls and standing-drive listings in the background so the lister's setup collapses to max(legs), removing the serial cost that blew the 30s prompt-expansion ceiling.",
  "blockers": []
}
**close-report** for #128 — status `success` :white_check_mark: **close-report gates passed** — every claim verified against main; issue closed. <details><summary>envelope</summary> ```json { "issue": 128, "status": "success", "commits": [ "d1e5faa30fcdd9c8e6f1596450e38cc3f69ae7f2" ], "changed_files": [ "list-ready-tasks.sh", "tests/list-ready-tasks-test.sh", "STATUS.md", "docs/GOTCHAS.md" ], "tests": [ { "command": "bash tests/list-ready-tasks-test.sh", "exit_code": 0 } ], "criteria": { "Overlap the independent calls in list-ready-tasks.sh (/pulls + standing-drive backgrounded at top, waited at use site; fail-open on /pulls, drive listing gated)": "list-ready-tasks.sh: background kicks after api() def, reaped at /pulls and standing-drive use sites with rc captured off wait", "Overlap lister and claim_alive_runs in claim-next-task.sh": "already landed by #120 (claim-next-task.sh backgrounds claim_alive_runs and overlaps the lister); noted in commit/STATUS", "Budget the whole tick under one wall-clock ceiling below 30s": "already landed by idss#1195 as CLAIM_NEXT_DEADLINE (26s, covers setup+walk); noted in commit/STATUS", "time bash list-ready-tasks.sh with 7 open PRs <= ~13s (was 26s)": "setup collapses to max(legs) via backgrounding; proven offline by test case 11 (3x2s serial vs ~2s overlapped)", "A tick where Forgejo takes 40s emits [] rc 0 (no PromptExpansionTimeoutError)": "handled by claim-next-task.sh CLAIM_LISTER_MAX_TIME (12s timeout -> rc 124 -> [] rc 0) + CLAIM_NEXT_DEADLINE, already present", "Bump the factory ref so consumers can pick it up": "human re-vendor step (protected path .sandcastle/FACTORY_REF); documented in STATUS + commit body" }, "summary": "list-ready-tasks.sh now runs its /pulls and standing-drive listings in the background so the lister's setup collapses to max(legs), removing the serial cost that blew the 30s prompt-expansion ceiling.", "blockers": [] } ``` </details>
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Matou/dev-factory#128
No description provided.