Skip to content

feat(opencode-claimant): hand back the next candidate on a saturated fire (#1187) - #12681

Closed
dezren39 wants to merge 1 commit into
mainfrom
xaltha/1187-hand-back
Closed

dezren39 wants to merge 1 commit into
mainfrom
xaltha/1187-hand-back

Conversation

@dezren39

@dezren39 dezren39 commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

Summary

#1187 criterion 2 (hand-back at capacity) had no code behind it: a saturated claimant fire logged one {"reason": "cap_saturated"} skip and exited, leaving the waiting candidate queued with nothing recorded but the fire log. This slice implements the hand-back in pm-stack/opencode-claimant/claimant.py:

Evidence

Before (test fails on origin/main): python3 -m unittest test.test_claimant.TestHandBack → 8 errors, AttributeError: module 'claimant' has no attribute 'hand_back_next_candidate'.

After (this branch, sandbox, pure Python — no Rust build involved):

  • python3 -I run_hermetic_tests.py → Ran 168 tests, OK (8 new TestHandBack cases; the opencode-claimant: slice-1 fire implementation diverges from packet spec (supervision selection, hard-rule labels, audit fields) #8038 cap-exit test updated to pin the hand-back skip).
  • CI equivalents: python3 -m unittest on test_poll.py (95 OK), test_claimant.py (44 OK), test/test_claimant.py (18 OK), grist discovery (27 OK), launch_one/send_to_opencode/dispatch_batch (27 OK).
  • Not verified live: no saturated fire has run against this code yet. Live proof is the next saturated claimant fire's fires.jsonl entry showing handed_back_executor_saturated plus the parked task and its issue note.

Merge Danger

  • Behavior change on live fires: the first saturated fire after deploy will claim+park one waiting candidate per fire (max one per 10-min fire) and post one issue note per hand-back. The park is a 1h capacity wait; the task returns to eligibility automatically, and urgent lanes can reclaim sooner via the capacity bypass.
  • If the park fails after a successful claim, the claimant holds the claim until the lease lapses (recorded as hand_back_park_failed); the task returns to the handoff sink, no attempt burned.
  • Mid-loop cap exhaustion inside launch_step is NOT handed back by this slice — only the fire-start saturated branch. That is the named next slice.

Refs #1187 (criterion 2 mechanism; the box stays unticked until a live saturated fire proves it).


Run Proof on this PR
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

Summary by CodeRabbit

  • New Features
    • When executor capacity is full, the system can now return one eligible unbound task to a capacity-wait state, with a one-hour retry delay.
    • If a candidate cannot be claimed, the system tries the next eligible candidate. It stops if parking a claimed task fails.
    • Shadow mode records which candidate would be returned without changing task state. Issue notes are posted when possible; a note-posting failure does not prevent the hand-back.

…fire (#1187)

A saturated claimant fire logged cap_saturated and exited with the
waiting candidate still queued and nothing recorded but the fire log.
It now hands back the next candidate within the round: claim --task as
the claimant (park requires a live claim), park with reason
executor-saturated as a capacity wait (1h floor, capacity bypass lets
an urgent lane reclaim sooner), and note it on the issue. One hand-back
per fire; shadow fires record shadow_would_hand_back and mutate nothing.

Tests: 8 new TestHandBack cases; the #8038 cap-exit test now pins the
hand-back skip. Hermetic suite 168/168; CI python suites green.
@dezren39
dezren39 requested a review from a team as a code owner November 22, 2026 21:04
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-22T21:08:39.470978Z 5c4d44c PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

When capacity is exhausted, the claimant now evaluates eligible unbound OpenCode candidates and can claim and park one as an executor-saturated capacity wait. Shadow mode records a would-hand-back result without mutation. The fire log records candidate outcomes, and launch and hand-back issue notes use a shared target resolver.

Changes: Capacity hand-back

Layer / File(s) Summary
Shared issue-note delivery
pm-stack/opencode-claimant/claimant.py
Launch and hand-back notes use a shared issue-target resolver and comment-posting helper. The hand-back note includes active-root count and capacity timing details.
Candidate selection and capacity parking
pm-stack/opencode-claimant/claimant.py, pm-stack/opencode-claimant/test/test_claimant.py, pm-stack/opencode-claimant/test_claimant.py
At zero capacity, the claimant filters candidates, tries claims in order, and parks at most one successful claim with a one-hour capacity wait. Shadow mode does not mutate candidates. Tests cover claim and park failures, exclusions, note-posting failure, and fire-log output.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant Fire as _fire
  participant HandBack as hand_back_next_candidate
  participant Queue as Queue CLI
  participant GitHub as gh
  Fire->>HandBack: candidates and recovered-task exclusions
  HandBack->>Queue: claim eligible candidate by ID
  Queue-->>HandBack: claim result
  HandBack->>Queue: park claimed task with capacity wait
  Queue-->>HandBack: park result
  HandBack->>GitHub: post issue note after successful park
Loading

Possibly related issues

Suggested reviewers: claude

Merge Risk: Minimal · up to 5c4d4

When capacity is exhausted, the claimant can now park one waiting candidate per fire as an executor-saturated capacity wait and post an issue note. No concrete defect was established in the reviewed change. The one remaining caveat is that live behavior on a saturated fire has not yet been observed, so check the first fires.jsonl hand-back entry after deploying.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the feature (hand back the next candidate on a saturated fire) and the component (opencode-claimant), which matches the main change: the new saturated-fire hand-back path in claimant.p…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the feature (hand back the next candidate on a saturated fire) and the component (opencode-claimant), which matches the main change: the new saturated-fire hand-back path in claimant.py, its helper, and the tests. It also includes the PR number (#1187), which is acceptable. The title is one sentence, specific, and does not use vague terms.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1faf5c50-73ac-4d52-8dac-d6fc9acadcdd
Commits

Reviewing files that changed from the base of the PR and between 703f8a7 and 5c4d44c.

Files selected for processing: 3

  • pm-stack/opencode-claimant/claimant.py
  • pm-stack/opencode-claimant/test/test_claimant.py
  • pm-stack/opencode-claimant/test_claimant.py

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5c4d44c983

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

claimed_id = (
claim_data.get("id") if isinstance(claim_data, dict) else None
)
if claim_result is None or claim_result.returncode != 0 or claimed_id != task_id:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Stop the pass after an indeterminate claim result

If a claim commits but the subprocess times out before returning its response, the exception is treated as an ordinary claim refusal and the loop proceeds to another candidate. A successful claim with malformed output has the same outcome. This can leave multiple tasks claimed without parking or launching any of them, making them unavailable until their leases expire. Unlike an explicit refusal, an indeterminate result should stop the pass or reconcile ownership before proceeding; the existing _collect_handed_offs also stops on exceptions.

Useful? React with 👍 / 👎.

stopped = True
continue
packet = candidate.get("packet", {})
note_posted = _post_hand_back_note(task_id, candidate, packet, cap_room)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Deduplicate capacity-park notes before posting

When a task is handed off again while the executor remains saturated, this path unconditionally posts another capacity-park comment for the same task. There is no prior-note check, and the new state=handed-back header is outside the lane guard's parked/picked-up deduplication states. Repeated saturation cycles can therefore produce repeated issue notifications without a meaningful progress transition. Check the existing notes using the documented lane-guard contract and use its parked-note header before posting.

AGENTS.md reference: AGENTS.md:L92-L94

Useful? React with 👍 / 👎.

Comment on lines +1184 to +1186
"--platform",
"openchamber",
],

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Include the claimant's model stamp in hand-back claims

For a sink candidate with payload.requires.model matching workhorse or opencode-route/workhorse, this claim always fails because it supplies neither model flags nor a session from which the CLI can derive them. The normal _collect_handed_offs path supplies LAUNCH_MODEL_PROVIDER and LAUNCH_MODEL_ID, so the same task is launchable when capacity exists but cannot be handed back when saturated. The CLI help declares [--model-provider <p>] [--model-id <id>] (pkgs/fleet/crates/fleet-queue/src/client/support.rs:236), and task_requirements_unmet explicitly rejects model-requiring tasks when the claim has no model. Pass the same model stamp here so these eligible candidates can be parked and noted rather than repeatedly skipped.

AGENTS.md reference: AGENTS.md:L80-L83

Useful? React with 👍 / 👎.

@dezren39

Copy link
Copy Markdown
Member Author

Closing as a duplicate of #12678 (merged 2026-11-22T20:52Z), which landed the same #1187 hand-back step: targeted claim of the next candidate on a saturated fire, park as executor-saturated under the capacity ready-condition, and the hand-back agent-note on the issue. Flagged during the #1234 reconciliation (2026-11-22) and dispositioned by agent felix. No unique content lost — the hand-back behaviour is on main via #12678, verified by its hermetic suite (165 tests OK at merge, 203 with today's babysitter + nudge slices).

@dezren39 dezren39 closed this Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant