feat(lifecycle): scans interrupted by an agent restart start again #459

Merged
sharang merged 1 commits from fix/requeue-interrupted-scans into main 2026-10-05 20:14:28 +00:00
Owner

Follow-up requested by the platform session. On prod, Orca's reconciler redeployed the agent at 21:50, which interrupted the customer scans car-system and gt-mobile. They stayed interrupted until the 02:00 run.

Change

  • lifecycle::resume_interrupted_scans, started in the background by main right after recover_orphaned_runs:
    • Which tenants: the same list as the scheduler (scheduler_tenants, from the registry, runnable tenants only), so a suspended tenant gets nothing restarted.
    • Which scans: the code scans closed as interrupted by this startup, matched on the identical completed_at.
    • How: through the normal path, run_target_scan (scan gate, concurrency), as a Scheduled scan, so usage isn't counted as a customer action.
  • Not restarted:
    • archived or deleted targets;
    • a target already interrupted once in the last 24 hours. The scan itself may be what stops the agent (OOM, crash), and restarting it would loop. The next scheduled run tries again.
  • scheduler::scheduler_tenants is now pub(crate).

Tests

  • only_scans_this_start_interrupted_are_resumed_once (Mongo), with four targets:
    • left open at this startup → resumed;
    • already interrupted 1 hour ago → not resumed;
    • archived → not resumed;
    • only an older interrupted run → not resumed.
  • fmt and clippy with the CI flags.

🤖 Generated with Claude Code

https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p

Follow-up requested by the platform session. On prod, Orca's reconciler redeployed the agent at 21:50, which interrupted the customer scans `car-system` and `gt-mobile`. They stayed `interrupted` until the 02:00 run. ## Change - **`lifecycle::resume_interrupted_scans`**, started in the background by `main` right after `recover_orphaned_runs`: - **Which tenants:** the same list as the scheduler (`scheduler_tenants`, from the registry, runnable tenants only), so a suspended tenant gets nothing restarted. - **Which scans:** the code scans closed as `interrupted` by **this** startup, matched on the identical `completed_at`. - **How:** through the normal path, `run_target_scan` (scan gate, concurrency), as a `Scheduled` scan, so usage isn't counted as a customer action. - **Not restarted:** - archived or deleted targets; - **a target already interrupted once in the last 24 hours.** The scan itself may be what stops the agent (OOM, crash), and restarting it would loop. The next scheduled run tries again. - `scheduler::scheduler_tenants` is now `pub(crate)`. ## Tests - `only_scans_this_start_interrupted_are_resumed_once` (Mongo), with four targets: - left open at this startup → resumed; - already interrupted 1 hour ago → not resumed; - archived → not resumed; - only an older interrupted run → not resumed. - fmt and clippy with the CI flags. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p
sharang added 1 commit 2026-10-05 20:05:35 +00:00
feat(lifecycle): scans interrupted by an agent restart start again
CI / Check (push) Skipped
CI / Detect Changes (pull_request) Skipped
CI / Deploy Agent (pull_request) Skipped
CI / Deploy Dashboard (pull_request) Skipped
CI / Deploy Docs (pull_request) Skipped
CI / Deploy MCP (pull_request) Skipped
CI / Check (pull_request) Successful in 8m18s
c05326e15f
A redeploy or restart closes the scans it cut off as `interrupted`
(#65), and nothing started them again: on prod the reconciler's redeploy
interrupted two customer scans that then waited for the nightly run.

After recover_orphaned_runs, resume_interrupted_scans starts those scans
again in the background, for every tenant the scheduler runs for (so a
suspended tenant is not), through the normal scan path (scan gate,
concurrency), as a scheduled scan. It finds them by the completed_at
this startup gave them. A target that is archived or gone is skipped, and
so is one whose scan was already interrupted within the last day: the
scan itself may be what stops the agent, and restarting it would loop.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p
sharang merged commit 0da96110c3 into main 2026-10-05 20:14:28 +00:00
Sign in to join this conversation.