Skip to content

fix: stop queued jobs from failing in-progress babysit runs - #167

Merged
jeremymcs merged 2 commits into
jeremymcs:mainfrom
cwbcheng:codex/fix-spurious-interrupted-run-failure
Aug 18, 2026
Merged

fix: stop queued jobs from failing in-progress babysit runs#167
jeremymcs merged 2 commits into
jeremymcs:mainfrom
cwbcheng:codex/fix-spurious-interrupted-run-failure

Conversation

@cwbcheng

@cwbcheng cwbcheng commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Problem

The PRs page showed a spurious failed run: Failed / run.failed / codex / Interrupted run missing replay context, even though the underlying run was still actively working.

Root cause

A babysit_pr background job can fire while a run for the same PR is already live in the process (the watcher re-queues follow-up work every sweep, e.g. while mergeable state is unstable). runQueuedBabysitPR then treated the active run as an "interrupted run" and — because its replay context (prompt/resolvedAgent/initialHeadSha) had not been persisted yet (in the merge-conflict path the prompt is never persisted at all) — marked it failed with "Interrupted run missing replay context". The follow-up babysitPR call was then skipped by the in-progress guard, leaving a bogus Failed entry visible in the UI until the live run's next record update overwrote it (minutes later during a long agent run).

Fix

runQueuedBabysitPR now first checks whether this process already has an active in-memory run for the PR (isRunAlreadyInProgress) and returns early if so, mirroring the existing guard in babysitPR. Recovery after a real server restart is unaffected: on restart the in-memory map is empty, so stale "running" runs are still recovered or re-run as before.

The in-progress guard was extracted into a shared private helper used by both babysitPR and runQueuedBabysitPR so the skip log stays identical.

Tests

  • Added regression test runQueuedBabysitPR does not mark a live in-progress run failed when a queued job fires before replay context is persisted (fails without the fix: the run is marked failed with the "Interrupted run missing replay context" error).
  • Verified: node --import tsx --test server/babysitter.test.ts (111 tests pass), npm run check passes.

@jeremymcs
jeremymcs force-pushed the codex/fix-spurious-interrupted-run-failure branch from 7716ac2 to 6f71213 Compare August 18, 2026 08:29
@jeremymcs

Copy link
Copy Markdown
Owner

Rebased onto main to clear the conflict.

This branch carried four commits that main had already landed separately through #163/#164/#165 (increase agent evaluation and apply timeouts, finalize code-owner fallback worktree, prevent reply loop on audit-trail comments, write GitHub comments and replies in Chinese). Those duplicates were what conflicted, so the branch is now just your unique commit on top of current main.

One real conflict needed resolving: willRetryBabysitFailure (added by #174) and your isRunAlreadyInProgress were inserted at the same point in babysitter.ts. Both are kept.

Verified locally: npm run check, npm run test:all (789 tests), npx eslint . — all green.

@jeremymcs
jeremymcs merged commit b23a4fc into jeremymcs:main Aug 18, 2026
8 checks passed
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.

2 participants