When the Terminal Disappears: Sessions, Compaction, and Recovery

Prime Agent's continuity design addresses a practical failure in long-running repository work: the person can close the terminal, the context can outgrow the model's window, or a worker can need to reconnect after a process failure while the task is still unfinished. The focus here is what Prime Agent preserves at each transition and what it cannot promise to preserve. That distinction lets a reader use sessions, compaction, and recovery deliberately instead of treating a resumed conversation as proof that nothing was lost.

The terminal is a client, not the owner of the work

Imagine that a parent session has admitted several focused repository reviews. One child is inspecting authentication call sites while another is checking regression coverage. The user has to leave before the findings arrive. In a terminal-first tool, closing the interface often feels equivalent to stopping the task. In Prime Agent's normal interactive path, it is a different event: the client detaches, while a resident worker continues to own the root session, its queue, its Python kernel, its schedules, its child agents, and its persisted state.

The distinction comes from the process topology. A local supervisor manages the connection between clients and workers. The interactive terminal renders messages and accepts input, but it does not own the agent loop. A worker owns one root session tree and the descendants below it. When the terminal closes, the worker is still the execution owner. The user can later inspect active agents and attach to the relevant one, returning to the same session rather than asking a new model to reconstruct the task from a short description.

That arrangement changes what “background work” means. The worker is not merely a shell command left running after the window disappears. It retains the session queue, the Python control environment, child lifecycles, and feature-specific artifacts. A later prompt can therefore arrive through the same execution path as the original user message. Heartbeats, schedules, goals, autonomous continuations, and messages from another agent do not need a separate kind of agent; they enter the session's queue and are handled by the same owner.

The durable record has two parts. Prime Agent stores the conversation as a JSONL session file, whose entries form a tree through identifiers and parent relationships. Feature-specific state is stored in a session artifact directory. That directory can hold the information needed for the kernel, schedules, harness state, or retained children when those features are used. The exact artifacts depend on the features involved, but the architectural point is stable: the session and its supporting state are not held only in the terminal process.

This ownership model also prevents a class of corruption. Before opening a persisted session, a worker acquires a process-safe lease keyed to the canonical transcript path. If another worker or one-shot client already owns that session, the second open is rejected rather than allowing two writers to append competing histories.