From fde4dd6d9ef4447b42820447aaaaf97d09263773 Mon Sep 17 00:00:00 2001 From: Drewry Pope Date: Mon, 2 Nov 2026 11:33:53 -0600 Subject: [PATCH] opencode-claimant: launch only into recorded handoffs (#3026) First live launch batch (2026-11-02) bound 4/4 sessions at launch, but 3 of the 4 tasks were simultaneously being worked/parked/failed by their claiming lanes: assignment alone is not a handoff. Lanes follow the yield protocol only sometimes (pre-1b instructions still running; mid-work races during the claimant long fires). - poll.py is_candidate now also requires progress.stage == handed_off, the claiming lane recorded yield (instruction 1b). New test; 21/21 pass. - prompt.md: step 4a re-verify names the handed_off condition; step 4c checkpoint runs as the candidate worker_id (checkpoint enforces claim ownership; as opencode-claimant it failed on every launch in the first batch: checkpoint_launched_ok false). --- pm-stack/opencode-claimant/poll.py | 10 ++++++++++ pm-stack/opencode-claimant/prompt.md | 16 +++++++++++----- pm-stack/opencode-claimant/test_poll.py | 9 ++++++++- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/pm-stack/opencode-claimant/poll.py b/pm-stack/opencode-claimant/poll.py index 59c640c621..be0ea23ab2 100644 --- a/pm-stack/opencode-claimant/poll.py +++ b/pm-stack/opencode-claimant/poll.py @@ -68,6 +68,16 @@ def is_candidate(row): prog = row.get("progress") or {} if prog.get("lane") != "opencode" or prog.get("session_id"): return False + # The claiming lane must have RECORDED its yield (instruction + # section 1b: checkpoint stage "handed_off"). Assignment alone is + # not a handoff: lanes on pre-1b instructions assign and then work + # the task themselves, and a launch into a task whose lane is + # mid-work double-executes it (first live batch, 2026-11-02: + # tasks 5565/5867/6397 were launched while their claiming lanes + # worked/parked/failed them in parallel). The recorded yield is + # the only launch-safe signal. + if prog.get("stage") != "handed_off": + return False lane_id = row.get("lane_id") if lane_id and UUID_LANE.match(lane_id): return False diff --git a/pm-stack/opencode-claimant/prompt.md b/pm-stack/opencode-claimant/prompt.md index 98f8c073b3..88d79e7f0f 100644 --- a/pm-stack/opencode-claimant/prompt.md +++ b/pm-stack/opencode-claimant/prompt.md @@ -70,8 +70,11 @@ Never claim, bind, launch, or mutate a task in shadow mode. 4. For each candidate, highest queue priority first, while cap room remains: a. Re-verify the task is still claimed, still lane `opencode`, - still unbound (re-run poll.py for that task id). If it changed, - skip it -- someone else owns the launch now. + still unbound, and still at stage `handed_off` (re-run poll.py + for that task id -- its candidate filter encodes all four). If + it changed, skip it -- someone else owns the launch now. A task + that is assigned `opencode` but NOT handed off belongs to its + claiming lane, which is working it: never launch into it. b. Create the worker session on the standing OpenCode server (`POST /api/session`, directory = the repo's laptop primary, title naming the queue task and issue, model = the route above). @@ -87,9 +90,12 @@ Never claim, bind, launch, or mutate a task in shadow mode. a different existing binding -- a bind error means someone else owns the launch; do not prompt your session, note it in the fire log, and move on. Then run the helper - `checkpoint --worker opencode-claimant --stage launched` - with the session id in the progress JSON. A launch without this - binding is the Oct 28 duplicate-PR defect -- never leave one. + `checkpoint --worker --stage launched` + with the session id in the progress JSON -- the checkpoint verb + enforces claim ownership, so it runs as the candidate's + `worker_id` (the claiming repo worker), not as yourself. A + launch without this binding is the Oct 28 duplicate-PR defect + -- never leave one. d. Send the worker prompt to the bound session: the queue runbook for its queue with the task id, issue, and packet inlined, instructing it to work THAT task (it is already claimed and diff --git a/pm-stack/opencode-claimant/test_poll.py b/pm-stack/opencode-claimant/test_poll.py index ea1ec34716..800e213bb6 100644 --- a/pm-stack/opencode-claimant/test_poll.py +++ b/pm-stack/opencode-claimant/test_poll.py @@ -121,7 +121,8 @@ def test_known_counts_give_room(self): class TestIsCandidate(unittest.TestCase): def row(self, **over): - r = {"progress": {"lane": "opencode"}, "lane_id": "code-a"} + r = {"progress": {"lane": "opencode", "stage": "handed_off"}, + "lane_id": "code-a"} r.update(over) return r @@ -143,6 +144,12 @@ def test_bound_session_is_not_candidate(self): self.assertFalse(poll.is_candidate( self.row(progress={"lane": "opencode", "session_id": "ses_1"}))) + def test_assigned_but_not_handed_off_is_not_candidate(self): + self.assertFalse(poll.is_candidate( + self.row(progress={"lane": "opencode", "stage": "verified"}))) + self.assertFalse(poll.is_candidate( + self.row(progress={"lane": "opencode"}))) + def test_unassigned_task_is_not_candidate(self): self.assertFalse(poll.is_candidate(self.row(progress={})))