A companion's session and its parent
What changes
A companion's session names its parent. A first
companion__spawnAgentstarts a child only on a session whoseparentSessionIdis the spawning session. Any other session at that id is left as it is, and the call is answerednot_spawned(child_entry_failed), on every runtime. ItserrorDetail.codeis'state_child_session_taken', or on a Durable Object'state_session_parent_mismatch'when that session is idle.A session keeps the parent it was created with on runtime-js and Temporal, and on Temporal its root. On runtime-js a direct turn on a child's session (an
execute()that names no parent) is the root of its own calls, as before.Temporal:
execute(agent, input, { parentSessionId })onto a session that is not that parent's is refusedstate_child_session_taken, non-retryable, before its run starts.runtime-js: a remote child (its parent comes from its
binding) is the root of its own calls, as on the other runtimes: it stores norootSessionId, and its own sub-agents'rootSessionIdis that child's session.core 19.1.0: a companion ref reads its own child: its status, output and notice come from a session whose
parentSessionIdis the ref's parent, and a re-spawn starts fresh over it. A re-spawn over any other session is answerednot_spawned, as above.
What to do
Companions whose session stores no parent: the parent reads a companion by the parent its session stores, and the same name is not started again over that session; on a Durable Object it is not re-consulted either. Finish them before upgrading to core 19.1.0, or spawn the companion under another name. On runtime-js before 39.0.0, a direct
execute()on a companion's session (one that names no parent) cleared the stored parent.An app that creates a companion's session itself before its first spawn: pass
parentSessionId(the spawning session's id) tocreateSession, or let the spawn create it. The spawn keeps the session's messages. Its custom state is kept on Temporal, DBOS and CF Workflows; on runtime-js a companion's first consult starts from itsstateSchema's defaults, as before. A Durable Object companion's session is always created by its parent's start, so there is nothing to pre-create.An app that reads a remote child's
rootSessionIdon runtime-js: read itsbinding.parentSessionId.Nothing otherwise.