Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

test(agent): assert the deferring seam emits no TurnCompleted

M3gA-Mind2bff4f831983
diff --git a/crates/openhuman-core/src/agent/session_host/turn/graph.rs b/crates/openhuman-core/src/agent/session_host/turn/graph.rs
index eb4f95628b..c089a6373e 100644
--- a/crates/openhuman-core/src/agent/session_host/turn/graph.rs
+++ b/crates/openhuman-core/src/agent/session_host/turn/graph.rs
@@ -125,6 +125,26 @@ pub(crate) async fn run_chat_turn_graph(graph: ChatTurnGraph) -> Result<Tinyagen
run_context.workspace = graph.workspace_descriptor.clone().or(run_context.workspace);
run_context.sandbox_mode = Some(graph.sandbox_mode);
run_context.thread_id = graph.thread_id;
+
+ // Bound by name rather than passed as bare `true` literals.
+ // `run_root_turn_via_hosted_agent` takes eighteen positional arguments,
+ // and these two `bool`s sat eleven lines apart in the call below. While
+ // investigating #6541 that pair produced four separate misreadings —
+ // in both directions, including one that briefly discarded a correct
+ // finding — because aligning an argument against the signature by
+ // counting is the only way to tell which flag a `true` belongs to.
+ // A binding puts the name inside the expression, so a future reordering
+ // is visible here and not only in the signature.
+ //
+ // Pause gracefully at the model-call cap so the turn emits a resumable
+ // checkpoint instead of erroring or returning a dangling tool cycle.
+ let pause_at_cap = true;
+ // The runtime's durable `after_commit` callback emits the terminal
+ // event after any driver-grounded close has become part of the
+ // candidate history. A seam-level event would arrive before that
+ // close and duplicate the lifecycle projection.
+ let defer_turn_completed_to_caller = true;
+
run_root_turn_via_hosted_agent(
run_context,
hosted_base,
@@ -158,9 +178,7 @@ pub(crate) async fn run_chat_turn_graph(graph: ChatTurnGraph) -> Result<Tinyagen
// on. Users watched an "Ask User Clarification" step succeed without
// ever being asked anything.
&["ask_user_clarification"],
- // Pause gracefully at the model-call cap so the turn emits a resumable
- // checkpoint instead of erroring or returning a dangling tool cycle.
- true,
+ pause_at_cap,
// Bound the main agent's per-call output (legacy parity — the engine
// capped every turn at `AGENT_TURN_MAX_OUTPUT_TOKENS`).
Some(AGENT_TURN_MAX_OUTPUT_TOKENS),
@@ -168,11 +186,7 @@ pub(crate) async fn run_chat_turn_graph(graph: ChatTurnGraph) -> Result<Tinyagen
graph.context_mw,
// Builder-configured tool policy enforcement (session chat path).
graph.tool_policy,
- // The runtime's durable `after_commit` callback emits the terminal
- // event after any driver-grounded close has become part of the
- // candidate history. A seam-level event would arrive before that
- // close and duplicate the lifecycle projection.
- true,
+ defer_turn_completed_to_caller,
)
.await
})
diff --git a/crates/openhuman-core/src/agent/tinyagents/turn_runner_tests.rs b/crates/openhuman-core/src/agent/tinyagents/turn_runner_tests.rs
index 1e5ff31aa7..e850abea77 100644
--- a/crates/openhuman-core/src/agent/tinyagents/turn_runner_tests.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/turn_runner_tests.rs
@@ -194,9 +194,32 @@ async fn a_streamed_delta_reaches_the_progress_channel_exactly_once() {
vec!["one delta".to_string()],
"every model delta is forwarded once, by one producer"
);
+ // The two counters have OPPOSITE contracts. Read them separately.
+ //
+ // `completed` is asserted by equality at 0, and that is a documented
+ // design: `run_root` passes `defer_turn_completed_to_caller = true`, so
+ // `turn_runner` leaves `turn_completed_sink` as `None` and the seam emits no
+ // terminal event — the caller emits the single one after its post-run
+ // wrap-up. It was `<= 1` before, which a seam emitting once also satisfies,
+ // and a seam emitting once on the deferring path is exactly the duplication
+ // this test exists to prevent. So the ceiling could not fail in the
+ // direction the test was written for. Do not loosen this one back.
+ //
+ // `started` deliberately stays a ceiling. The deferral flag governs
+ // `TurnCompleted` only; it does not suppress the root's `Started` event.
+ // `host/progress_sink.rs:400` forwards `TurnStarted` for the root run, and
+ // the module docs at `:59` and `:185` say only the root projects a
+ // top-level one — and this path IS the root, so exactly one is what the
+ // contract calls for.
+ //
+ // It is nevertheless absent: instrumenting this test measured
+ // `started = 0`. `assert_eq!(started, 1)` is therefore the RIGHT eventual
+ // assertion and would fail today, so it is not made here — a PR tightening
+ // a test should not land a knowingly-red one. Tracked as #6576; tighten
+ // this to `== 1` as part of fixing that, not before.
assert!(started <= 1, "TurnStarted was emitted {started} times");
- assert!(
- completed <= 1,
- "TurnCompleted was emitted {completed} times"
+ assert_eq!(
+ completed, 0,
+ "the deferring seam must emit no TurnCompleted — the caller owns it"
);
}