codexlaunch

package
v0.30.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: MIT Imports: 15 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 codexlaunch owns the per-launch secret that lets one codex process reach ccdad's local Codex proxy, and the evidence that says the launch is still running.

A launch is TWO files named after the same hash of the same secret:

<root>/codex/launches/<sha256hex>.lock   0 bytes, flocked for the launcher's life
<root>/codex/launches/<sha256hex>.json   {"pin":…,"startedAt":…}

The lock is the liveness test, and AGE IS NEVER A CRITERION. A launcher that dies without cleaning up leaves both files behind; the next lookup takes the lock the dead process was holding, learns from that alone that nobody is there, and removes them. A codex session a user left open for a week keeps its lock and stays valid, which is exactly what an expiry would have broken.

The two lock modes are not interchangeable and the difference is measured rather than stylistic. The LAUNCHER takes an EXCLUSIVE lock and holds it for its child's whole life. Every PROBE takes a SHARED one, so that probes never contend with each other and a refused try-lock can only mean a launcher.

The secret is treated as public within the session: a same-uid process can read it out of the launcher's environment. What it authorises is one route on a loopback listener for one launch's pin or the serving account, and nothing else — no OAuth token is reachable through it.

Index

Constants

View Source
const UnroutedName = "unrouted"

UnroutedName is the tally's basename, beside the launch records.

Variables

This section is empty.

Functions

func Dir

func Dir(root string) string

Dir is where a store's launch records live.

func Lookup

func Lookup(root, bearer string) (Record, LookupResult, error)

Lookup answers for one bearer.

It is safe to call from any number of goroutines at once, including about the same bearer, which is not a courtesy: the proxy calls it per request and the daemon's sweep calls it for every record on every tick.

func NoteUnrouted added in v0.14.0

func NoteUnrouted(root string) error

NoteUnrouted records one unrouted launch.

ONE APPENDED BYTE, never read-modify-write. Two launchers can start in the same second -- two terminals, a shell script, an editor task -- and a read-add-write from each would lose one of the two silently. An O_APPEND write of a single byte is delivered whole, so the count is simply how many newlines the file holds, and nothing has to be parsed.

It is cumulative for the life of the store and is never reset. That is the honest shape: the question a reader has is "has this machine ever run codex outside ccdad", and a counter that cleared itself would answer no for a machine where it happens every morning.

func Reap

func Reap(root string) (int, error)

Reap sweeps the whole directory and reports how many dead records it removed.

It exists because a Lookup only ever reaches the record a live codex quotes: a machine that ran ten codex sessions and lost all ten to a reboot would otherwise keep ten pairs of files forever.

func UnroutedCount added in v0.14.0

func UnroutedCount(root string) int

UnroutedCount is how many unrouted launches the tally records.

A file that is not there is none, which is the ordinary state of a machine whose codex has always been routed. A file that holds something else is a wrong count and never an error: the only consumer is a status document, and refusing to publish one over a byte in a tally would take the whole document down with it.

func UnroutedPath added in v0.14.0

func UnroutedPath(root string) string

UnroutedPath is <root>/codex/unrouted: how many codex sessions a launcher had to start WITHOUT ccdad's proxy in front of them.

A FILE and not a message, because there is nothing to send a message to. The launcher is a short-lived CLI process; the daemon it would tell is the very thing that is not running, which is why the launch was unrouted at all; and by the time a daemon exists the launcher is long gone. The daemon reads this when it publishes, so `ccdad doctor` and `ccdad status` can say that some codex sessions are spending whatever the user's own codex home holds -- an account ccdad neither chose nor can see.

Beside the launch records rather than in a directory of its own, so that `ccdad uninstall` takes it with a name it already recognises.

Types

type Launch

type Launch struct {
	// contains filtered or unexported fields
}

Launch is one live launch, held by the process that started codex.

func Create

func Create(root, pin string) (*Launch, error)

Create mints a secret, takes the lock and writes the record.

The returned Launch must be held for the child's whole life and closed after it exits: releasing the lock is what tells the proxy the launch is over.

func (*Launch) Close

func (l *Launch) Close() error

Close releases the lock and removes both files.

The unlock comes FIRST: Windows refuses to delete a file another handle holds a lock on, so deleting first would strand the lock file there and make every later lookup pay to reap it.

func (*Launch) Secret

func (l *Launch) Secret() string

Secret is the value the launcher puts in the child's environment.

type LookupResult

type LookupResult int

LookupResult is what a bearer turned out to be.

const (
	// Valid: the record exists and its launcher still holds the lock.
	Valid LookupResult = iota
	// Unknown: no record under this bearer's hash.
	Unknown
	// Dead: the record exists and nothing holds the lock, so the launcher is
	// gone. Lookup removes both files before returning it.
	Dead
)

func (LookupResult) String

func (r LookupResult) String() string

String names a result, so a failing test reads as a sentence rather than as an integer.

type Record

type Record struct {
	// Pin is the account uuid this launch is bound to, or "" for a launch that
	// follows the serving pointer.
	Pin string `json:"pin"`
	// StartedAt is when the launcher created the record. It is informational:
	// nothing reads it to decide whether a launch is alive.
	StartedAt time.Time `json:"startedAt"`
}

Record is the document beside the lock.

Jump to

Keyboard shortcuts

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