- Category: B. Software Architecture
- English term: Exit Code Contract
- Related: Pipes and Filters Pattern (Pipeline Architecture) · Deterministic Verification · Work Queue (Producer-Consumer Pattern) · Fallback Chain (Cascading Fallback) · Retry Limits and Circuit Breakers
General Meaning
In Unix-like operating systems, every terminating process returns an integer exit status (0 to 255) to its parent process or shell.
While many scripts treat 0 as success and anything non-zero as a generic failure, automated pipelines and agent harnesses define an explicit Exit Code Contract mapping specific integer codes to exact failure modes and required next actions. This allows callers to route tasks deterministically without parsing stdout/stderr log strings with brittle regular expressions.
Why It Matters
- Eliminating fragile log parsing: Parsing stdout or stderr text breaks easily when wording changes, translations are added, or debug output appears.
- Fast, deterministic branching: Queue managers and dispatchers can inspect a single integer (
0,1,2,42,75) to decide immediately whether to publish, send back for fixes, abort on corrupt input, or re-queue to another node. - Cooperative checkpointing and resumption: When a job approaches its time limit, it can save state cleanly and exit with a 'more work remaining' code instead of being killed mid-write.
How the Site Factory Uses It
The Site Factory enforces a unified exit code contract across engine/ scripts, resident workers, and watchdog runners (engine/common.py, ops/watchdog/run_job.py, ops/watchdog/studio2_runner.py): 0 (EXIT_OK) means passing/complete, proceeding to the next stage or publication; 1 (EXIT_FINDINGS / EXIT_FAIL) means review findings or inspection failure, routing back for fixes or dropping failing items; 2 (EXIT_BROKEN) means corrupt input (such as malformed JSON or missing required files) that should fail immediately without retry; 42 (EXIT_UNAVAILABLE) means the runner or remote machine (such as Studio 2) is temporarily unreachable, triggering fallback to another runner; and 75 (EXIT_MORE / QUOTA_CODES, from Unix EX_TEMPFAIL) means time slice expired or quota reached.
For example, engine/extract.py checks its --until deadline before starting a new item and exits cleanly with 75 if time is up, telling mini-queue or patrol to resume the remaining work on the next pass without recording an error.
Caveats & Operational Rules
- Do not return
exit(1)for everything: Collapsing corrupt input, transient network errors, and review findings into1prevents the caller from choosing the right fallback or retry policy. - Keep log output consistent with the exit code: Never print
ERRORwhile exiting0, or emit noisy warnings tostderron a clean run that trick parent wrappers into flagging a failure. - Respect the 0–255 unsigned 8-bit range: Returning negative numbers or values ≥ 256 wraps modulo 256 (
x % 256) on Unix, silently corrupting the contract.
Related Terms
- Pipes and Filters Pattern (Pipeline Architecture)
- Deterministic Verification
- Work Queue (Producer-Consumer Pattern)
- Fallback Chain (Cascading Fallback)
- Retry Limits and Circuit Breakers
References
- Book: W. Richard Stevens & Stephen A. Rago, *Advanced Programming in the UNIX Environment*, Chapter 8 (Process Control); Eric S. Raymond, *The Art of Unix Programming*
Verified: 2026-11-08