Skip to content

Bug: orchestration follow-up prompt is not reliably inserted for inherited child agents #253

Closed as not planned

Description

@Juliusolsson05

Problem

When using orchestration agents with inheritParentContext: true, a follow-up prompt can fail to appear as a new instruction in the child agent. In the observed workflow, we attempted to redirect/continue an orchestrated child, but the new prompt did not get inserted into the child session.

This is especially dangerous for inherited children: the child starts from a duplicated parent transcript, so without an explicit inserted handoff/follow-up prompt it may continue interpreting the inherited conversation as if it is still the parent/orchestrator. That breaks role separation and makes parallel orchestration unreliable.

Why this matters

The existing bootstrap wrapper in src/mcp/shared/orchestrationPrompt.ts is the right idea: provider-visible text is the only reliable cross-provider instruction channel. The child must see, in its own transcript/composer input, that inherited history is read-only background and that the newly supplied task is its active instruction.

If orchestration_send_prompt reports success but the prompt is not actually inserted/submitted, the parent believes the child was redirected while the child keeps operating from stale inherited context.

Suspected areas

  • src/mcp/runtime/createBuiltInMcpServer.ts around orchestration_send_prompt
  • submitPrompt(...) behavior for Claude/Codex sessions
  • OrchestrationBridge.notePromptSubmitted(...) and lifecycle reporting after prompt delivery
  • markBootstrapPromptDelivered(...) ordering and whether bootstrap delivery is marked before/after real insertion succeeds
  • renderer/session readiness path used by orchestration prompt submission

Expected behavior

  • orchestration_send_prompt should only return ok: true after the prompt has been inserted/submitted to the target child session.
  • For inherited children whose bootstrap handoff has not been delivered, the first prompt must be wrapped with buildOrchestrationBootstrapPrompt(...).
  • If insertion/submission fails, the MCP tool must return a clear failure with a stable error code and message.
  • Prompt delivery metadata should not advance in a way that makes wait_agents or status surfaces believe a prompt is in flight unless the prompt was actually accepted by the target session.
  • The child transcript/feed should contain the inserted prompt so the child understands it is an orchestrated child, not the original parent from the inherited transcript.

Acceptance criteria

  • Add a regression test or harness coverage for orchestration_send_prompt against an inherited child.
  • Prove the first follow-up prompt to an inherited child is wrapped and inserted exactly once.
  • Prove a failed prompt insertion returns ok: false and does not mark bootstrap delivery or prompt submission state.
  • Prove a successful prompt insertion updates lifecycle/status so the parent can wait on the child without seeing stale completion.
  • Include a WHY comment near the delivery/order check explaining that inherited children can otherwise misidentify themselves as the parent agent.

Related context

This is separate from Root Access MCP (#242). Root Access is about global/non-descendant control. This bug is about scoped orchestration prompt delivery to a valid child session and the correctness of inherited-context role handoff.

Activity

  1. Juliusolsson05 commented on May 20, 2026

    @Juliusolsson05
    OwnerAuthor

    Investigation update:

    The observed failure was on the Codex orchestration path, not Claude. orchestration_send_prompt waited for Codex readiness, then wrote the bracketed paste and the trailing Enter as two separate PTY writes. That differs from the normal renderer Codex composer path, which sends bracketed paste + Enter in one write.

    Why this matters: CodexHeadless.write() records a submitted prompt as soon as it sees bracketed paste bytes. With the split-write orchestration path, the prompt ledger and orchestration delivery state can advance after the paste write even if the separate Enter write fails, is dropped, or lands outside the intended input state. For inherited children, that is especially bad because the child can keep reading the cloned parent transcript as active context without ever receiving the new handoff/follow-up task.

    Local patch: align the MCP Codex path with the renderer Codex path by doing one atomic \x1b[200~...\x1b[201~\r write after awaitCodexReadyForPrompt(...). Claude remains on the two-phase placeholder path because its paste race is different.

    Focused verification: npm run test:orchestration-mcp passes. Broader typechecks still hit existing unrelated failures in packages/codex-headless/src/channels/SemanticChannel.ts and missing pidusage typings / stale project-reference outputs.

  2. Juliusolsson05 commented on Jul 7, 2026

    @Juliusolsson05
    OwnerAuthor

    Obsolete — superseded by #260, which disabled orchestration context inheritance (inheritParentContext is forced false and the clone/resume path is removed in createBuiltInMcpServer.ts). Inherited children that resume a cloned parent transcript no longer exist, so the follow-up-prompt / role-confusion failure this tracks can't occur. Prompt-delivery correctness for clean children folds into the #259 rebuild. Closing as superseded.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions