Skip to content

fix(orchestrator): Expose pending delegated child work - #4793

Open
mwolson wants to merge 3 commits into
pingdotgg:t3code/codex-turn-mappingfrom
mwolson:fix/delegated-task-status-queued-turn
Open

fix(orchestrator): Expose pending delegated child work#4793
mwolson wants to merge 3 commits into
pingdotgg:t3code/codex-turn-mappingfrom
mwolson:fix/delegated-task-status-queued-turn

Conversation

@mwolson

@mwolson mwolson commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Summary

Expose whether a delegated child thread has later work pending without changing
the established meaning of the original delegation fields.

childRunId, status, summary, and resultContextTransferId stay tied to
the original delegate_task run. New hasPendingChildRuns and
latestTerminal* fields let callers avoid treating a busy child as idle and
inspect its newest meaningful terminal result.

This replaces the earlier broader implementation. The branch no longer changes
current-run selection, per-follow-up result finalization, wake policy, or
task_cancel behavior.

Problem and Fix

Problem and Why it Happened Fix
task_status intentionally reported the original delegated run, but provided no indication that the same child thread had a queued or executing follow-up. A caller could see completed and act on a workspace the child was still changing. Add hasPendingChildRuns, derived from nonterminal runs with a later ordinal than the delegated run, while preserving the original delegation fields.
The original result remains useful while later work is active, but callers could not identify the newest completed follow-up. Add latestTerminalRunId, latestTerminalStatus, latestTerminalSummary, and latestTerminalResultContextTransferId. Rolled-back runs and never-started later cancellations do not displace a meaningful result.
Legacy projections without a subagent_spawn transfer selected the latest child run as the delegated run, which could hide later active work. Preserve the first child run as the delegated run for legacy projections and use run ordinals to identify later work.
Tool documentation did not state that wait mode and primary status fields describe the original delegated run. Document the stable primary fields and the new observability fields in the MCP tool descriptions and orchestration reference.

Validation

  • Focused contract and MCP integration tests: 2 files, 6 tests passed.
  • The existing CTM cancellation-isolation regression remains unchanged and
    passes: cancelling a completed original task does not interrupt a later child
    run.
  • Targeted formatting and lint passed for all six changed files.
  • Contracts typecheck passed.
  • Isolated headless live test with a Claude parent and real Codex child:
    • Original ordinal 1 completed with STATUS_FIRST_DONE.
    • During ordinal 2, primary fields stayed on ordinal 1,
      hasPendingChildRuns was true, and the latest terminal result stayed on
      ordinal 1.
    • After ordinal 2 completed with STATUS_SECOND_DONE, pending became false
      and latestTerminalRunId advanced to ordinal 2 while primary fields
      remained unchanged.
  • GitHub Release Smoke, Mobile Native Static Analysis, CodeRabbit, Cursor
    Bugbot, and Macroscope Effect Service Conventions pass.
  • Test currently fails in five unchanged queued-turn replay assertions from the
    newer t3code/codex-turn-mapping merge result. Check is separately red from
    the known Vite+ stdout panic while printing warnings.

Checklist

  • This PR is small and focused
  • I explained what changed and why

Note

Medium Risk
Extends the orchestrator MCP result schema and changes legacy delegated-run selection; callers relying on old semantics or latest-run fallback could misread status, though primary fields are intentionally preserved and cancel/wake behavior is unchanged.

Overview
Delegated task MCP responses now report follow-up child activity without changing what the original delegation fields mean. childRunId, status, summary, and resultContextTransferId still describe the first delegate_task run.

task_status and delegate_task results add hasPendingChildRuns (true when any later child run is still queued or executing) and latestTerminal* fields that surface the highest-ordinal meaningful terminal run that actually started, including summary and subagent_result transfer id. Rolled-back runs and never-started cancellations are excluded from that “latest” view. Context transfer resolution now prefers transfers whose sourcePoint.runId matches the run in question.

For legacy child projections without a subagent_spawn transfer, delegatedTaskRun now uses the first run in childProjection.runs instead of the latest run, so primary status stays on the original delegation.

Contracts, orchestrator MCP tool descriptions, and the orchestration reference doc are updated; integration and contract tests cover follow-ups, pending state, and cancellation isolation.

Reviewed by Cursor Bugbot for commit e87ea74. Bugbot is set up for automated code reviews on this repo. Configure here.

Note

Expose pending delegated child work in orchestrator task_status responses

  • Adds hasPendingChildRuns and latestTerminal* fields (latestTerminalRunId, latestTerminalStatus, latestTerminalSummary, latestTerminalResultContextTransferId) to OrchestratorMcpDelegateTaskResult so callers can distinguish follow-up child runs from the original delegated run.
  • The new hasPendingChildRuns helper returns true when the child projection contains non-terminal runs with a higher ordinal than the delegated run, signaling that additional work is in progress.
  • The latestTerminal* fields reflect the highest-ordinal meaningful terminal run, excluding rolled_back and never-started cancellations; resultContextTransferId resolution now prefers transfers whose sourcePoint.runId matches the run.
  • Behavioral Change: delegatedTaskRun now returns the first run in childProjection.runs for legacy projections without a subagent_spawn transfer, instead of the previously computed latest run.

Macroscope summarized e87ea74.

@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 6e60d16f-b7b4-477e-b468-d36bc166ced3

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added vouch:unvouched PR author is not yet trusted in the VOUCHED list. size:L 100-499 changed lines (additions + deletions). labels Jul 28, 2026
@mwolson
mwolson marked this pull request as ready for review July 28, 2026 23:20
@macroscopeapp

macroscopeapp Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Needs human review

1 blocking correctness issue found. This PR adds new orchestrator capability to expose pending child work state through multiple new fields. An unresolved high-severity comment identifies a potential logic bug in hasPendingChildRuns that could cause incorrect behavior.

You can customize Macroscope's approvability policy. Learn more.

@mwolson
mwolson force-pushed the fix/delegated-task-status-queued-turn branch from e1056de to 4df5866 Compare July 30, 2026 03:08
@github-actions github-actions Bot added size:M 30-99 changed lines (additions + deletions). and removed size:L 100-499 changed lines (additions + deletions). labels Jul 30, 2026
@mwolson mwolson changed the title fix(orchestrator): Report current delegated task status fix(orchestrator): Expose pending delegated child work Jul 30, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 4df5866. Configure here.

Comment thread apps/server/src/mcp/OrchestratorMcpService.ts Outdated
Comment thread apps/server/src/mcp/OrchestratorMcpService.ts Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M 30-99 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant