Skip to Content
Motoko

Continuing a run

A run that ended without an answer, such as one at its turn limit, keeps what it did: its replies and its calls' results. session.continue({ requestId }) starts a run on the session's context as it is, without a new message, so the model carries on from where the run stopped, on the round's results:

const { id } = await instance.createSession({ maxTurns: 3 });
// ... a run ends with `run:end` and `code: "turn_limit"`: the user agrees to let it go on.
await instance.session(id).configure({ maxTurns: 10 });
await instance.session(id).continue({ requestId: crypto.randomUUID() });
  • It is pi-durable's continue. It starts a run only while none is going: a busy session rejects with SessionBusyError (session_busy), and nothing is written. Inputs a failed run left waiting (pi-durable's afterFailedRun: "keep", its default) join the run it starts.
  • A context with nothing to answer, empty or ending in an answer, ends the run at once without a model request: run:end with reason: "error" and code: "nothing_to_answer".
  • It is idempotent on requestId, as submit is: a retry, also at once, returns the first continue's submissionId and starts nothing.
  • The run resolves the scope's models first, as submit does. A child session refuses it with SessionOwnedError.

pi-durable's continue places no entry, so the stream could not tell from history alone where the failed run ended and the continued one began. In the commit that admits a continue whose run takes no waiting input, the runtime writes a motoko.continue entry (nothing the model reads) naming the continue's submission. The stream shows that run as run:start there, then its replies and calls, and its run:end, live and in history alike, and a cursor's run names that entry, as it names the user entry of a run an input started (see Cursors). A run that takes waiting inputs starts at the first of them, as any run does.