These invariants MUST hold for all backend operations.
Violation of any invariant is a critical bug.
Enforcement categories:
- [REPLAY] – Enforced during replay of events
- [EXEC] – Enforced at execution / event-emission time (replay may not be able to verify)
- [EXEC] RunID uniqueness is enforced at creation time
- No two runs share the same RunID
- [EXEC] State transitions are enforced during execution
- Valid transitions:
pending → running → completed, orpending → running → failed
- State transitions are monotonic (no going backwards)
- [REPLAY] Enforced during replay
run.startedmust be the first event- No events may exist before
run.started - Duplicate
run.startedevents cause replay failure
- [REPLAY] Enforced during replay
- Termination event must have the highest
seqvalue - No events may exist after termination
- Exactly one termination event must exist
- Duplicate termination events cause replay failure
- [REPLAY] Enforced during replay
- Phase order:
planner → executor → reviewer - Steps may stop early on failure (see invariant #7)
- No steps may be out of order
- [EXEC] Path validation enforced at execution time
- All file operations are restricted to
workspace_rootor subdirectories - No file access outside
workspace_rootis permitted
- [EXEC] Enforced during execution
- If planner fails, executor and reviewer do not run
- If executor fails, reviewer does not run
- [EXEC] Uniqueness enforced at creation time
- [REPLAY] Enforced during replay
- No duplicate
step.startedevents for the samestep_id - Duplicate start events cause replay failure
- Start
seqis tracked for error reporting
- [REPLAY] Enforced during replay
- No subsequent events may reference the same
step_id - Incomplete steps cause replay failure
- [REPLAY] Enforced during replay
Step.RunIDmust match a validRunID
- [EXEC] Phase is immutable for a step
- Valid phases:
planner,executor,reviewer
- [EXEC] Enforced before emitting
step.started - Planner phase → planner agent
- Executor phase → executor agent
- Reviewer phase → reviewer agent
- [EXEC] Uniqueness enforced at creation time
- [REPLAY] Enforced during replay
- No duplicate
tool.calledevents - Duplicate start events cause replay failure
- Start
seqis tracked for error reporting
- [REPLAY] Enforced during replay
- No subsequent events may reference the same
tool_call_id - Incomplete tool calls cause replay failure
- [REPLAY] Enforced during replay
ToolCall.StepIDmust match a validStepID
- [EXEC] Enforced before emitting
tool.called - Tool must exist in the registry
- Tool must be whitelisted for the step's agent
- [EXEC] Enforced before emitting
tool.called Agent.PermissionTier ≥ Tool.PermissionTier- Permission check happens before execution
- [EXEC] Enforced before emitting
tool.called - Invalid input →
tool.failed (INVALID_INPUT)
- [EXEC] Enforced before emitting
tool.returned - Invalid output →
tool.failed (INVALID_OUTPUT)
- [EXEC] Enforced when calculating duration
- [EXEC] Uniqueness enforced at creation time
- [REPLAY] Enforced during replay
- No duplicate start events
- Start
seqis tracked for error reporting
- [REPLAY] Enforced during replay
- No subsequent events may reference the same
llm_call_id - Incomplete calls cause replay failure
- [REPLAY] Enforced during replay
LLMCall.StepIDmust match a validStepID
- [EXEC] Uniqueness enforced at creation time
- [EXEC] Enforced at creation time
- [REPLAY] Enforced during replay
- [REPLAY] Enforced during replay
- [EXEC]
file,diff,text - Type is immutable
- [EXEC] Calculated at creation time
- [EXEC] Calculated at creation time
- [EXEC] Enforced at creation time
- Absolute and within
workspace_root - No path traversal or escapes
- Path optional for
diffandtext
- [EXEC] Events are never modified or deleted
- Written in
seqorder
- [EXEC] Enforced at creation time
- [REPLAY] Valid types:
run.started,run.finished,run.failedstep.started,step.finished,step.failedllm.requested,llm.respondedtool.called,tool.returned,tool.failedartifact.created
- [REPLAY] Strictly increasing per run
- No duplicate
seqvalues
- [REPLAY] Invalid payloads are critical errors
- [EXEC] One JSON object per line
- Newline-terminated
- [REPLAY] Guaranteed by replay engine
- Entire RunView reconstructed from events
- [EXEC] Enforced by file tools
- [EXEC] Relative paths resolved against
workspace_root - Path containment enforced
- [EXEC] No
execute_shelltool (yet) - Only allowlisted wrappers:
run_testsrun_buildrun_lint
- [EXEC] Configuration is immutable
- Agents identified by ID
- [EXEC] Enforced before tool execution
- [EXEC] Permission tiers are immutable
- [EXEC]
- Planner (READ-only)
- Executor (WRITE / EXECUTE)
- Reviewer (READ-only)
- [EXEC] Namespaced by RunID
- No cross-run access
- [EXEC] Lost on restart
- Not persisted (yet)
- Event log is the source of truth
- [EXEC] Values are JSON-serializable
- [REPLAY] Based only on events sorted by
seq
- [REPLAY] Errors include:
seq- event type
- short reason
- [REPLAY] Equivalent to the original run state