fix(server): run_scheduled_task_now returns the thread the run launched #17458
main fromrefs/pull/17458/head·merged by juliusmarminge View on GitHubrun_scheduled_task_now returned a task’s configured thread binding, so runs that created a fresh thread returned null. It now returns the thread the run actually dispatched to. Failed dispatches return null; subsequent runs retain the original task binding.
The scheduler service carries the dispatch result to the thin MCP handler. Both launch and bound-thread sends normalize their success result to a thread ID. Existing MCP and client wire schemas stay compatible; webhook and timed scheduling retain their bookkeeping behavior.
Based on @sbansal1999’s #17458. Preserved the contributor’s commits and merged main.
Verification:
- Focused suite: 122 tests before → 123 tests after in five existing files. Retained fresh/bound × user/agent success assertions, extended five existing failed-launch cases with null-result assertions, and added one failed-bound-send case checking null output and preserved binding.
- Without the production fix, all nine original relevant cases fail. Reintroducing the original patch’s failed-bound-send behavior also fails the new case; restored fix passes. These integration cases use real orchestration services and persisted thread/message projections, without starting provider processes.
- Server typecheck, focused lint and formatting pass. Lint retains one existing test warning.
- No screenshots apply to this server response change. No live MCP/provider launch was performed; macOS, Windows, iOS, Android, and Electron desktop were not exercised.
Implemented with Codex gpt-6.1-sol in T3 Code; tests by Codex gpt-6-astra. Independent adversarial reviews: two rounds each with Claude claude-opus-5-5 and Codex gpt-6-sol; the second round checks the failed-bound-send coverage and tool description.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:S
sbansal1999(GitHub profile, opens in a new tab) changed the title
Approvability#
Verdict: Approved at
784981dMacroscope's review found this PR approvable — This is a localized server bug fix that reports the thread actually used by a scheduled-task run while preserving task bindings and existing scheduling behavior. Added coverage verifies successful fresh-thread dispatch and null results on failed dispatch.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).Warning
Review limit reached#
Only developers with an assigned seat can use this organization's usage-based review budget, and seats here are assigned manually. Ask an admin to assign a seat, or change the review continuation mode in Billing.
Next included review available in 4 minutes.
View limit details
-
Limit details: You’ve used all 10 included reviews currently available.
Review configuration:
⚙️ Run configuration
-
- Configuration used: Path: .coderabbit.config.ts
- Review profile: CHILL
- Plan: Advanced
- Run ID:
838e30e0-af9e-4bb9-9e21-d69e8f317217
📥 Commits
-
Reviewing files that changed from the base of the PR and between 405ee64cd8d98face8e09956b373f94076918bc6 and 784981de1d5ea6d28082fd277e2375fb0a9ef21f.
📒 Files selected for processing: 5
-
apps/server/src/mcp/toolkits/thread/handlers.tsapps/server/src/mcp/toolkits/thread/tools.tsapps/server/src/orchestration-v2/ThreadLaunchService.test.tsapps/server/src/scheduledTasks/ScheduledTaskService.interval.test.tsapps/server/src/scheduledTasks/ScheduledTaskService.ts
-
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
-
⚙️ Run configuration
-
- Configuration used: Path: .coderabbit.config.ts
- Review profile: CHILL
- Plan: Advanced
- Run ID:
5b9f63d6-15b9-4c6c-bcd6-04a8767c5244
📥 Commits
-
Reviewing files that changed from the base of the PR and between e16fab3f5c7e86f4fa7b4e1831d8240e588bc4d6 and 405ee64cd8d98face8e09956b373f94076918bc6.
📒 Files selected for processing: 3
-
apps/server/src/mcp/toolkits/thread/handlers.tsapps/server/src/orchestration-v2/ThreadLaunchService.test.tsapps/server/src/scheduledTasks/ScheduledTaskService.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
-
📝 Walkthrough
-
Scheduled task runs now return a
threadIdalongside the task. The result contains the bound thread ID, the launched thread ID after a successful launch, ornullwhen no thread is available. The MCP handler returns this value.Changes: Scheduled task run results
Layer / File(s) Summary Resolve the thread ID for each run
apps/server/src/scheduledTasks/ScheduledTaskService.tsrunTaskreturns the task with athreadId. It uses the bound thread ID or the launched thread ID after a successful launch. Non-dispatch paths and failed launches returnnull.Return and consume the run result
apps/server/src/scheduledTasks/ScheduledTaskService.ts,apps/server/src/mcp/toolkits/thread/handlers.ts,apps/server/src/orchestration-v2/ThreadLaunchService.test.tsrunNowreturns the expanded result. Webhook handling reads the task from the result. The MCP handler reads itsthreadId, and a test checks that value against the selected thread.Priority: ⬇️ Low
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix
Suggested reviewers:
juliusmarminge
Merge Risk: ⚪ Minimal · up to
405ee-
No actionable issue is established for this change; it is ready to merge after normal checks.
Security architecture risk: 🔵 Low · up to
405ee-
The returned identifier comes from the task’s bound thread or the thread launched for that run. Existing full-access requirements and task-selected execution targets remain unchanged. No introduced authorization bypass was established, although concurrent replacement and recovery behavior are not fully validated.
Retained concerns No architecture-level concerns identified.
Security review details
-
Security Blast Radius
- inferred — The relevant authority is environment-level rather than limited to the calling thread: an authorized caller selects an existing scheduled task, whose configuration determines the target project and thread. The change makes a fresh run’s thread directly addressable to that caller but does not add target-selection inputs or establish a new tenant or service boundary.
Trust Boundaries and Controls
- observed — The unchanged MCP wrapper rejects read-only clients, requires orchestration capability, checks live provider ownership for thread callers, and requires full-access/default authority. The handler also verifies task existence before calling runNow. Returning the thread identity does not replace these controls.
Resilience and Maintainability Implications
- observed — The result refactor preserves in-memory run reservation, dispatch failure capture, best-effort stuck-run recovery, and guaranteed reservation release. Webhook failure accounting still depends on task status rather than the new identifier. No changed failure-containment mechanism was found in the base-to-head comparison.
-
Pre-merge checks:
3 · 1-
Failed checks: 1 warningCheck name Status Explanation Resolution Description check The description explains the problem, implementation, verification, test results, and limitations. However, it omits the required Scope and approval section and does not provide a triaged issue, maint… Add a Scope and approval section. Link the relevant issue or maintainer approval with the approval comment, or explain why this focused fix qualifies as an obvious bug that does not require prior approval. Passed checks: 3 passed-
Check name Status Explanation Linked Issues check No active directly linked targets remain. Issue #8731is closed and supplies historical context only. Therefore, this PR has no linked-issue coding requirements to assess.Out of Scope Changes check The handler, ScheduledTaskService, and focused test changes implement the stated threadId behavior for run_scheduled_task_now. The changes remain within the server scheduled-task service and MCP tool … Title check The title clearly and concisely describes the primary change: returning the thread launched by run_scheduled_task_now. Full details: Out of Scope Changes check
-
Explanation
The handler, ScheduledTaskService, and focused test changes implement the stated threadId behavior for run_scheduled_task_now. The changes remain within the server scheduled-task service and MCP tool scope. The test changes support that implementation.
-
Full details: Description check
-
Explanation
The description explains the problem, implementation, verification, test results, and limitations. However, it omits the required Scope and approval section and does not provide a triaged issue, maintainer approval, or a clear justification for the small-obvious-bug exemption.
Resolution
Add a Scope and approval section. Link the relevant issue or maintainer approval with the approval comment, or explain why this focused fix qualifies as an obvious bug that does not require prior approval.
-
✨ Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
-
coderabbitai[bot](GitHub profile, opens in a new tab) approved these changes
sbansal1999(GitHub profile, opens in a new tab) changed the title
sbansal1999(GitHub profile, opens in a new tab) changed the title
juliusmarminge added labelsmacroscope-review
juliusmarminge assignedjuliusmarminge
Taking over this one. I will bring it onto current main, keep the service returning the actual launched thread, and verify the manual-run behavior before pushing to this branch.
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:S
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes
juliusmarminge merged thisec967f3
juliusmarminge closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed