fix(backend): resume only the schedules archiving paused when re-hiring an expert #17267
All Vouch review confidence checks passed
Residual risk 0.35 = Change Risk (0.52) × (1 − Review Confidence (0.32)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 58% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #17267"
general
weight: 0.35
coderabbitai[bot]
Why / What / How
Why: Letting an expert go pauses its running schedules, and hiring it again resumed every paused schedule attributed to it, including the ones the user had paused themselves. The user then saw runs, and possibly charges, they had switched off. Presets and routines already tell the two kinds of pause apart (
AgentPreset.deactivatedByExpertArchive,ExpertRoutine.pausedByExpertArchive). Workflow schedules had nowhere to keep that mark: a schedule is an APScheduler job, not a Prisma row, and a pause is stored only asnext_run_time = NULL. The experts journey in #17266 reproduces the bug end to end on dev; the steps are in the issue's latest comment.What: Re-hiring now resumes only the schedules that letting the expert go paused. A schedule the user paused before letting the expert go, or while it was away, stays paused.
How: The mark lives on the job itself, so no migration is needed.
GraphExecutionJobArgsgainspaused_by_expert_archive(defaultFalse), which is stored in the job's kwargs.pause_execution_schedule(..., for_expert_archive=True)pauses a running workflow schedule and marks it in onemodify_jobwrite. It never marks a schedule that is already paused, because that pause was someone else's.resume_execution_schedule(..., only_if_paused_by_expert_archive=True)resumes only a marked schedule and clears the mark. Every resume clears it.next_run_time: both are pause state, not part of what the create asked for.Schedules archived before this change carry no mark, so re-hiring leaves them paused. The archive used to pause them with the same call a user's pause makes, so nothing tells "paused by letting the expert go" apart from "paused by the user". Resuming them would repeat this bug for anyone who had paused one on purpose. Leaving them paused costs one resume: they show as Paused on the expert's schedules, and the expert resumes them from chat (
resume_schedule). The same holds during the rollout. An old scheduler ignores the new arguments, because the RPC body model drops unknown fields, and an old API pod doesn't send them. So mixed versions never resume more than they do today, and a schedule an old pod pauses carries no mark, which leaves it paused on a later re-hire.The approach follows #15101 by goingforstudying-ctrl. That PR was closed unmerged; this is a new implementation on current dev. It also lets a user's pause take over a schedule the archive already paused, holds the jobstore lock across each read and write, and keeps the mark out of the create-retry comparison.
Fixes #14577
Changes 🏗️
backend/executor/scheduler.py: thepaused_by_expert_archivemark;pause_execution_schedule(for_expert_archive=...)andresume_execution_schedule(only_if_paused_by_expert_archive=...), both under the jobstore lock; the create-retry comparison leaves the mark out.backend/api/features/experts/scheduling.py:detach_expert_triggersmarks the schedules it pauses;reattach_expert_triggersresumes only marked ones.frontend/src/app/api/openapi.json: regenerated;GraphExecutionJobInfogains the field.backend/executor/scheduler_archive_mark_test.py: a real APScheduler on a SQL job store. Covers who sets and clears the mark, a job stored before the mark existed, an edit, a create retry, and a forced race between a user's pause and the archive flow.backend/api/features/experts/rehire_schedules_test.py: DB-backed, against the scheduler service and its job store, through the real archive and hire flows. Covers the issue's steps (paused from the expert's chat, two round trips), a pause while the expert is away (directly, and after a resume), and a schedule archived before the mark existed.backend/api/features/experts/experts_db_test.py: the mocked detach and reattach tests now expect the new arguments.No
data/.pychanges and no new queries. The scheduler's pause and resume still check the job's owner (_authorized_job, by user id) before they read or write it.The journey's re-hire check in #17266 is still pinned with a runtime
test.fail(). #17266 hasn't merged yet; once both have landed, that pin comes off.Agents and large language models used
Checklist 📋
For code changes:
- [x] The 4 new DB tests pass on this branch. They ran against the scheduler service and its job store, on a private Postgres, Redis cluster and RabbitMQ stack with the
serverfixture.- [x] Revert check. The same 4 tests fail on dev
4b4a8354a2(fix reverted, tests kept), on the bug itself. Three fail with "the user's paused schedule resumed"; the pre-mark case fails with its paused schedule running again. The 11 new scheduler tests fail on dev too, since the arguments don't exist there.- [x] Mutation checks. Seven one-change mutants of the scheduler: no lock in pause, no lock in resume, the create retry comparing the mark, no take-over by a user's pause, the archive marking an already-paused schedule, a resume keeping the mark, and re-hire ignoring the mark. Each fails at least one of the new scheduler tests. An archive that forgets to mark fails 3 of the 4 DB tests; the pre-mark case passes either way.
- [x] Neighbours on this branch, 229 passed.
executor/scheduler_test.py,scheduler_cadence_test.pyandscheduler_idempotent_create_test.py; the expertsscheduling_test.pyandworkflow_removal_test.py;copilot/tools/manage_schedules_test.py; the schedulesroutes_test.py; the external v2schedules_test.py; and the three detach/reattach tests inexperts_db_test.py.- [x]
backend/util/architecture_test.pyandbackend/blocks/test/test_block.py: 4451 passed, 84 skipped.- [x] Whole-backend
pyright: 0 errors.ruff check(0.17.4), isort 9.0.2 andblackchange nothing.- [x]
export-api-schemaplus prettier: theopenapi.jsondiff is the one new field. Whole-frontendtsc --noEmit,next lint, oxlint andprettier --check .pass.For frontend changes (design system, see
docs/engineering/design-system.md):Not applicable: the only frontend change is the generated
openapi.json.For configuration changes:
None.
🤖 Generated with Claude Code