codexexec

package
v0.209.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 1, 2026 License: Apache-2.0 Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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.

View Source
const BatchGap = 10 * time.Minute

BatchGap is how long a parent may go without a run before the next one starts a new batch.

View Source
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

func Covers(parent, dir string) bool

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

func PromptHash(prompt string) string

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

type Alive func(pid int32, start int64) bool

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.

func Batches

func Batches(runs []store.CodexRun, now int64, alive Alive) []Batch

Batches groups a parent's runs (oldest first, as store.CodexRunsOf lists them): consecutive runs under one agent from one directory, a new batch whenever BatchGap passes with none at work. Oldest batch first.

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).

func New

func New(db store.Querier, log *slog.Logger) *Linker

New builds a linker over the store.

func (*Linker) Observe

func (l *Linker) Observe(ctx context.Context, run codex.ExecRun)

Observe records what a run's file says: for a run already linked, its newest record and how it ended; for one not yet, it tries to link it. Best effort: a failure costs the link, never the import.

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).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL