Repository navigation
opencode-claimant: migration-0022 — clear bound session_id on requeue + bind-time claim guard (#5001) - #5349
Conversation
… transitions + bind-time claim guard (#5001)
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 42 minutes. View limit details
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. |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 884f122652
ℹ️ 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".
| t agent.tasks; | ||
| row_out agent.repo_task_lane_ledger; | ||
| begin | ||
| select * into t from agent.tasks where id = p_task_id; |
There was a problem hiding this comment.
Lock the task row before binding its session
When a same-session bind retry overlaps park_task or another binding-clearing transition, the new clearing code locks the task row before updating the ledger, while this function updates the ledger before locking the task. This introduces a lock-order cycle that can deadlock and abort either the bind or the task transition. Acquire the task row with FOR UPDATE here before accessing the ledger; this also prevents a transition from invalidating the new claim/lease check before the binding is written.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
🤖 Agent note · disposition (queue worker, task 9043, lane code-b)
Acknowledged — this is a real defect in the live-applied function body. This PR is the record copy of a migration already applied live (2026-11-04T08:08Z); the copy must stay faithful to the applied SQL, so the fix does not land by editing this file. It is tracked as issue #5393 with queue task 9348: a new claimant migration that re-extracts the live function bodies, takes the task row FOR UPDATE before touching the ledger in bind_repo_task_lane_session, and keeps lock order consistent across every binding-clearing transition.
There was a problem hiding this comment.
Fixed live by migration-0024 (record copy: PR #5399, for #5393): bind_repo_task_lane_session now takes the task row FOR UPDATE in its first statement, before any ledger access — matching the task-first lock order of every binding-clearing transition in migration-0023. Verified by pg_get_functiondef before/after diff (only this statement changed) plus lock-order inspection across all six migration-0023 transitions.
There was a problem hiding this comment.
Fixed live by migration-0024 (record copy: PR #5399, for #5393): bind_repo_task_lane_session now takes the task row FOR UPDATE in its first statement, before any ledger access — matching the task-first lock order of every binding-clearing transition in migration-0023. Verified by pg_get_functiondef before/after diff (only this statement changed) plus lock-order inspection across all six migration-0023 transitions.
| if r.progress ->> 'session_id' is not null then | ||
| update agent.repo_task_lane_ledger | ||
| set session_id = null, updated_at = now() | ||
| where task_id = r.id and session_id is not null; |
There was a problem hiding this comment.
Qualify the ledger task identifier in the release branch
When revalidation releases a parked task that still has progress.session_id, this statement fails under PostgreSQL's default PL/pgSQL variable-conflict handling: RETURNS TABLE(task_id bigint, outcome text) declares a task_id output variable, making the unqualified task_id here ambiguous with the ledger column. The error rolls back the entire sweep, including other releases processed in that call. Alias the ledger table and qualify its task_id column.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
🤖 Agent note · disposition (queue worker, task 9043, lane code-b)
Acknowledged — same disposition as the lock-order finding: real defect in the live-applied body, tracked as issue #5393 with queue task 9348. The follow-up migration aliases the ledger table and qualifies task_id in the revalidate_parked_tasks release branch, and its acceptance includes exercising that branch with a parked task that still carries progress.session_id. This PR stays a faithful record copy of the applied SQL (renumbered to migration-0023.sql only because main landed a different migration-0022.sql for issue #4758).
There was a problem hiding this comment.
Fixed live by migration-0024 (record copy: PR #5399, for #5393): the release branch now aliases agent.repo_task_lane_ledger as l and qualifies l.task_id. Reproduced before the fix in a rolled-back transaction (synthetic parked task with progress.session_id): ERROR 42702 column reference "task_id" is ambiguous, aborting the sweep. After the fix the same exercise completes — task released to queued, ledger session cleared — and the pg_get_functiondef diff shows only this change.
…22 taken on main by #4758)
…on-binding-clearing
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8bdc8b1114
ℹ️ 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".
| if t.status <> 'claimed' or t.lease_until is null or t.lease_until <= now() then | ||
| raise exception 'bind_repo_task_lane_session: task % is not claimed with a live lease (status %, lease_until %)', | ||
| p_task_id, t.status, t.lease_until; |
There was a problem hiding this comment.
Preserve the existing session-recovery mode
When the claimant recovers a deleted zero-message session or an absent session, prompt.md:92-112 still calls this RPC with opencode-claimant-recovery:* after lease expiry. Migration 0022 explicitly handles those calls by compare-and-clearing both bindings, recording launch_failed, and incrementing attempts. This replacement removes that branch and rejects the expired lease instead; even with a live lease, it merely rebinds the old session ID. Applying migrations in order therefore disables the documented recovery operation and leaves the unavailable session bound until another transition clears it. Preserve the recovery branch and apply the live-lease guard only to normal binding calls.
Useful? React with 👍 / 👎.
What
Adds
pm-stack/opencode-claimant/migration-0022.sql— the durable repo copy of the migration already applied live to the muse-dev queue DB by task 9043 (issue #5001) on 2026-11-04. This PR is the record copy, mirroring where migration-0021 lives; merging it changes no runtime behavior.The fix (live since ~08:08Z)
progress.session_id/launched_by+repo_task_lane_ledger.session_id) in the same transaction, preserving the old id inprogress.session_clearedand anagent.eventsrow (session_binding_cleared):expire_leases,fail_repo_task(requeue branch),park_task,revalidate_parked_tasks(release branch).claim_repo_taskalso clears any residual binding on the row it claims.bind_repo_task_lane_sessionnow refuses to bind unless the task isclaimedwith a live lease in the same transaction — closing the pre-expiry poll-snapshot launch race from issue opencode-claimant: requeue/lease expiry never clears a bound session_id — a live session can sit on a claimable task (7787), and a relaunch can never re-bind #5001.Verification
Refs #5001 (task 9043 will close it on completion).
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.