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
14 changes: 11 additions & 3 deletions pm-stack/opencode-claimant/dispatch_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,17 @@ def claim_batch(queue_name, worker, lane, count, family,
if data is None:
return [], f"batch claim unparseable (rc={rc}): {err.strip()[:200]}"
tasks = data.get("tasks")
if not isinstance(tasks, list):
return [], f"batch claim returned no tasks array: {str(data)[:200]}"
return tasks, None
if isinstance(tasks, list):
return tasks, None
# count == 1 IS the single claim (#8217: count absent or 1 is
# the ordinary claim), and the client answers a single claim
# with the bare row — or {"task": null} when nothing is
# claimable. Normalize both to the batch shape.
if isinstance(data.get("id"), int):
return [data], None
if data.get("task") is None and "task" in data:
return [], None
return [], f"batch claim returned no tasks array: {str(data)[:200]}"


def release_task(task_id, worker, reason):
Expand Down
27 changes: 27 additions & 0 deletions pm-stack/opencode-claimant/test_dispatch_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,17 @@ def verbs(self, verb: str) -> list[tuple]:
return [c for c in self.calls if c[0] == verb]


class BareRowQueue(FakeQueue):
"""The client's count==1 shape: a claim answers with the bare
row (the single claim), not the batch {"tasks": [...]} body."""

def __call__(self, *args, timeout=120):
self.calls.append(args)
if args[0] == "claim":
return 0, json.dumps(self.claim_rows[0]), ""
return 0, "{}", ""


class DispatchBatchTests(unittest.TestCase):
def setUp(self):
self.worktree_calls: list[tuple] = []
Expand Down Expand Up @@ -275,6 +286,22 @@ def test_claude_item_without_bind_is_prepared_unbound(self):
self.assertIn("bind_command", item)
self.assertEqual(fake_q.verbs("bind"), [])

def test_single_item_batch_accepts_bare_row_response(self):
# Regression (live acceptance, #8217): --count 1 is the
# single claim, whose response is the bare row; dispatch
# must normalize it instead of failing the claim phase.
fake_q = BareRowQueue([row(101, 555)])
db.queue = fake_q
out = io.StringIO()
with contextlib.redirect_stdout(out):
rc = db.main(["dispatch_batch.py",
*self.base_argv("--to", "opencode",
"--session-id", "ses_lane",
"--count", "1", "--dry-run")])
self.assertEqual(rc, 0)
summary = json.loads(out.getvalue().strip().splitlines()[-1])
self.assertEqual(summary["tasks"], [101])

# -- validation ---------------------------------------------------

def test_count_over_cap_refused_before_claiming(self):
Expand Down
Loading