Skip to content

orchestration: /plan confirm race condition in piped stdin mode — 'Plan canceled' before sub-agent results #2246

@bug-ops

Description

@bug-ops

Summary

When running the agent in piped stdin mode (echo "..." | cargo run ...) with confirm_before_execute = true, after sending /plan confirm, the DagScheduler cancels tasks with Plan canceled. N/N tasks did not run. — but sub-agent results still appear afterward. This is a race condition between stdin EOF triggering shutdown and background tokio sub-agent tasks completing.

Reproduction

echo -e "/plan research memory systems\n/plan confirm" | \
  RUST_LOG=zeph_orchestration=debug cargo run --features full -- --config .local/config/testing.toml \
  2>.local/testing/debug/session.log

Config: confirm_before_execute = true, max_tasks = 10, max_parallel = 2

Observed behavior

  1. Agent receives /plan research ..., generates a plan, displays it
  2. Agent receives /plan confirm, starts executing plan
  3. Stdin reaches EOF → agent shutdown begins
  4. DagScheduler logs Plan canceled. 2/2 tasks did not run.
  5. Sub-agent results still print to stdout after the "canceled" message

Expected behavior

Either:

  • The scheduler should wait for in-flight tasks before honoring the shutdown signal (graceful drain), OR
  • The "Plan canceled" message should only appear if no tasks started

Root cause (hypothesis)

DagScheduler receives cancellation via the shutdown token when stdin reaches EOF. It logs "canceled" immediately, but tokio sub-agent tasks that were already spawned continue to completion on the runtime. The shutdown/cancel path does not drain in-flight futures.

Context

Fix direction

In DagScheduler::run() (or shutdown handler), after receiving cancellation, await all in-flight task futures before logging "canceled" and returning. Alternatively, only log "canceled" for tasks that were never started (not in-flight).

Metadata

Metadata

Assignees

Labels

P3Research — medium-high complexitybugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions