Skip to content

A turn that starts while a continuation of its conversation runs interleaves with it #643

Open

Description

@jddunn

A conversation's turn, tool-result continuation and resume each start when the host calls them; the full runtime does not queue them per conversation or per session. A turn that starts while a continuation or a resume of the same conversation runs interleaves with it.

Failing input. A turn pauses for read_file. The host passes its result with handleToolResults() and, before that stream ends, sends the conversation's next message with processRequest().

What happens (read at master after #636):

  • The continuation takes the pause in one synchronous step (ExternalToolResultHandler.takeStreamPause(), or the resume's take after its second check), so the new turn's start (TurnExecutionPipeline.prepareTurn(), the endSavedPause call before Phase 8) finds no pause to end.
  • Phase 8 records the new turn's input while the continuation has not yet recorded its results or its reply, so the input lands among the continuation's messages: the stored history can hold the pause's tool_calls, then the user's message, then the tool results, which providers refuse as a call not followed by its results.
  • Both run on the session's GMI. The shipped GMI refuses a user turn while a continuation keeps it PROCESSING (GMI.ensureReady(), SYS_INVALID_STATE), but only after Phase 8 recorded the turn's input; before the continuation reaches the GMI, the turn runs beside it.

Stated as a limit in docs/TURN_LIFECYCLE.md (opening paragraph) and docs/getting-started/HIGH_LEVEL_API.md (the one-instance paragraph): start a conversation's next turn once the stream of its continuation or resume has ended.

Design question. Two ways to close it:

  1. Queue a session's operations, as agent().session() does with its TurnLock (src/api/runtime/gmiSession.ts). A tool that a continuation runs and that starts a turn on its own conversation would wait on the continuation that waits on it, so a queue needs a rule for nested operations.
  2. Refuse a turn, before Phase 2 acquires the GMI and before Phase 8 records anything, while a continuation or a resume of its conversation runs (SYS_INVALID_STATE), so the host retries once that stream ends.

The integration test a new turn that starts while a resume continues the pause leaves the pause to the resume, so its call is answered once (tests/api/AgentOS.toolResultContinuation.integration.spec.ts) runs this interleaving today and checks only that the call is answered once.

Links

Activity

  1. added
    track
    on Oct 29, 2026
  2. jddunn commented on Nov 23, 2026

    @jddunn
    MemberAuthor

    23 Nov 2026 UTC. The overlap is still covered by the documented host sequencing rule. A runtime fix needs a decision on how turns, continuations and resumes share the session queue, including re-entrant tool calls and when to record input. That has to be decided before changing the ordering.

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

    track

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions