THE INCIDENT · CHAPTER 01
It is 4:47 p.m. on a Friday. Mira, a platform engineer, asks Grok Build to find a failing Rust test, fix it, and prove the fix. The terminal answers that the work is complete. But the test is still red. One sentence from a model and one changed repository are clearly not the same thing.
The question: What has to exist between a useful model answer and a trustworthy software change?
Start from first principles
Think of the model as a brilliant engineer speaking through a radio. The harness is the teammate holding the repository, terminal, notebook, safety checklist, and test results. Intelligence travels over the radio; work happens through the teammate.
A model can propose cargo test. It cannot place the repository in the correct directory, authorize a process, preserve its output, edit a file, rerun the check, and prove that the requested behavior changed. Those are harness and environment responsibilities.
The first Harness Engineering series established Agent = Model + Harness. This series continues from that definition by following a large implementation across real crate boundaries. We will use the source to distinguish a client feature from a runtime contract and a runtime contract from an operator-supplied guarantee.
The snapshot is main at c68e39f60462f28d9be5e683d9cbe2c57b1a5027, researched July 16, 2026. The public history contains one visible publication commit, so this is a precise implementation study rather than a claim about the system's private development history.
Build the smallest useful mental model
Treat the command line as a window into a control loop. User input becomes session state. The runtime assembles messages and effective tool schemas. A sampler returns text or tool calls. Policy decides whether those calls may execute. The workspace causes side effects and returns observations. The loop continues until it reaches a stop condition.
The multiplication in the series equation is deliberately strict. A capable model inside a weak harness loses context or misreads failures. A strong harness in a broken environment cannot compile the code. Both can still produce confident prose when verification is missing. Each factor can collapse the outcome.
That framing also keeps safety claims honest. Permission prompts, OS sandboxing, plan review, CI branch protection, and semantic tests are different controls. Calling all of them 'guardrails' hides which threat each one addresses.
Fig 1.1 — The terminal client drives a feedback system; it is not the whole agent.
Now open the hood
Only after the idea is clear does Mira open the source. She ignores most of the workspace and follows the few boundaries that must exist for this part of the story to work.
1. The next clue — Composition starts in pager-bin
Mira now needs one small mechanism: The binary must turn CLI intent into one of several client or service modes without duplicating the underlying agent semantics.
She follows that responsibility into the repository. xai-grok-pager-bin/src/main.rs imports the pager and shell entry points; run_agent_command dispatches agent modes while main composes the process. The important point is not the Rust syntax. It is ownership: this is where the system decides what crosses the boundary.
Then she tests the unhappy path: If mode-specific configuration diverges here, identical prompts can reach different runtime capabilities; compare resolved fields rather than assuming interface parity. If the model, operator, and saved session do not receive the same honest outcome, the mechanism is not yet trustworthy.
Source:crates/codegen/xai-grok-pager-bin/src/main.rs,main,run_agent_command. Verified against Grok Buildc68e39f60462f28d9be5e683d9cbe2c57b1a5027.
2. The next clue — Headless is an ACP client
Mira now needs one small mechanism: A one-shot command still needs initialization, authentication, session materialization, prompt streaming, cancellation, and result projection.
She follows that responsibility into the repository. headless.rs::run_single_turn starts the shell in-process and drives initialize, authenticate, session, and prompt requests before emitting plain or structured output. The important point is not the Rust syntax. It is ownership: this is where the system decides what crosses the boundary.
Then she tests the unhappy path: A prompt that never reaches the model omits spend fields; an interrupted run must preserve its session identifier if a later job expects resume. If the model, operator, and saved session do not receive the same honest outcome, the mechanism is not yet trustworthy.
Source:crates/codegen/xai-grok-pager/src/headless.rs, module documentation andrun_single_turn. Verified against Grok Buildc68e39f60462f28d9be5e683d9cbe2c57b1a5027.
3. The next clue — The shell owns the turn
Mira now needs one small mechanism: Prompt resolution, chat state, model rounds, tool observations, interjections, compaction, and stopping must remain one coherent state machine.
She follows that responsibility into the repository. handle_prompt begins prompt state and persistence; process_conversation_turn builds requests, samples, executes calls, appends results, and repeats. The important point is not the Rust syntax. It is ownership: this is where the system decides what crosses the boundary.
Then she tests the unhappy path: A no-tool response can end an ordinary turn even when the engineering acceptance condition is incomplete; inspect evidence, not only EndTurn. If the model, operator, and saved session do not receive the same honest outcome, the mechanism is not yet trustworthy.
Source:crates/codegen/xai-grok-shell/src/session/acp_session_impl/turn.rs. Verified against Grok Buildc68e39f60462f28d9be5e683d9cbe2c57b1a5027.
4. The next clue — Tools are two contracts
Mira now needs one small mechanism: The model needs a name, description, and JSON schema; the environment needs executable code with session-scoped dependencies.
She follows that responsibility into the repository. ToolDefinition carries the model-facing function contract, while FinalizedToolset and SessionContext connect it to terminal, filesystem, cwd, memory, and other services. The important point is not the Rust syntax. It is ownership: this is where the system decides what crosses the boundary.
Then she tests the unhappy path: A valid-looking model call can still be denied, malformed, unavailable in the current toolset, or fail during execution; each result must return to chat state. If the model, operator, and saved session do not receive the same honest outcome, the mechanism is not yet trustworthy.
Source:xai-grok-tools/src/types/definition.rsandregistry/types.rs. Verified against Grok Buildc68e39f60462f28d9be5e683d9cbe2c57b1a5027.
5. The next clue — Workspace is the side-effect boundary
Mira now needs one small mechanism: The turn loop should request an operation without assuming whether it executes in the current process or behind a workspace service.
She follows that responsibility into the repository. WorkspaceOps has local and proxy variants; bind_local_session installs a session toolset and call_tool dispatches locally or through the hub. The important point is not the Rust syntax. It is ownership: this is where the system decides what crosses the boundary.
Then she tests the unhappy path: Path, environment, VCS, and filesystem assumptions can differ across placements; logs must identify the effective workspace rather than only the client cwd. If the model, operator, and saved session do not receive the same honest outcome, the mechanism is not yet trustworthy.
Source:crates/codegen/xai-grok-workspace/src/workspace_ops.rs. Verified against Grok Buildc68e39f60462f28d9be5e683d9cbe2c57b1a5027.
6. The next clue — Policy precedes side effects
Mira now needs one small mechanism: A proposed action must pass deterministic hooks, rule evaluation, remembered decisions, built-in approvals, and the active prompt policy before implementation dispatch.
She follows that responsibility into the repository. prepare_tool_call performs normalization, plan-mode checks, PreToolUse, permission requests, and execution. The guide documents deny > ask > allow. The important point is not the Rust syntax. It is ownership: this is where the system decides what crosses the boundary.
Then she tests the unhappy path: Broad approval mode is not a sandbox, hook failures are fail-open unless they emit explicit denial, and headless cannot pause indefinitely for a person. If the model, operator, and saved session do not receive the same honest outcome, the mechanism is not yet trustworthy.
Source:xai-grok-shell/.../tool_calls.rsand user guide22-permissions-and-safety.md. Verified against Grok Buildc68e39f60462f28d9be5e683d9cbe2c57b1a5027.
7. The next clue — Sessions make the loop durable
Mira now needs one small mechanism: A prompt needs append-oriented conversation state, file-state tracking, and an end-of-turn flush if interruption and rewind are first-class behavior.
She follows that responsibility into the repository. The session guide lists update/chat JSONL, plan, rewind, signals, feedback, compaction, and subagent artifacts; RewindPoint stores prompt-indexed before/after file state. The important point is not the Rust syntax. It is ownership: this is where the system decides what crosses the boundary.
Then she tests the unhappy path: Local file rewind does not undo remote API calls, deployed resources, databases, or messages; external side effects require their own compensating workflow. If the model, operator, and saved session do not receive the same honest outcome, the mechanism is not yet trustworthy.
Source: User guide17-sessions.mdandxai-grok-workspace/src/session/file_state.rs. Verified against Grok Buildc68e39f60462f28d9be5e683d9cbe2c57b1a5027.
8. The next clue — Completion is not correctness
Mira now needs one small mechanism: The runtime needs a protocol stop while the engineering workflow needs an objective acceptance condition.
She follows that responsibility into the repository. The no-tool branch normally moves to EndTurn; required completion-tool recovery only applies when an agent definition declares completion_requirement. The important point is not the Rust syntax. It is ownership: this is where the system decides what crosses the boundary.
Then she tests the unhappy path: Treating a final response as proof allows skipped tests, wrong test selection, or environment-specific failures to pass through CI as success. If the model, operator, and saved session do not receive the same honest outcome, the mechanism is not yet trustworthy.
Source:turn.rs::process_conversation_turn_with_recoveryandprocess_conversation_turn. Verified against Grok Buildc68e39f60462f28d9be5e683d9cbe2c57b1a5027.
Mira runs the experiment — repair one failing Rust test
Reading source gives her a hypothesis. A small experiment tells her whether that hypothesis survives contact with a real workspace. Follow a representative request without giving any component magical authority: 'Find the failing test, fix the implementation, run the relevant tests, and summarize the change.'
- The client sends the prompt into a new or resumed ACP session.
- The shell records the prompt index and begins file-state tracking.
- Rules, skills, history, memory reminders, and effective tool schemas form the request.
- The model requests search, read, or a test command; policy authorizes or denies it.
- Workspace execution returns compiler/test output as a structured observation.
- The model proposes an edit; the same authorization path applies before mutation.
- A second command supplies verification evidence rather than a prose assertion.
- The runtime flushes the session and emits the final response plus session metadata.
grok -p "Find the failing test, fix the implementation, run the relevant tests, and summarize the change." \ --output-format streaming-json
What she learns. The command is documented, but the outcome still depends on repository state, model choice, tool exposure, permissions, and available dependencies. Structured output makes the loop observable; it does not create a correctness proof.
That last check matters. Grok Build can expose a mechanism and report an observation; the repository, operating system, CI platform, and reviewer decide whether those observations prove the actual task succeeded.
The whiteboard test
Before Mira explains the chapter to her team, she reduces it to three questions: what owns the decision, what evidence comes back, and what changes when the mechanism fails?
| Review question | Source-backed answer | Operational consequence |
|---|---|---|
| Where does the model end? | At generated text/tool intent and streamed sampling responses. | Do not attribute filesystem or process behavior to the model. |
| Where does authority live? | Hooks, permission policy, tool exposure, workspace capabilities, and OS policy. | Review effective configuration, not the prompt alone. |
| What proves completion? | No universal proof; the turn has a protocol stop and the workflow supplies acceptance checks. | CI and reviewers must validate evidence. |
| What survives interruption? | Session artifacts and tracked file state within documented boundaries. | External mutations need separate provenance and rollback. |
This is not a feature scorecard. A mechanism can work exactly as implemented and still be the wrong control for a particular threat. Defaults also change, so recheck the pinned source path before copying configuration into production.
Signals Mira keeps
- Session and request identifiers across every client boundary.
- Effective tool definitions, policy decision, normalized arguments, duration, and result status.
- Workspace identity, cwd, environment fingerprint, changed paths, and command exit codes.
- Verification command, test selection, diff summary, and whether cost/usage is complete.
Together, those signals tell a complete story: the model proposed an action, the harness admitted and routed it, the environment performed something, and a verifier measured the result.
Limits and uncertainty
The public repository is unusually detailed, but it is not the complete deployed product. The snapshot has one visible public commit, so it cannot support a rich historical explanation of why every boundary evolved. Hosted xAI model serving, account systems, and production topology remain outside this study. Where code and guide differ, this series gives the pinned implementation priority and marks documentation-only behavior instead of silently merging versions.
FAQ
Is Grok Build open source evidence of the Grok model internals?
No. It exposes the coding-agent harness and client-side contracts. The hosted model implementation and full serving topology are outside this public snapshot.
Does EndTurn mean the task is correct?
No. It means the protocol turn ended. Correctness comes from task-specific verification such as tests, static checks, diff review, and human acceptance.
Is the TUI required?
No. Headless mode and ACP clients can drive the runtime. The TUI remains important because it gives an interactive operator a rich approval and observability surface.
Does a sandbox make every approved command safe?
No. It restricts capabilities. A command can remain logically destructive inside an allowed workspace, and network restrictions have documented platform and in-process boundaries.
Why compare Pi and Hermes later?
They expose different harness choices: a deliberately small programmable core, a broad persistent orchestration system, and Grok Build's integrated coding workspace. The comparison is architectural, not a popularity ranking.
What changed for Mira
By the end of the evening, Mira stops asking whether the model is smart enough. She starts tracing the complete system that turns an intention into evidence.
Next: To trace that system, she first needs a map of the Rust workspace.
Key takeaways
- The terminal is a client; the agent is the complete feedback system.
- Tool intent, authorization, execution, observation, and verification belong to different contracts.
- Workspace and session design determine where side effects and recovery live.
- A protocol stop is not an engineering proof.
- Every safety claim must name the layer and threat it addresses.
References & source notes
- Pinned Grok Build repository — default branch snapshot researched July 16, 2026.
- Grok Build README — first-party overview and source-build entry points.
- Harness Engineering series — the conceptual foundation this source study continues.
Freshness boundary. Grok Build claims in this article are pinned to c68e39f60462f28d9be5e683d9cbe2c57b1a5027. Pi comparison claims, where present, are pinned to 97f9978fa66685f78d2da19ae22e20c46d125f74; Hermes claims are pinned to c9c9bb33fcc6ab479846a1c496a6e9efe2c1c7d4. Recheck paths, symbols, commands, and defaults if those branches advance.