fix: preserve running status while a job starts

Merged
BO
1mo ago
+136-1

Concurrent Python calls to Supervisor.start() and Supervisor.status() on the same instance could mark a job failed before its worker starts. The job could then complete successfully with a stale crash error. Check the existing startup reservation and fresh record ownership under the registry lock before reconciling an absent worker.

Regression tests pause startup after metadata creation and before Thread.start(), then verify normal completion without the false diagnostic. A duplicate-start test checks that orphan reconciliation resumes once the reservation is released. Foreign-owner and terminal handling are preserved. Standard synchronous stdio handling does not interleave these calls.

Validation: 150 selected Supervisor, MCP and session-store tests passed on Linux/Python 3.12, plus Ruff, an offline wheel/sdist build and the release artifact audit. Local full-suite, native Windows and real-provider E2E runs were not performed.

CI for e9da634 passed all five code jobs and 48 steps, including required lint/test/build/artifact checks and Linux/macOS compatibility tests on Python 3.11 and 3.13: CI run.

Follow-up to the startup race identified in #16.

Summary by Sourcery

Preserve running job state while local workers are starting and reconcile genuine orphaned jobs after startup reservations are released.

Bug Fixes:

  • Prevent status checks from falsely marking locally starting jobs as failed before their worker begins.
  • Preserve orphan reconciliation for duplicate starts after the startup reservation is released.

Tests:

  • Add regression coverage for status checks during startup and duplicate-start orphan reconciliation.

Summary by cubic

Fixes a race where concurrent Supervisor.start() and Supervisor.status() calls on the same instance could mark a job failed before its worker started, leaving a stale crash error on a job that later completed successfully.

  • status() now checks the job's local startup reservation and fresh record ownership under the registry lock before reconciling an absent worker.
  • Orphan reconciliation is preserved for foreign-owned records and resumes once a duplicate start releases its reservation.
  • Adds regression tests for status checks during startup and for duplicate-start orphan reconciliation.

Summary by CodeRabbit

  • Bug Fixes
    • Job status now remains accurate while a job is starting, rather than incorrectly showing it as failed.
    • Cancellation requests during startup correctly indicate when the job cannot yet be cancelled.
    • Duplicate job starts are reconciled to a failed status when the start attempt returns.