Repository navigation
Conversation
|
Thanks for this, and for the careful write-up. The diagnosis checks out against the code: a run started on an already-open PR is promoted to To address
Non-blocking
Verified: read the diff with its callers (snapshot builder, run attachment, task worker settle path, PR watcher, pod pool). The reconciler unit test fails with Reviewed by Claude on the maintainer's behalf. |
4712163 to
b985252
Compare
|
Thanks for the thorough review.
|
…l runs A run started on an already-open PR is promoted to pr_opened straight away. Two things then misread it: the reconciler flagged the PR's conflicts/CI as needs_attention while the agent was still fixing them, and the active-count reconcile only counted running/provisioning tasks, so the pod read idle and the reaper killed it mid-run.
The attach lease renews on a timer, so a hung agent kept its PR run out of review, auto-merge, auto-resume and needs_attention indefinitely. Only wait while its last activity is within the stall threshold. The repo-pool integration test now builds leases from Postgres now(), not the host clock.
The lease renews on a timer, so counting any live lease kept a hung pr_opened agent's pod busy and unreapable. Count it only while its last activity is within the stall threshold.
ba1b6c1 to
b6e569f
Compare
|
Re-review at Earlier requests
What changes for ordinary runs (the decision)
Non-blocking
Verified: read the three commits with the reconciler's state dispatch, the snapshot's heartbeat and execution fields, Reviewed by Claude on the maintainer's behalf. |
Also cover the wait with auto-merge and review launch on, and stop the pod count test depending on OPTIO_STALL_THRESHOLD_MS being unset.
|
Thanks, the non-blocking points are done in 96625f6: changelog entry, I merged main in rather than rebasing, so the commits you reviewed keep their hashes. The CI run you approved for b6e569f never started any jobs, so the new head probably needs approving again. |
Summary
A conflict-resolve run on an existing PR got flagged
needs_attentionfor the very conflicts it was started to fix, two seconds after it started. Ten minutes later the repo pod was reaped with the agent still working in it. I saw this on a real run: provisioning to running to pr_opened to needs_attention within 2s, agent logging until 14:10, pod killed around 14:11.Two causes:
decideRunningpromotes it topr_openedimmediately.decideFromPrStatusthen seesmergeable === falseand, with auto-resume off or exhausted, moves it toneeds_attention. It never looks at whether an agent is still attached.reconcileActiveTaskCountsonly counts tasks inrunning/provisioning. Once the task waspr_opened/needs_attentionthe pod'sactive_countwas reset to 0 while the agent was still streamed, andidlePodsthen picked it up 10 minutes after that reset.Changes
reconcile-repo.ts: after the merged/closed checks,decideFromPrStatusreturns a noop (agent_still_running) while an instance holds the run's attachment and the agent's last activity is within the stall threshold. The lease renews on a timer, so the activity bound is what stops a hung agent from holding the PR forever. Merged and closed PRs still resolve immediately. The wait returns before any status is written, so a conflict or CI failure still triggers its follow-up once the agent is done.repo-pool-service.ts:reconcileActiveTaskCountsalso counts tasks with a liveattach_lease_untilwhoselast_activity_atis within the stall threshold, whatever their state. A hung agent's pod still goes idle.docs/reconciliation.mdandCHANGELOG.mddescribe the new timing.Known limits: an agent that keeps emitting events and never exits holds the follow-through for as long as it runs, and a single tool call longer than the stall threshold ends the wait early. Runs on a local machine are unchanged.
Testing
Unit tests for the reconciler (attached and active agent waits, attached but silent past the stall threshold or with no activity goes ahead, auto-merge and review launch wait too, merged PR still completes) and an integration test for the count (live lease keeps the pod busy, expired lease or silent agent frees it; leases are written from Postgres
now()so host clock drift can't flip them). Both failed before the change.pnpm check:pushpasses (every check CI runs, sized to the change;pnpm lintandpnpm knipare the quick local checks)Locally, lint, typecheck, knip, format and the full
@optio/apiand@optio/sharedunit suites pass, plus the repo-pool integration test. A fullcheck:pushon my Mac fails on time-sensitive tests (webhook delivery, schedule triggers, usage ledger) that also fail on a cleanmainthere: the Mac clock drifts tens of ms behind the podman VM's, andtrigger-deliverycompares Postgresnow()againstDate.now(). They pass onmainonce the clocks agree, so I'm leaving the box unticked and relying on CI here.Related
None.