Architecture

The gateway

How a task leaves GAOS and comes back. GAOS does not run a model; it asks ai-manager to run one turn inside the product's workspace, and ai-manager hands the turn to ai-claude-cli. This page is the contract between them, the error mapping, the session policy, and the upstream change that makes one workspace per product possible.

Built, as of v0.30.0

Decided by D-055 to D-062. Built: the upstream provisioning API (last section, live on prod since 2026-11-02), and the ai-manager adapter with the reply handoff and the error mapping below (GAOS_MODEL_MODE=aimanager), and since v0.25.0 one workspace per product with its sync, the drift gate and one live turn per product, and since v0.27.0 a session per task and recovery by request id (M14.5), proved by one real turn through live-aim-run.sh. Since v0.28.0 the board (M14.6); since v0.29.0 this is the only path, because M14.7 deleted the CLI adapter of BRD §7.6, the packet on disk and the detached runner; and since v0.30.0 the context the worker observed is compared with the pinned Blueprint after every turn (T-156).

Three layers, one job each

The product owner's wording is the specification: ai-claude-cli works the task with context; ai-manager shapes it with a workspace; GAOS shapes it with the product, the task details and the product's Blueprint. Each layer has something it alone owns and something it must never do, in the same form as the six layers.

LayerOwnsMust never
GAOSThe product record, its Blueprint and versions, readiness, the task graph and status machine, the brief, egress screening, the event stream, the durable prompt, reply and handoff of every attempt, the boardSpawn a model tool; hold a provider credential; send a filesystem path
ai-managerAuthentication, the list of workspaces chat may use, sessions, async request-reply, cost and usage accountingChoose a folder from client input; replace a lost session silently
ai-claude-cliThe folder under one managed root, the instruction files allowed in it, running claude with resume, reporting what it observed at startupWrite outside the managed root, or write a file outside the allowlist

A product has its own workspace, with the id gaos-<tenant>-<product code>, and — since D-071 — a second one for its reviews, gaos-<tenant>-<product code>-review, which holds the same standing files in its own root. Both ids are derived once, stored on the Workspace vertex, and never renamed, because ai-claude-cli keys stored transcripts by them.

One turn, end to end

A turn is one prompt and one reply inside one session. Every attempt at a task is one turn. The path below replaced the packet-on-disk and detached-process path in v0.29.0; the stages before Submit are the ones that path already had.

Assemblethe brief, by traversal
→
Screenegress, BR-32
→
Freezeslice + pinned Blueprint
→
SubmitPOST /v1/chat, async
→
Polluntil a result
→
Extractthe handoff block
turn
scheduler finds READY task T in product P
  │  workspace lease for P is free            # BR-38: one live turn per workspace
  │  P.workspace.syncedDigest == pinned digest # BR-39: else DispatchRefused(blueprint-drift)
  ▼
brief   = BuildBrief(T, P.record, cited handoffs, last review)
cleared = Screen(policy, target, brief)       # the only way to get a Cleared
run     = TaskRun{requestId: "gaos.<tenant>.<T>.<attempt>", sessionId, blueprintVersion}
persist run                                    # before the request leaves
  ▼
POST /v1/chat   X-Request-ID: run.requestId
  {"new_session": true, "workspace_id": "gaos-t1-p5", "model": "...", "prompt": RenderPrompt(cleared)}
  or {"session_id": "...", "prompt": ...}      # a retry resumes, D-056
→ 202 {request_id, status_url, result_url}     # emit TaskDispatched
  ▼
GET /v1/requests/{id}         every GAOS_AIM_POLL_MS   # processing → RunStarted, then Heartbeat
GET /v1/requests/{id}/result  → 200 {text, session_id, cost_usd, input_tokens, output_tokens, metadata}
  ▼
store Prompt, reply Artifact, metadata            # BR-41: the session is transport
handoff = ExtractHandoff(text)                    # last ```gaos-handoff block, run id must match
emit RunExited → task REVIEW | BLOCKED | FAILED
  ▼
digest  = workspace digest of P, read again      # BR-39, after the turn (T-156)
if digest != pinned digest or metadata.context.workspace != pinned version:
    emit DispatchRefused(rule=observed-drift)     # this turn is judged as usual
    refuse the next dispatch in P until a sync  # the drift gate above

The request id is deterministic for a reason. ai-manager treats a second POST with the same X-Request-ID as a no-op, so a request whose 202 was lost can be sent again without starting a second turn. The same id is what recovery polls after a restart.

The last step exists because a turn can change the workspace it ran in: a model may rewrite its own CLAUDE.md. So after every turn GAOS asks for the workspace digest again and compares the context the worker reports in metadata.context.workspace with the pinned Blueprint version. Drift leaves the finished attempt's outcome alone; it records a DispatchRefused with rule observed-drift and refuses the next dispatch in that product until a sync puts the published Blueprint back (BR-39). Drift is detected, not prevented.

What each answer means

ai-manager's errors are precise, and each maps to exactly one outcome. The important property is that no error is turned into a silent success or a silent fresh start.

ai-manager answersGAOS recordsTask goes to
200 with a valid gaos-handoff blockThe handoff's status; cost measured from cost_usdREVIEW, or BLOCKED if the handoff says so
200, no block, two disagreeing blocks, or a run id that is not this run'sSignature handoff-missingFAILED
200 with metadata.session_warningSignature turn-unsaved, even if the handoff is valid — the session no longer matches the recordFAILED
410Signature session-lost; SessionLost eventFAILED; the retry opens a new session
409Nothing. Another turn of this session is running — this is busy, not a failure, and no TaskRun is closedStays READY; the scheduler tries again
403 or 423DispatchRefused, rule workspace-inactiveStays READY, blocked with a reason
502, 503, transport errorExit class crashedFAILED
404 on a request GAOS submittedTaskOrphaned, rule request-lostSee recovery

Cost follows D-062: cost_usd is Claude Code's own total_cost_usd, passed through, so it is measured. A missing value, or zero while tokens are above zero, is unavailable and never zero (BR-37). TaskRun.invocation is gateway, recorded and never branched on.

Sessions: one per task

ai-manager keeps a conversation as a session: GAOS sends only the new message, and the worker restores the transcript before every turn. GAOS opens one session per task (D-056), not one per product.

SituationSessionEvent
First attempt at a taskNew, in the product's workspaceSessionOpened, reason first
Retry on the same modelResumed — the model sees its failed reply and the review—
Escalation to another modelNewSessionOpened, reason escalation
410 on resumeNew, on the next attemptSessionLost, then SessionOpened, reason lost
Older than GAOS_AIM_SESSION_MAX_AGE (25 days)NewSessionOpened, reason rotation
The product's policy now sends the task's role to the other vendorNew, on that vendor — a session lives with the provider that opened itSessionOpened, reason vendor

Why not one long session per product

ai-manager runs one turn at a time per session and answers a second with 409, so a product session would queue every task behind every other. Each turn re-reads the whole transcript, so cost would grow with the product's age. And sessions expire thirty days after their last turn, so the product's memory would vanish on a timer. Knowledge that must outlive a task belongs in the Blueprint, which every session loads from the workspace, and in earlier handoffs cited into the brief.

The session is transport, not the record (BR-41). For every attempt GAOS stores the rendered prompt, the full reply, the parsed handoff and the metadata ai-manager returned. All of it stays readable after the session expires or answers 410.

When GAOS restarts mid-turn

There is no process to adopt any more; there is a request id. At boot GAOS polls the id of every TaskRun still marked STARTED or RUNNING.

pseudocode
for run in taskRuns where status in (STARTED, RUNNING) and requestId != "":
    r = GET /v1/requests/{run.requestId}

    if r.status in (completed, failed):
        finish(run, result(r))          # adopt: the same Attempt a supervised run gets
    elif r.status in (pending, processing):
        keep_polling(run)               # lease held, heartbeats continue
    else:  # 404 -- ai-manager restarted, or the record aged out
        emit TaskOrphaned(rule=request-lost)
        hold lease until run.submittedAt + GAOS_AIM_TURN_DEADLINE
        requeue(run.task, new_session=true)

The last branch is the important one. ai-manager keeps request records in memory, so a 404 may mean the turn is still running in the worker with nobody listening. Nothing in ai-manager can cancel it (OQ-26), so GAOS keeps the workspace leased until the turn must have ended — GAOS_AIM_TURN_DEADLINE, default 660 seconds, longer than ai-manager's own 600-second provider timeout — and only then hands the workspace to another turn. This is D-054's rule kept and its mechanism replaced: a turn that cannot be proved dead is made dead, by waiting rather than by a signal.

Configuration

These replace the GAOS_CLI_* settings. Secrets are read from files, never from the environment directly, so they cannot leak through a process listing or a crash dump.

VariableDefaultMeaning
GAOS_MODEL_MODEoffaimanager selects this gateway
GAOS_AIM_URL—ai-manager base URL, e.g. https://ai-manager.mfardiansyah.id
GAOS_AIM_CHAT_AUTH_FILE—File holding the Basic login for /v1/*
GAOS_AIM_ADMIN_KEY_FILE—File holding the admin bearer for provisioning and file sync
GAOS_AIM_POLL_MS2000Interval between status polls
GAOS_AIM_TURN_DEADLINE660sWhen an unreachable turn is treated as ended
GAOS_AIM_SESSION_MAX_AGE25dAge at which a task's session is rotated
GAOS_MODEL—Passed as model; ai-manager's documented defaults disagree, so always set it
GAOS_RUNNERoffThe permission to spend money. off: nothing is sent. manual: the scheduler readies work and only a board move ready → working sends a turn (D-080). on: the scheduler dispatches everything ready. Anything else is off

When the agent needs the operator

Added in v0.31.0 (D-064, I-11). Some decisions are the operator's: a product choice the record does not settle, a trade-off with a cost GAOS cannot see. Guessing wastes the turn and the retry after it, so the agent may ask — and because a turn cannot pause (no stdin, no cancel, OQ-26), asking ends the turn.

  1. GAOS sends every turn with ask_user: true and caller: "gaos". The worker adds the question protocol to the system prompt and turns off Claude Code's own AskUserQuestion, which has nobody to answer it headless.
  2. The model ends its reply with one ai-question block — exactly three options, the one it recommends first; the operator's own words are always a fourth — and writes no handoff. A block with any other number of options is not a question, and the turn is judged as usual.
  3. ai-manager stores the question in its temp bucket and returns it on the reply: finish_reason: "awaiting_input", question: {id, question, context, options}.
  4. GAOS moves the task to AWAITING_INPUT, stores the question as an artifact, writes QuestionAsked, and lists it in the "Needs you" inbox. The task holds no lease and the scheduler never picks it (BR-44).
  5. The operator answers — POST /products/{id}/tasks/{taskId}/answer, {choice: 1..4, text}. GAOS writes QuestionAnswered and the task goes to READY.
  6. The next attempt is an ordinary turn with its own request id, sent through POST /v1/questions/{id}/answer: ai-manager marks the question answered and resumes the session that asked, with the operator's answer and GAOS's reply contract as the prompt. If that route refuses — already answered, expired, the store switched off — GAOS sends the turn through /v1/chat instead; the answer is in the frozen slice as context/answer.md either way.
  7. A question is open as long as the session that asked it exists — thirty days from the asking turn (D-066). The answer turn resumes that session even past GAOS's twenty-five-day rotation; at thirty days the task moves to BLOCKED with rule question-expired.
Answer-route statusMeaningWhat GAOS does
202Answered; the resume turn is queued under the request idPolls /v1/requests/{id}/result as for any turn
409Answered already, by another requestSends the turn through /v1/chat
410The question expired with the bucket (30 days)Same; in practice unreachable, because GAOS blocks the task at thirty days (D-066)
404, 503Unknown, or the question store is offSame

Which vendor runs a turn

ai-manager has two session vendors: claude (ai-claude-cli) and antigravity, a round-robin pool of ai-antigravity-cli accounts on several hosts that fails over only between its own accounts. Each product's vendor policy (D-067) — Claude CLI only, Antigravity only, or mixed by role — decides which one a task's turn names, and the product picks the Antigravity model from the models that GET /v1/providers lists.

VendorThe turn sendsThe workspace
Claude CLIno provider (ai-manager's session default) and GAOS_MODEL — the body every turn had before M16Admin calls with no ?provider, as before
Antigravityprovider: antigravity on the first turn and on every resume, and the product's model or noneAdmin calls with ?provider=antigravity, fanned out to every account; agy reads the same files through AGENTS.md, GEMINI.md and .agents/rules links

The run records the vendor (TaskRun.provider), so a retry knows where its session lives; a retry whose vendor changed opens a new one (BR-45). The Blueprint gate asks every vendor the policy uses. When the pool's copies disagree ai-manager answers 409, and GAOS's sync repairs it: provision, which creates the missing copies and leaves the rest, then one pruning write without if_match. Nothing falls back between vendors: a failed Antigravity turn fails and is retried on Antigravity.

Limits that shape the design

These are ai-manager's and ai-claude-cli's limits, measured from their source and docs on 2026-11-02. GAOS has to fit inside them; it cannot configure them.

LimitValueConsequence for GAOS
Request body (MAX_REQUEST_KB)256 KBThe brief must fit; the standing Blueprint goes in files, not the prompt
Provider timeout600 sA task must fit in one turn — atomic tasks matter more, not less
Worker concurrency2 processesParallelism across products is bounded upstream
Turns per session1 at a time (409)One session per task
Session retention30 days after the last turnGAOS stores the record itself
Async recordsIn memory, 24 hRecovery must tolerate 404 (OQ-30)
Streaming, cancelNone through ai-managerPoll, and wait out a turn that cannot be stopped
File uploadNoneOnly the provisioning API below can place files

The upstream change: provisioning a workspace

Measured on 2026-11-02, ai-claude-cli has no API to create a workspace and reads configs/workspaces.json once at startup; ai-manager can only switch an existing one on or off. D-059 extends both. This is the specification M14.1 builds in the ardi-personal-workspace-ai repository.

ai-claude-cli (and ai-cli-common)

SettingRule
WORKSPACES_MANAGED_ROOTAbsolute, exists, not a symlink. Boot refuses if the root or any folder above it holds CLAUDE.md, CLAUDE.local.md or .claude/CLAUDE.md — Claude Code would load it into every product
WORKSPACES_PROVISIONED_FILEA separate registry. The hand-written workspaces.json is never rewritten
WORKSPACE_PROVISION_PREFIXe.g. gaos-; a provisioned id must carry it
WORKSPACE_ADMIN_TOKENBearer for these routes only; the worker port stays private
RouteBodyAnswers
POST /v1/workspaces{id, files?}201 manifest; 200 if it already exists (idempotent); 400 bad id; 409 collides with a static id
PUT /v1/workspaces/{id}/files{files, prune, if_match} 200 manifest; 412 stale if_match; 403 on a static workspace
GET /v1/workspaces/{id}/files—Manifest: path, bytes, sha256. Never contents
DELETE /v1/workspaces/{id}—Deregisters; the folder moves to .trash/, never hard-deleted

ai-manager

Route (admin bearer)Does
POST /admin/workspaces/provision {id, files, active}Calls the worker, then adds the id to the chat list. Idempotent; a 502 says which half succeeded, and repeating the call completes the other
PUT, GET /admin/workspaces/{id}/filesProxied to the worker, with a 512 KiB route limit separate from MAX_REQUEST_KB
Any of the three with ?provider=antigravity (M16)Sent to every account of the pool, blocked ones included, with ANTIGRAVITY_WORKSPACE_ADMIN_TOKEN; every reply carries a members map. GET is 200 only when every account holds one digest, 404 when none has the workspace, and 409 when they disagree
POST /admin/requests/{id}/cancel (recommended)Maps a request to its worker job and cancels it — answers OQ-26

Two smaller requests ride along. The workspace note the model receives on the first turn is not refreshed on resume, which makes drift harder to see; and a durable request store would retire most of the deadline branch (OQ-30).