| title | Session lifecycle | ||
|---|---|---|---|
| summary | How a Coven session moves through created, running, completed, failed, orphaned, archived, and summoned states from coven run to replay. | ||
| read_when |
|
||
| description | How a Coven session moves through created, running, completed, failed, orphaned, archived, and summoned states from coven run to replay. |
This document explains what happens from coven run through completion, replay, archive, summon, and deletion.
The current store records session status as a string. Common states include:
created- the session record exists before live execution begins.running- the harness process is active under daemon supervision.completed- the harness exited successfully.failed- setup or launch failed before normal completion.orphaned- a previous daemon stopped while a session was still marked running.
Archive state is stored separately as archived_at. A completed or failed session can be hidden from the active list without changing its final status.
stateDiagram-v2
[*] --> created: coven run / POST /sessions
created --> running: PTY spawn succeeds
created --> failed: validation fails / PTY spawn errors
running --> completed: harness exits 0
running --> failed: harness exits non-zero
running --> orphaned: daemon stops while running
completed --> archived: coven archive
failed --> archived: coven archive
orphaned --> archived: coven archive
archived --> completed: coven summon (was completed)
archived --> failed: coven summon (was failed)
archived --> orphaned: coven summon (was orphaned)
completed --> [*]: coven sacrifice --yes
failed --> [*]: coven sacrifice --yes
orphaned --> [*]: coven sacrifice --yes
archived --> [*]: coven sacrifice --yes
The diagram above is normative for the v0 store. running sessions cannot be archived or sacrificed directly — kill them or wait for exit first. created → running is the only transition that requires PTY spawn; every other transition is a store-only state change managed by the Rust daemon.
The normal launch flow:
- User or client sends a task through the CLI or local API.
- Coven resolves the project root.
- Coven canonicalizes the project root and working directory.
- Coven rejects outside-root working directories.
- Coven verifies the harness id is supported.
- Coven creates a session record in SQLite.
- The daemon spawns the harness in a PTY using argv APIs.
- Output and exit data are written as events.
- Session status and exit code are updated.
The Rust layer performs the authority checks even when a TypeScript client has already validated the request for UX.
sequenceDiagram
participant Client as Client (CLI / TUI / comux / plugin)
participant Daemon as Coven daemon
participant Store as SQLite store
participant PTY as Harness PTY
Client->>Daemon: POST /api/v1/sessions { projectRoot, cwd, harness, prompt }
Daemon->>Daemon: canonicalize projectRoot
alt projectRoot invalid
Daemon-->>Client: 400 invalid_request
end
Daemon->>Daemon: canonicalize cwd inside projectRoot
alt cwd outside root
Daemon-->>Client: 400 invalid_request (cwd outside project root)
end
Daemon->>Daemon: lookup harness in adapter table
alt harness unknown
Daemon-->>Client: 400 invalid_request (with install hint)
end
Daemon->>Store: insert session (status=created)
Daemon->>PTY: spawn argv (prefix args + prompt)
alt spawn / initial-write fails
Daemon->>Store: update status=failed
Daemon-->>Client: 500 launch_failed (details.sessionId set)
else PTY spawn ok
Daemon->>Store: update status=running
Daemon-->>Client: 200 SessionRecord
PTY-->>Store: append output / exit events
PTY->>Daemon: process exits with code
Daemon->>Store: update status=completed|failed, exit_code
end
coven run ... --detach creates the session record without launching the harness. This is useful for testing and development flows that need a ledger record without starting an external process.
Detached records should not be presented as completed agent work.
coven attach <session-id> replays known event output and follows live output when the session is still active.
For a completed session, attach acts like a log viewer. For a running session, attach also forwards input to the live daemon session.
coven sessions chooses output mode based on context:
- In an interactive terminal, it opens the session browser.
- When piped or run with
--plain, it prints table output. --jsonprints machine-readable session records for local clients.--allincludes archived sessions.--manageforces the browser.
The browser offers contextual actions so users do not have to memorize session ids.
Archive hides a non-running session from the default active list while preserving the session record and event log.
coven archive <session-id>Use archive for old work that should remain inspectable.
Summon restores an archived session to the active list and then replays/follows it:
coven summon <session-id>Summon does not re-run the original harness prompt. It changes archive state and opens the existing record.
Sacrifice permanently deletes a non-running session and cascades deletion to its events:
coven sacrifice <session-id> --yesThe command refuses live sessions. The interactive browser asks the user to type sacrifice before deletion.
Use sacrifice only when the session and its logs should be removed from the local ledger.
If the daemon starts and finds sessions that were marked running from a previous daemon lifetime, those sessions are marked orphaned.
An orphaned session means Coven no longer owns a live process for that record. The event log may still be useful, but live input and kill operations should fail.
Events are append-only records in SQLite. This gives clients a stable replay source even when the original PTY process has exited.
Do not intentionally write secrets, environment dumps, private URLs, or token-bearing command output into events. Coven cannot guarantee that harness output is secret-free, so users should avoid running untrusted prompts in sensitive repositories.
coven sessions search <query>runs a SQLite FTS5 query overevents.payload_json. Supports the full FTS5 query syntax (phoenix OR rises,"exact phrase",phoe*). Output is a flat list of hits ordered most-recent-first; pass--jsonto get the raw SearchHit array for client tools.coven run <harness> --continueresumes the most recently created, non-archived session whoseproject_rootmatches the current directory. The harness is launched withConversationHint::Resumeso codex/claude pick up the prior turn's context.coven run <harness> --continue <ID>resumes by explicit session id.coven run <harness> --labels foo,bar --visibility workspace --archive "task"tags and archives a one-shot run in a single command.--labelsand--visibilityare creation-time only (ignored when resuming). Valid visibility values:private(default),workspace,shared.--detachand--continueare mutually exclusive — resuming-but-not-running is incoherent.