Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions doc/fleet/queue-turso-cutover.md
Original file line number Diff line number Diff line change
Expand Up @@ -413,3 +413,34 @@ at their attempt cap. The broker now owns waiting:
was the one place bookkeeping cycles consumed attempts (task
10501 reached 24/24 on handoff cycles alone). Direct claims
and bound sessions mid-work still return to `queued`.

## Amendment — the sink gets its own status (#8234, 2026-11-10)

The section above describes the #8184 landing as built; two of
its mechanisms were superseded the same day, first by #8187
(lanes DO collect sink rows through the default pick and flip
them direct — the `NOT (PARKED_HANDOFF_SQL)` exclusion is gone)
and then by #8234, Drew's ruling "sink gets its own status, drop
the fake timer":

- The handoff sink is status **`handed_off`**, not `parked`.
`parked` now means only a genuine broker-owned wait
(`wait_kind` + `ready_condition` + floored `not_before`).
- The park verb classifies its own landing: a park whose merged
progress is a recorded opencode handoff with no caller-declared
genuine wait lands in `handed_off` with every wait field NULL.
A caller-attached real condition always wins — that park is a
genuine wait even on a handoff-shaped row.
- `expire_leases` returns an expired sink-shaped claim to
`handed_off` with `not_before = NULL` and NO ready_condition —
the +1200s fake timer the sink pick never read is deleted.
- Sink membership is the status, on both sides of the wire:
neither the broker's pick SQL nor the claimant's poll reads a
progress stage to decide it (the broker and poll once read
different stage sources and disagreed — #8192, folded in).
- The wake verb refuses `handed_off` rows (not a wait; already
claimable), and `fleet queue health` reports `handed_off` as
its own bucket. Existing sink-shaped `parked` rows were moved
by one auditable migration (event kind
`handoff_status_migration`); rows carrying a genuine wait
stayed `parked`.
17 changes: 9 additions & 8 deletions pkgs/fleet/crates/fleet-queue/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1371,18 +1371,19 @@ fn cmd_claim(rest: &[String]) -> i32 {
Ok(None) => {}
Err(e) => die(2, &e),
}
// --handoff: the no-id collection of the next parked recorded
// opencode handoff (#8097 Rule 1) — the claimant's default
// parked-handoff path. The BROKER picks the row; the caller
// names no task id. (--task remains the special-case claim.)
// --handoff: the no-id collection of the next recorded
// opencode handoff from the sink (status 'handed_off', #8234;
// #8097 Rule 1) — the claimant's default handoff path. The
// BROKER picks the row; the caller names no task id. (--task
// remains the special-case claim.)
if args.has("handoff") {
body["pick"] = json!("parked_handoff");
body["pick"] = json!("handed_off");
}
// --task <id>: by-id claim — take exactly that row when the
// broker's by-id predicate allows it (a queued row under the
// ordinary predicate, or a parked recorded opencode handoff).
// The opencode claimant uses this to collect handed-off tasks
// out of the parked sink; a plain claim never names a task.
// ordinary predicate, or a sink row). The opencode claimant
// uses this to collect handed-off tasks out of the sink; a
// plain claim never names a task.
if let Some(task) = args.get_i64("task") {
body["task_id"] = json!(task);
}
Expand Down
479 changes: 338 additions & 141 deletions pkgs/fleet/crates/fleet-queue/src/turso_queue.rs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pm-stack/opencode-claimant/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ of waiting for the next claimant fire.
# Read-only: is this task a launch candidate, and what would happen?
python3 pm-stack/opencode-claimant/launch_one.py --preflight repo-health-code-pilot:12345

# Live only (mode file must read `live`): collect a parked handoff's
# Live only (mode file must read `live`): collect a sink row's
# claim by id if needed, create + verify + bind a session, checkpoint
# launched, send the prompt, post the agent-note. Prints the bound
# session_id; any failure exits non-zero and deletes a created
Expand Down
78 changes: 38 additions & 40 deletions pm-stack/opencode-claimant/claimant.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,29 +481,26 @@ def _send_prompt(session_id: str, prompt: str) -> bool:
CLAIMANT_WORKER = "opencode-claimant"


def _collect_parked_handoffs(queue: str, want: int) -> Dict[int, Dict]:
"""Collect up to `want` parked recorded handoffs from `queue`
WITHOUT naming a task id (#8097 Rule 1): each
def _collect_handed_offs(queue: str, want: int) -> Dict[int, Dict]:
"""Collect up to `want` recorded handoffs from `queue`'s
handoff sink WITHOUT naming a task id (#8097 Rule 1): each
`repo-queue claim --handoff` lets the BROKER pick the next
parked handoff (its ordinary pick order), claimed as the
claimant, so the launch flow below has a live claim to bind
against. Returns {task_id: claimed row}.

The handing-off lane parks the task as its handoff sink, so
without collection the task is never in the claimed state the
launch flow binds against — it waited out the park timer, was
re-claimed by the next shift wave, handed off, and parked again
(#7907/#6533). Collection used to name the task
(`claim --task <id>`); that by-id claim is now the special-case
verb (one-off revivals), and this default path does not depend
on it — the broker's handoff pick only ever returns a parked
recorded opencode handoff (unbound yield progress), never a
live claim or a genuine wait park.
sink row (its ordinary pick order), claimed as the claimant,
so the launch flow below has a live claim to bind against.
Returns {task_id: claimed row}.

A handed-off task rests in the sink (status 'handed_off',
#8234), so without collection it is never in the claimed state
the launch flow binds against. Collection used to name the
task (`claim --task <id>`); that by-id claim is now the
special-case verb (one-off revivals), and this default path
does not depend on it — the broker's handoff pick only ever
returns a sink row (status 'handed_off', unbound opencode
yield), never a live claim or a genuine wait park.

The claim declares the claimant's family, --platform
openchamber (#8097 Rule 2): a parked handoff whose item
carries the `muse` selector is not the opencode claimant's
to collect.
openchamber (#8097 Rule 2): a sink row whose item carries the
`muse` selector is not the opencode claimant's to collect.
"""
collected: Dict[int, Dict] = {}
for _ in range(max(want, 0)):
Expand Down Expand Up @@ -632,20 +629,20 @@ def launch_step(mode: str, cap_room: int) -> List[Dict]:
]

# Parked handoff sink (#8097 Rule 1): collect this fire's
# parked candidates' claims up front, grouped by queue,
# sink candidates' claims up front, grouped by queue,
# without naming any task id — one broker-picked handoff
# claim per discovered parked candidate. A parked
# candidate whose id is not in `collected` when its turn
# comes was not collected (its pick lost a race or the
# broker had nothing claimable) and is skipped below —
# the binding is never improvised.
parked_by_queue: Dict[str, int] = {}
# claim per discovered sink candidate. A sink candidate
# whose id is not in `collected` when its turn comes was
# not collected (its pick lost a race or the broker had
# nothing claimable) and is skipped below — the binding is
# never improvised.
handed_off_by_queue: Dict[str, int] = {}
for c in unbound_opencode:
if c.get("status") == "parked":
parked_by_queue[c["queue"]] = parked_by_queue.get(c["queue"], 0) + 1
if c.get("status") == "handed_off":
handed_off_by_queue[c["queue"]] = handed_off_by_queue.get(c["queue"], 0) + 1
collected: Dict[int, Dict] = {}
for queue_name, want in parked_by_queue.items():
collected.update(_collect_parked_handoffs(queue_name, want))
for queue_name, want in handed_off_by_queue.items():
collected.update(_collect_handed_offs(queue_name, want))

for candidate in unbound_opencode:
if cap_room <= 0:
Expand All @@ -660,18 +657,19 @@ def launch_step(mode: str, cap_room: int) -> List[Dict]:
issue = candidate.get("issue", "")
packet = candidate.get("packet", {})

# Parked handoff sink: the candidate was handed off and
# then parked by its claiming lane, so no live claim
# existed to bind against until the collection above
# claimed it (as the claimant; the launched session
# then works under the claimant's worker identity). A
# candidate the collection did not claim is skipped —
# the binding is never improvised.
if candidate.get("status") == "parked":
# Handoff sink: the candidate was handed off by its
# claiming lane and rests in the sink (status
# 'handed_off'), so no live claim existed to bind
# against until the collection above claimed it (as
# the claimant; the launched session then works under
# the claimant's worker identity). A candidate the
# collection did not claim is skipped — the binding
# is never improvised.
if candidate.get("status") == "handed_off":
if task_id not in collected:
skips.append({
"task_id": task_id,
"reason": "parked_claim_failed"
"reason": "sink_claim_failed"
})
continue
candidate["status"] = "claimed"
Expand Down
71 changes: 38 additions & 33 deletions pm-stack/opencode-claimant/launch_one.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
OpenChamber cron every few minutes: it discovers every candidate and
launches under the fleet cap. It has no per-task trigger, so a handoff
that should launch *now* ("handoff = immediate launch", #8187) waits
for the next fire — and a parked handoff sink can loop unlaunched.
for the next fire — and a handoff sink can loop unlaunched.
This tool performs exactly the claimant's launch sequence (prompt.md
step 4) for ONE named task:

python3 -I launch_one.py --preflight <queue>:<task_id> [...]
python3 -I launch_one.py --launch <queue>:<task_id>

--preflight is read-only and always allowed: it reports whether the
task is a launch candidate (claimed, or a parked recorded handoff —
progress.lane == "opencode", no session_id, stage handed_off /
launch_failed), what blocks it if anything (attempts exhausted, held
task is a launch candidate (claimed with a recorded yield, or a
sink row — status "handed_off" (#8234), progress.lane ==
"opencode", no session_id), what blocks it if anything (attempts exhausted, held
labels, cap saturated, mode not live), and the exact steps a launch
would take. It mutates nothing: no claim, no session, no journal.

Expand All @@ -24,21 +24,22 @@
reads "live":

1. re-verify the candidate through poll.py's classifiers
(is_candidate for claimed rows, is_handoff_parked for parked
(is_candidate for claimed rows, is_handoff_waiting for sink
rows — the query logic lives in poll.py, not here);
2. fail closed on exhausted attempts and on held labels
(held / user/owned / do-not-merge / do-not-auto-edit, read live
through `gh`; an unreadable label set is a refusal, not a pass);
3. check the concurrency cap through claimant.py's cap_step
(unknown cap room launches nothing);
4. a PARKED handoff has no live claim to bind against, so collect
its claim first with the broker's by-id special-case verb
4. a sink row (status "handed_off") has no live claim to bind
against, so collect its claim first with the broker's by-id
special-case verb
(`repo-queue claim --task <id> --worker opencode-claimant
--platform openchamber`; prompt.md reserves the by-id claim for
one-off revivals, which is exactly what a named per-task launch
is — the claimant's default no-id `--handoff` collection cannot
promise the broker picks THIS task). The session then works
under --worker opencode-claimant, as in claimant.py's parked
under --worker opencode-claimant, as in claimant.py's sink
path;
5. create the worker session on the OpenCode server through
claimant.py's verified transport, journal its id to
Expand Down Expand Up @@ -70,7 +71,7 @@
This file supersedes the state-dir helper of the same name
(~/.local/state/opencode-claimant/launch_one.py), which broke when
poll.fetch_claimed was replaced by fetch_claimed_rows /
fetch_parked_rows and its REPO_QUEUE path went stale.
fetch_handed_off_rows and its REPO_QUEUE path went stale.
"""

import importlib.util
Expand Down Expand Up @@ -145,9 +146,12 @@ def queue(*args, timeout=120):
# --- Candidate discovery (delegated to poll.py) ---------------------

def explain_not_candidate(row):
"""Why poll.is_candidate / is_handoff_parked said no, in words a
"""Why poll.is_candidate / is_handoff_waiting said no, in words a
coordinator can act on. Mirrors the classifiers' checks; the
classifiers themselves stay the verdict."""
classifiers themselves stay the verdict. (The stage line speaks
to the CLAIMED-row classifier — sink rows are not stage-gated
since #8234/#8192 — but it is harmless context for a sink row
too: the classifiers, not this text, decide.)"""
prog = row.get("progress") or {}
reasons = []
if prog.get("lane") != "opencode":
Expand All @@ -161,26 +165,26 @@ def explain_not_candidate(row):
lane_id = row.get("lane_id")
if lane_id and poll.UUID_LANE.match(str(lane_id)):
reasons.append(f"claiming lane {lane_id} is an OpenChamber scheduled lane")
if row.get("status") not in (None, "claimed", "parked"):
if row.get("status") not in (None, "claimed", "handed_off"):
reasons.append(f"status is {row.get('status')!r}")
return reasons or ["not a candidate"]


def find_row(queue_name, task_id):
"""(row, status, candidate, reasons) for one task, read through
poll.py's broker fetch helpers: claimed rows first, then the
parked handoff sink. (None, None, False, [...]) when the task is
in neither set for this queue."""
handoff sink (status 'handed_off'). (None, None, False, [...])
when the task is in neither set for this queue."""
for row in poll.fetch_claimed_rows(queue_name):
if row.get("id") == task_id:
if poll.is_candidate(row):
return row, "claimed", True, []
return row, "claimed", False, explain_not_candidate(row)
for row in poll.fetch_parked_rows(queue_name):
for row in poll.fetch_handed_off_rows(queue_name):
if row.get("id") == task_id:
if poll.is_handoff_parked(row):
return row, "parked", True, []
return row, "parked", False, explain_not_candidate(row)
if poll.is_handoff_waiting(row):
return row, "handed_off", True, []
return row, "handed_off", False, explain_not_candidate(row)
return None, None, False, [f"task {task_id} not found in queue {queue_name}"]


Expand Down Expand Up @@ -359,12 +363,12 @@ def post_agent_note(row, ref, repo, sid):

# --- The launch sequence ----------------------------------------------

def collect_parked_claim(queue_name, task_id):
"""Claim THIS parked handoff by id, as the claimant. Returns
(claimed_row, None) or (None, error). The claim output is the
claimed row itself, a {"task": row} wrapper, or {"task": null}
when the broker would not hand it over; only a row whose id is
the requested task counts."""
def collect_sink_claim(queue_name, task_id):
"""Claim THIS sink row (status 'handed_off') by id, as the
claimant. Returns (claimed_row, None) or (None, error). The
claim output is the claimed row itself, a {"task": row}
wrapper, or {"task": null} when the broker would not hand it
over; only a row whose id is the requested task counts."""
try:
rc, out, err = queue("claim", "--queue", queue_name,
"--worker", CLAIMANT_WORKER,
Expand Down Expand Up @@ -417,16 +421,17 @@ def launch(queue_name, task_id):
"reason": "cap_saturated", "cap_room": cap_room}

worker_id = row.get("worker_id")
if status == "parked":
if status == "handed_off":
# No live claim exists to bind/checkpoint against: collect
# this task's claim first. The successful by-id claim is the
# broker's own verification that the row is a parked recorded
# opencode handoff; the session then works as the claimant,
# exactly as in claimant.py's parked path.
claimed, claim_err = collect_parked_claim(queue_name, task_id)
# broker's own verification that the row is a sink row
# (status 'handed_off', recorded opencode handoff); the
# session then works as the claimant, exactly as in
# claimant.py's sink path.
claimed, claim_err = collect_sink_claim(queue_name, task_id)
if claimed is None:
return {"task": task_id, "queue": queue_name, "ok": False,
"reason": "parked_claim_failed", "detail": claim_err}
"reason": "sink_claim_failed", "detail": claim_err}
worker_id = CLAIMANT_WORKER
else:
# Re-verify immediately before creating anything (claimant
Expand Down Expand Up @@ -539,9 +544,9 @@ def would_steps(queue_name, row, status, worker_id):
directory = REPOS[queue_name][1]
prov, mdl = route_for(row)
steps = []
if status == "parked":
if status == "handed_off":
steps.append(
f"collect the parked handoff's claim by id: repo-queue claim "
f"collect the sink row's claim by id: repo-queue claim "
f"--queue {queue_name} --worker {CLAIMANT_WORKER} "
f"--platform openchamber --task {row.get('id')}")
steps += [
Expand Down Expand Up @@ -583,7 +588,7 @@ def preflight(queue_name, task_id):
if mode != "live":
blockers.append(f"mode_not_live: mode file reads {mode!r}; --launch would refuse")
worker_id = row.get("worker_id") or (
CLAIMANT_WORKER if status == "parked" else None)
CLAIMANT_WORKER if status == "handed_off" else None)
return {
"task": task_id, "queue": queue_name, "candidate": candidate,
"ok": candidate and not blockers,
Expand Down
Loading
Loading