· ENPT-BR
Grok Build for Alembic · Honest operation

Honesty rails: usage, errors, sessions, auth

Fail closed where the protocol is incomplete or Factory cannot preserve the state atomically.

Primary source
Pinned session management guide

Pinned upstream commit: b189869b7755d2b482969acf6c92da3ecfeffd36

The Simple layer stands alone; open Technical for exact contracts and edge cases.
You will be able to
  • Map complete token fields without double-counting cache reads.
  • Explain why sessionId can be kept while incomplete usage is omitted.
  • Defend fail-closed resume/fork and external credential ownership.
1

The big idea


A useful provider must be honest about what it cannot know. It reports token usage only when Grok says the snapshot is complete. It surfaces documented errors. It refuses resume and fork because a Grok session is a coordinated directory, not one file. It accepts credentials only through the external CLI's normal environment/login boundary.

Think of it like… Think of a sealed evidence bag: if one required item is missing or the seal is broken, label it incomplete instead of guessing the contents. It breaks because some protocol fields can still be used safely while others are omitted.

Headless usage treats `input_tokens` as uncached input and reports cache reads separately. The adapter maps cache creation to zero because that field is not part of the terminal event shape it consumes. If `usage_is_incomplete` is true, it emits sessionId but no usage event.

Grok stores `summary.json`, `updates.jsonl`, `chat_history.jsonl`, plan, rewind points, signals, feedback, compaction checkpoints, and subagent metadata under one session directory. Factory's present capture abstraction is file-shaped, so pretending it can resume would lose coordinated state. `captureSessions:false` and a thrown resume/fork error are correctness features.

Evidence: Pinned session management guide

input_tokenscache_readoutput_tokensincompletesessionId Safe: preserve known metadata and omit the incomplete claim.
Fail closed where the protocol is incomplete or Factory cannot preserve the state atomically.
2

Compare the boundaries


Safe
Safe: preserve known metadata and omit the incomplete claim.
Risky
Risky: report zeros, copy one JSONL, or embed a credential literal.
SurfaceUpstreamAlembicVerdict
Complete usageAll required token fields presentEmit mapped usageREPORT
Incomplete usage`usage_is_incomplete:true`Keep session; omit usageOMIT
Resume/forkUpstream directory can resumeNo atomic directory seam yetFAIL CLOSED

Grok stores `summary.json`, `updates.jsonl`, `chat_history.jsonl`, plan, rewind points, signals, feedback, compaction checkpoints, and subagent metadata under one session directory. Factory's present capture abstraction is file-shaped, so pretending it can resume would lose coordinated state. `captureSessions:false` and a thrown resume/fork error are correctness features.

3

Real code and commands


packages/factory/src/GrokAgentProvider.ts
if (event.usage_is_incomplete !== true) {
  const usage = parseGrokUsage(event.usage);
  if (usage) parsed.push({ type: "usage", usage });
}

if (resumeSession || forkSession) {
  throw new Error("Grok session resume/fork is not supported …");
}
How to reach it
sed -n '20,150p' packages/factory/src/GrokAgentProvider.ts
rg -n "Storage Layout|usage_is_incomplete" /tmp/alembic-grok-build-20260716/crates/codegen/xai-grok-pager/docs/user-guide/{14-headless-mode,17-sessions}.md

Evidence: RESOURCES.md

4

Visual atlas


inputproofinput_tokens
Trace the boundary: input_tokens.
surfaceseamownercache_read
Locate the owner: cache_read.
claimwithout gateevidenceat boundaryvsoutput_tokens
Compare claim and evidence: output_tokens.
learnexecuteverifyincomplete
Read the sequence: incomplete.
complete?yes / nosessionId
Find the decision gate: sessionId.
inputproofsummary.json
Trace the boundary: summary.json.
surfaceseamownerupdates.jsonl
Locate the owner: updates.jsonl.
claimwithout gateevidenceat boundaryvshistory
Compare claim and evidence: history.
learnexecuteverifyrewind
Read the sequence: rewind.
complete?yes / nosignals
Find the decision gate: signals.
inputproofauth.json
Trace the boundary: auth.json.
surfaceseamownerXAI_API_KEY
Locate the owner: XAI_API_KEY.
claimwithout gateevidenceat boundaryvserror
Compare claim and evidence: error.
learnexecuteverifyfail-closed
Read the sequence: fail-closed.
5

Practice and feedback


Predict before revealing

Usage is incomplete but sessionId is present. What can the provider emit?

The sessionId only. Completeness applies to usage, not to the identifier.

Retrieval cards

Retrieval cardsUncached inputClick or press Enter to flip
Uncached input`input_tokens` in headless spend projection.
Retrieval cardsIncomplete usageClick or press Enter to flip
Incomplete usageA signal to omit the usage claim.
Retrieval cardsMulti-file sessionClick or press Enter to flip
Multi-file sessionCoordinated state requiring atomic handling.
Retrieval cardsCredential boundaryClick or press Enter to flip
Credential boundaryLogin or environment owned by the external CLI.
A useful provider must be honest about what it cannot know. It reports token usage only when Grok says the snapshot is complete. It surfaces documented errors. It refuses resume and fork because a Grok session is a coordinated directory, not one file. It accepts credentials only through the external CLI's normal environment/login boundary.
Headless usage treats `input_tokens` as uncached input and reports cache reads separately. The adapter maps cache creation to zero because that field is not part of the terminal event shape it consumes. If `usage_is_incomplete` is true, it emits sessionId but no usage event.

Inject a boundary fault

Choose a fault and inspect the honest provider response.

Verdict

Four-slide summary

Uncached input

`input_tokens` in headless spend projection.

Incomplete usage

A signal to omit the usage claim.

Multi-file session

Coordinated state requiring atomic handling.

Credential boundary

Login or environment owned by the external CLI.

Check your model

Spaced review

Why is `captureSessions` false in phase one?

The session is valuable, but honest capture requires atomic coordinated-directory support.
6

Sources and next move


Ask your teacher to challenge a verdict, replay an event, or review a future unit against the same proof discipline.