run-swarm: a queue-draining run holds the heavy slot across tasks — the drive yield (#663/#664) only fires at run START, so a ready rehearsal drive waits for the whole queue #111

Closed
opened 2026-08-28 16:56:45 +00:00 by ben · 3 comments
Owner

Observed (elitebook-03, 2026-08-28 16:16Z→)

The idss phase-5 drive (#854) reserved host capacity (/tmp/matou-drive-wanted, ADR 0184) at 16:18Z. A Matou/coa swarm run that had started at 16:16Z finished coa #7, then — inside the SAME run — started coa #8 (new container 16:39Z) and kept /tmp/matou-host-slot-2.lock. coa has 11 ready-for-agent tickets; the run would hold the slot for hours. The drive executor skipped 20+ consecutive ticks ("host capacity busy … reservation held so NEW heavy work yields").

Cause

run-swarm.sh consults the reservation once, before acquiring the slot (schedule_drive_yield, schedule-lib.sh:60). Sandcastle's run() then drains every ready task in-process; nothing re-checks host_capacity_drive_wanted between tasks, so a reservation raised after the run began is honoured only by the next run.

Wanted

Between tasks (or via a Sandcastle per-task cap when a reservation exists), re-check host_capacity_drive_wanted; if set, finish the current task, release the slot and exit reason=yielded-to-drive so the drive fires and the swarm resumes on its next trigger. Should self-test offline like the existing yield (SWARM_DRIVE_DEFER_COUNT).

Filed from the idss watch (ADR 0174); the immediate incident was handled by hand.

## Observed (elitebook-03, 2026-08-28 16:16Z→) The idss phase-5 drive (#854) reserved host capacity (`/tmp/matou-drive-wanted`, ADR 0184) at 16:18Z. A `Matou/coa` swarm run that had started at 16:16Z finished coa #7, then — inside the SAME run — started coa #8 (new container 16:39Z) and kept `/tmp/matou-host-slot-2.lock`. coa has 11 `ready-for-agent` tickets; the run would hold the slot for hours. The drive executor skipped 20+ consecutive ticks ("host capacity busy … reservation held so NEW heavy work yields"). ## Cause `run-swarm.sh` consults the reservation once, before acquiring the slot (`schedule_drive_yield`, schedule-lib.sh:60). Sandcastle's `run()` then drains every ready task in-process; nothing re-checks `host_capacity_drive_wanted` between tasks, so a reservation raised after the run began is honoured only by the *next* run. ## Wanted Between tasks (or via a Sandcastle per-task cap when a reservation exists), re-check `host_capacity_drive_wanted`; if set, finish the current task, release the slot and exit `reason=yielded-to-drive` so the drive fires and the swarm resumes on its next trigger. Should self-test offline like the existing yield (`SWARM_DRIVE_DEFER_COUNT`). Filed from the idss watch (ADR 0174); the immediate incident was handled by hand.

This was generated by AI during triage.

Ruled by agent under ADR 0174 — veto anytime.

Ruling: ready-for-agent (bug).

Why it is a two-way door: the fix lives entirely in unprotected root harness files — run-swarm.sh, schedule-lib.sh, and/or main.mts — none of which are on the protected list (prompt skeletons, the vendored .sandcastle/ self-copy, .forgejo/). It reaches consumers only at the next pin bump, and it is reverted by a single follow-up commit or a label change. No one-way-door residue: no credentials, no security-posture widening, no member-facing trust accept, no data destruction, no spend.

What proves it: the reporter's own acceptance — the between-task re-check must self-test offline like the existing yield (SWARM_DRIVE_DEFER_COUNT / schedule_drive_yield). There is a directly-adjacent, already-offline-tested pattern to mirror: host_capacity_drive_wanted + host_capacity_consumer_defer_bump/_reset in host-capacity-lib.sh, exercised through schedule_drive_yield. The regression and the fix are both observable through that shimmed test surface with no docker/network.

Codebase confirmation of the cause: confirmed. run-swarm.sh calls schedule_drive_yield exactly once, before it acquires the heavy slot (~run-swarm.sh L115). It then hands off to execute_sandcastle_run (execute-lib.sh), which runs pnpm run sandcastle → main.mts, whose run() (from @ai-hero/sandcastle) drains up to maxIterations: 3 tasks in a single in-process session. Nothing between those iterations re-consults host_capacity_drive_wanted, so a reservation raised after the slot is taken is honoured only by the next run — exactly as reported. main.mts already has a per-run abort mechanism (the TUI cancel marker, #612/ADR 0186); a between-iteration reservation check is the same shape.


Agent Brief

Category: bug
Summary: A queue-draining swarm run keeps the shared heavy slot across every task, so a drive reservation raised mid-run is ignored until the whole queue drains.

Current behavior:
A swarm run consults the drive reservation once, before it takes a heavy slot. Once it holds the slot, the in-process orchestration loop works ready tasks back-to-back (up to its iteration cap) without ever re-checking the reservation. A rehearsal/standing drive that reserves host capacity after the run has started is starved until the run finishes its whole batch — observed holding /tmp/matou-host-slot-2.lock for hours while a drive executor skipped 20+ consecutive ticks.

Desired behavior:
Between tasks, a run that holds a heavy slot re-checks whether a drive has since reserved host capacity. If it has, the run finishes the current task cleanly, releases the slot, and exits with a named yield reason (e.g. yielded-to-drive) so the reserved drive can fire and the swarm resumes on its next trigger. A run started while no reservation exists and none appears mid-run behaves exactly as today.

Key interfaces / mechanisms:

  • The reservation predicate is host_capacity_drive_wanted (host-capacity-lib.sh); the consecutive-yield accounting pattern to mirror is host_capacity_consumer_defer_bump / host_capacity_consumer_defer_reset, wired through schedule_drive_yield (schedule-lib.sh) and driven by SWARM_DRIVE_DEFER_COUNT.
  • The between-task decision must be offline-testable in the same style as schedule_drive_yield — keep the re-check logic in shell (a schedule-lib.sh helper the orchestrator loop calls, or a per-task cap enforced by run-swarm.sh), not buried in untestable TypeScript. The orchestrator loop lives in main.mts (run({ maxIterations }) from @ai-hero/sandcastle); it already honours a per-run abort marker (the TUI cancel path, ADR 0186) — the reservation yield can reuse that seam or a per-iteration hook.
  • The run's exit/yield reason must be a distinct, named verdict (not the generic sandcastle-run-failed), consistent with SWARM_EXIT_REASON conventions in execute-lib.sh.

Acceptance criteria:

  • With a drive reservation raised after a run has taken a heavy slot, the run completes its current task, releases the slot, and exits with a named yielded-to-drive-style reason rather than draining the remaining queue.
  • With no reservation (or one that never appears), run behaviour and the number of tasks worked are unchanged from today.
  • The current task in flight is never abandoned mid-work to yield.
  • The new behaviour has an offline self-test (shimmed, no docker/network) in the same style as the existing SWARM_DRIVE_DEFER_COUNT / schedule_drive_yield coverage, added in the same commit as the change.
  • STATUS.md updated in the same commit (this changes scheduling/yield semantics).

Out of scope:

  • The triage yield-starvation signal (#110) — related root cause (both contend on the shared host slots) but a separate fix on a protected path.
  • Changing the number of pooled heavy slots or the reservation TTL.
  • Any change to .forgejo/ workflow files or the run-start yield in schedule_drive_yield (that gate already works; this adds a between-task gate).

Related: #110 (the triage-side starvation this slot-holding contributes to), #663/#664 (drive-defer counter), ADR 0184 (host-capacity reservation), ADR 0186 (per-run cancel marker).

> *This was generated by AI during triage.* **Ruled by agent under ADR 0174 — veto anytime.** **Ruling:** `ready-for-agent` (`bug`). **Why it is a two-way door:** the fix lives entirely in unprotected root harness files — `run-swarm.sh`, `schedule-lib.sh`, and/or `main.mts` — none of which are on the protected list (prompt skeletons, the vendored `.sandcastle/` self-copy, `.forgejo/`). It reaches consumers only at the next pin bump, and it is reverted by a single follow-up commit or a label change. No one-way-door residue: no credentials, no security-posture widening, no member-facing trust accept, no data destruction, no spend. **What proves it:** the reporter's own acceptance — the between-task re-check must self-test offline like the existing yield (`SWARM_DRIVE_DEFER_COUNT` / `schedule_drive_yield`). There is a directly-adjacent, already-offline-tested pattern to mirror: `host_capacity_drive_wanted` + `host_capacity_consumer_defer_bump`/`_reset` in `host-capacity-lib.sh`, exercised through `schedule_drive_yield`. The regression and the fix are both observable through that shimmed test surface with no docker/network. **Codebase confirmation of the cause:** confirmed. `run-swarm.sh` calls `schedule_drive_yield` exactly once, before it acquires the heavy slot (~`run-swarm.sh` L115). It then hands off to `execute_sandcastle_run` (`execute-lib.sh`), which runs `pnpm run sandcastle` → `main.mts`, whose `run()` (from `@ai-hero/sandcastle`) drains up to `maxIterations: 3` tasks in a single in-process session. Nothing between those iterations re-consults `host_capacity_drive_wanted`, so a reservation raised after the slot is taken is honoured only by the *next* run — exactly as reported. `main.mts` already has a per-run abort mechanism (the TUI cancel marker, #612/ADR 0186); a between-iteration reservation check is the same shape. --- ## Agent Brief **Category:** bug **Summary:** A queue-draining swarm run keeps the shared heavy slot across every task, so a drive reservation raised mid-run is ignored until the whole queue drains. **Current behavior:** A swarm run consults the drive reservation once, before it takes a heavy slot. Once it holds the slot, the in-process orchestration loop works ready tasks back-to-back (up to its iteration cap) without ever re-checking the reservation. A rehearsal/standing drive that reserves host capacity *after* the run has started is starved until the run finishes its whole batch — observed holding `/tmp/matou-host-slot-2.lock` for hours while a drive executor skipped 20+ consecutive ticks. **Desired behavior:** Between tasks, a run that holds a heavy slot re-checks whether a drive has since reserved host capacity. If it has, the run finishes the *current* task cleanly, releases the slot, and exits with a named yield reason (e.g. `yielded-to-drive`) so the reserved drive can fire and the swarm resumes on its next trigger. A run started while no reservation exists and none appears mid-run behaves exactly as today. **Key interfaces / mechanisms:** - The reservation predicate is `host_capacity_drive_wanted` (`host-capacity-lib.sh`); the consecutive-yield accounting pattern to mirror is `host_capacity_consumer_defer_bump` / `host_capacity_consumer_defer_reset`, wired through `schedule_drive_yield` (`schedule-lib.sh`) and driven by `SWARM_DRIVE_DEFER_COUNT`. - The between-task decision must be offline-testable in the same style as `schedule_drive_yield` — keep the re-check logic in shell (a `schedule-lib.sh` helper the orchestrator loop calls, or a per-task cap enforced by `run-swarm.sh`), not buried in untestable TypeScript. The orchestrator loop lives in `main.mts` (`run({ maxIterations })` from `@ai-hero/sandcastle`); it already honours a per-run abort marker (the TUI cancel path, ADR 0186) — the reservation yield can reuse that seam or a per-iteration hook. - The run's exit/yield reason must be a distinct, named verdict (not the generic `sandcastle-run-failed`), consistent with `SWARM_EXIT_REASON` conventions in `execute-lib.sh`. **Acceptance criteria:** - [ ] With a drive reservation raised after a run has taken a heavy slot, the run completes its current task, releases the slot, and exits with a named `yielded-to-drive`-style reason rather than draining the remaining queue. - [ ] With no reservation (or one that never appears), run behaviour and the number of tasks worked are unchanged from today. - [ ] The current task in flight is never abandoned mid-work to yield. - [ ] The new behaviour has an offline self-test (shimmed, no docker/network) in the same style as the existing `SWARM_DRIVE_DEFER_COUNT` / `schedule_drive_yield` coverage, added in the same commit as the change. - [ ] `STATUS.md` updated in the same commit (this changes scheduling/yield semantics). **Out of scope:** - The *triage* yield-starvation signal (#110) — related root cause (both contend on the shared host slots) but a separate fix on a protected path. - Changing the number of pooled heavy slots or the reservation TTL. - Any change to `.forgejo/` workflow files or the run-start yield in `schedule_drive_yield` (that gate already works; this adds a between-task gate). **Related:** #110 (the triage-side starvation this slot-holding contributes to), #663/#664 (drive-defer counter), ADR 0184 (host-capacity reservation), ADR 0186 (per-run cancel marker).
Author
Owner

Claimed by an interactive session (Ben + Claude) — swapped ready-for-agent → agent-working so the swarm skips it.

Claimed by an interactive session (Ben + Claude) — swapped ready-for-agent → agent-working so the swarm skips it.
Author
Owner

Landed in 79c92ed on main.

Why not a between-task check in run-swarm: sandcastle run() drains all iterations in one call; it has no between-iteration host hook, its abort signal kills the in-flight agent, and the prompt's claim-next-task.sh expansion runs INSIDE the sandbox where /tmp/matou-drive-wanted is invisible.

Design: main.mts polls the host reservation every 2s (same freshness/TTL rule as host_capacity_drive_wanted) and mirrors it into a run-scoped host dir mounted read-only at /run/host-signals in every sandbox. list-ready-tasks.sh answers [] before any API call when drive-wanted is there, so claim-next-task.sh claims nothing more and the prompt's Done re-check completes the loop after the CURRENT task. On exit main.mts prints SANDCASTLE_YIELDED_TO_DRIVE run=<id>; execute-lib sets EXECUTE_YIELDED_TO_DRIVE (rc 0 — the finished task still verifies and lands), run-swarm exits reason=yielded-to-drive, the slot is released at exit and the drive fires; report_self_rearm still re-dispatches, and that follow-up run yields at the existing startup gate (#664 defer counter).

Proof (offline): tests/list-ready-tasks-test.sh 16 cases (signal → [] with zero curl calls; absent → unchanged), tests/execute-lib-test.sh 14 groups (1b: marker → flag, rc 0, log cleaned), full suite green, node --check main.mts OK. GOTCHAS 38.

Still owed (live): a re-vendor + FACTORY_REF bump on the hosts, then one real observation of a run ending reason=yielded-to-drive in run-swarm-verdicts.log while a drive reservation stands.

Landed in `79c92ed` on main. **Why not a between-task check in run-swarm:** sandcastle `run()` drains all iterations in one call; it has no between-iteration host hook, its abort signal kills the in-flight agent, and the prompt's `claim-next-task.sh` expansion runs INSIDE the sandbox where `/tmp/matou-drive-wanted` is invisible. **Design:** `main.mts` polls the host reservation every 2s (same freshness/TTL rule as `host_capacity_drive_wanted`) and mirrors it into a run-scoped host dir mounted read-only at `/run/host-signals` in every sandbox. `list-ready-tasks.sh` answers `[]` before any API call when `drive-wanted` is there, so `claim-next-task.sh` claims nothing more and the prompt's Done re-check completes the loop after the CURRENT task. On exit main.mts prints `SANDCASTLE_YIELDED_TO_DRIVE run=<id>`; execute-lib sets `EXECUTE_YIELDED_TO_DRIVE` (rc 0 — the finished task still verifies and lands), run-swarm exits `reason=yielded-to-drive`, the slot is released at exit and the drive fires; `report_self_rearm` still re-dispatches, and that follow-up run yields at the existing startup gate (#664 defer counter). **Proof (offline):** `tests/list-ready-tasks-test.sh` 16 cases (signal → `[]` with zero curl calls; absent → unchanged), `tests/execute-lib-test.sh` 14 groups (1b: marker → flag, rc 0, log cleaned), full suite green, `node --check main.mts` OK. GOTCHAS 38. **Still owed (live):** a re-vendor + FACTORY_REF bump on the hosts, then one real observation of a run ending `reason=yielded-to-drive` in `run-swarm-verdicts.log` while a drive reservation stands.
ben 2026-08-28 18:46:49 +00:00
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#111
No description provided.