Documentation
¶
Overview ¶
Package codexexec links `codex exec` runs to the Claude Code session that started them and groups them into batches (ADR-121): a Claude Code session, or one of its subagents, driving many Codex workers through a script is drawn as one branch of its subagent tree.
It only reads the process table (procstat): nothing here signals or opens another process (rule 7). Where the table cannot be read, or the run's process is already gone, the link falls back to the parent's own hooks.
Index ¶
Constants ¶
const ( StateRunning = "running" StateDone = "done" // StateRetried is a run that failed and was run again with the same // prompt later in its batch. StateRetried = "retried" StateFailed = "failed" )
Run states (Run.State). Queued is not knowable: a run Caprock has not seen start has no file yet.
const BatchGap = 10 * time.Minute
BatchGap is how long a parent may go without a run before the next one starts a new batch.
const QuietFailed = 15 * time.Minute
QuietFailed is how long a run with no process to check may go without a record, while its file says nothing of an end, before it reads as failed: the subagents' SubagentQuietMax.
Variables ¶
This section is empty.
Functions ¶
func Covers ¶
Covers reports whether dir is parent or a directory under it, as written or once symbolic links are resolved: macOS's /var is /private/var, and one agent may record a directory the one way and another the other. Case is folded on Windows, where paths are not case-sensitive.
func PromptHash ¶
PromptHash is the first 16 hex digits of the SHA-256 of a run's prompt, "" for none: what tells a retry (codex_exec_runs.prompt_hash).
Types ¶
type Alive ¶
Alive reports whether the process pid that started at start (unix ms) is still that process.
type Batch ¶
type Batch struct {
// ID is its first run's session id.
ID string `json:"id"`
// AgentID is the subagent that started it; absent for the main thread.
AgentID string `json:"agent_id,omitempty"`
Cwd string `json:"cwd"`
StartedAt int64 `json:"started_at"`
// EndedAt is its last run's end; absent while any runs.
EndedAt int64 `json:"ended_at,omitempty"`
Runs []Run `json:"runs"`
Count int `json:"count"`
Done int `json:"done"`
Running int `json:"running"`
Failed int `json:"failed"`
Retried int `json:"retried"`
// Parallel is the most runs at work at once: "4 in parallel".
Parallel int `json:"parallel"`
Tokens int64 `json:"tokens"`
// CostUSD is every run's together; absent when any is unknown.
CostUSD *float64 `json:"cost_usd,omitempty"`
}
Batch is a parent's consecutive runs from one directory, under one agent.
type Linker ¶
type Linker struct {
// Procs reads the process table; procstat.Read, replaced in tests.
Procs func(ctx context.Context) (*procstat.Table, error)
// Now is the clock, replaced in tests.
Now func() time.Time
// contains filtered or unexported fields
}
Linker links runs as the Codex importer reads them (codex.Ingester.OnExec).
type Run ¶
type Run struct {
SessionID string `json:"session_id"`
// StartedAt and EndedAt are unix ms; EndedAt is absent while it runs.
StartedAt int64 `json:"started_at"`
EndedAt int64 `json:"ended_at,omitempty"`
State string `json:"state"`
Tokens int64 `json:"tokens"`
// CostUSD is at list price from the pricing table; absent when its
// model is unknown and it used tokens: never a zero standing in.
CostUSD *float64 `json:"cost_usd,omitempty"`
// Lane is the worker track it ran on, from 0: runs packed onto the
// fewest tracks that never overlap.
Lane int `json:"lane"`
LinkedBy string `json:"linked_by"`
}
Run is one run in a batch (GET /v1/sessions/{id}/codex-runs).