Creating a session again
createSession({ requestId }) is idempotent, as submit is: a retry with the same request ID returns
the session the first call made, so a caller whose reply was lost (a dropped connection, a forwarded
call tried again) never makes a second one. The ID is stored on the session's entry in the sessions
record, in the commit that creates the session, and looked up in that same commit, so it holds
across calls made at once, an idle close, a restart and another process on the same storage, and no
crash can leave a session without it.
const requestId = crypto.randomUUID();
const first = await instance.createSession({ requestId, tools: ["read_note"] });
// The same request, sent again: the same session, as it was made.
const again = await instance.createSession({ requestId });
// again.id === first.id- A retry gets the first session as it is, whatever its other options say, as a
submitretry gets the first submission whatever its text. - The ID is remembered while its session is listed. Deleting the session forgets it, so the record grows with the sessions alone, and a later call with that ID makes a new session; the deleted one stays gone.
- Without a
requestId, every call makes a session.