Skip to main content

Module session_tree

Module session_tree 

Source
Expand description

The session tree: every session running on this machine under the session that started it, read from recorded facts and saying which ones a parent was inferred from (harness.v1.sessions.tree, supercode sessions tree).

A session’s starter is, first, what was recorded: the machine daemon’s launch journal (launches.jsonl, the by of the launch that first started the session, joined by its native session or its pane), or Codex’s own parent_thread_id on a subagent thread. A resume (supercode open <id>) is not a start: the session keeps its first starter and the resume is shown as resumed_by. A session started outside the daemon (a codex exec or a claude -p a session’s shell ran) has no launch record, and its starter is inferred from its process: the nearest process above it that is another running session, or, when its parents have exited (nohup … &), the session its environment names (CLAUDE_CODE_SESSION_ID, CODEX_THREAD_ID, SUPERCODE_TEAMS_PANE, which each harness and the daemon set for the processes they start). Every parent says which of these it came from; a session none of them names is a root, started outside any session.

record keeps the tree in <teams home>/sessions-tree.jsonl when its shape changes (with a heartbeat while it does not), so recorded_tree answers what was running, and under whom, at a past moment — after a reboot too. Reading only: nothing here acts on a session.

Functions§

journal_path
The tree’s journal.
live_tree
The running sessions on this machine as a tree. sessions is flat, each with its parent (an address, or null for a root) and how that parent is known; parents_elsewhere names each parent that is not running here (on another machine, or ended), so every parent resolves to a row.
record
Append tree to the journal when its shape differs from the last recorded one, else a heartbeat when the last record is [HEARTBEAT_MS] old. Returns what was written: "tree", "heartbeat" or "nothing".
recorded_tree
The tree as recorded at at_ms: the last recorded tree at or before it, when it was recorded, the last moment the record confirms it unchanged (a heartbeat or the next record), and the next change after it. None when nothing was recorded by then.