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.
| Layer | Owns | Must never |
|---|---|---|
| GAOS | The 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 board | Spawn a model tool; hold a provider credential; send a filesystem path |
| ai-manager | Authentication, the list of workspaces chat may use, sessions, async request-reply, cost and usage accounting | Choose a folder from client input; replace a lost session silently |
| ai-claude-cli | The folder under one managed root, the instruction
files allowed in it, running claude with resume, reporting what it observed at
startup | Write 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.
POST /v1/chat, asyncscheduler 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 answers | GAOS records | Task goes to |
|---|---|---|
200 with a valid gaos-handoff block | The handoff's status;
cost measured from cost_usd | REVIEW, or BLOCKED if the handoff says so |
200, no block, two disagreeing blocks, or a run id that is not this
run's | Signature handoff-missing | FAILED |
200 with metadata.session_warning | Signature
turn-unsaved, even if the handoff is valid — the session no longer matches the
record | FAILED |
410 | Signature session-lost; SessionLost
event | FAILED; the retry opens a new session |
409 | Nothing. Another turn of this session is running — this is busy,
not a failure, and no TaskRun is closed | Stays READY; the scheduler tries again |
403 or 423 | DispatchRefused, rule
workspace-inactive | Stays READY, blocked with a reason |
502, 503, transport error | Exit class
crashed | FAILED |
404 on a request GAOS submitted | TaskOrphaned, rule
request-lost | See 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.
| Situation | Session | Event |
|---|---|---|
| First attempt at a task | New, in the product's workspace | SessionOpened, reason first |
| Retry on the same model | Resumed — the model sees its failed reply and the review | — |
| Escalation to another model | New | SessionOpened, reason escalation |
410 on resume | New, on the next attempt | SessionLost, then SessionOpened, reason lost |
Older than GAOS_AIM_SESSION_MAX_AGE (25 days) | New | SessionOpened, reason rotation |
| The product's policy now sends the task's role to the other vendor | New, on that vendor — a session lives with the provider that opened it | SessionOpened, 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.
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.
| Variable | Default | Meaning |
|---|---|---|
GAOS_MODEL_MODE | off | aimanager 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_MS | 2000 | Interval between status polls |
GAOS_AIM_TURN_DEADLINE | 660s | When an unreachable turn is treated as ended |
GAOS_AIM_SESSION_MAX_AGE | 25d | Age at which a task's session is rotated |
GAOS_MODEL | — | Passed as model; ai-manager's documented defaults disagree, so always set it |
GAOS_RUNNER | off | The 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.
- GAOS sends every turn with
ask_user: trueandcaller: "gaos". The worker adds the question protocol to the system prompt and turns off Claude Code's ownAskUserQuestion, which has nobody to answer it headless. - The model ends its reply with one
ai-questionblock — 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. - ai-manager stores the question in its
tempbucket and returns it on the reply:finish_reason: "awaiting_input",question: {id, question, context, options}. - GAOS moves the task to
AWAITING_INPUT, stores the question as an artifact, writesQuestionAsked, and lists it in the "Needs you" inbox. The task holds no lease and the scheduler never picks it (BR-44). - The operator answers —
POST /products/{id}/tasks/{taskId}/answer,{choice: 1..4, text}. GAOS writesQuestionAnsweredand the task goes toREADY. - 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/chatinstead; the answer is in the frozen slice ascontext/answer.mdeither way. - 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
BLOCKEDwith rulequestion-expired.
| Answer-route status | Meaning | What GAOS does |
|---|---|---|
202 | Answered; the resume turn is queued under the request id | Polls /v1/requests/{id}/result as for any turn |
409 | Answered already, by another request | Sends the turn through /v1/chat |
410 | The question expired with the bucket (30 days) | Same; in practice unreachable, because GAOS blocks the task at thirty days (D-066) |
404, 503 | Unknown, or the question store is off | Same |
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.
| Vendor | The turn sends | The workspace |
|---|---|---|
| Claude CLI | no provider (ai-manager's session default) and GAOS_MODEL — the body every turn had before M16 | Admin calls with no ?provider, as before |
| Antigravity | provider: antigravity on the first turn and on every resume, and the product's model or none | Admin 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.
| Limit | Value | Consequence for GAOS |
|---|---|---|
Request body (MAX_REQUEST_KB) | 256 KB | The brief must fit; the standing Blueprint goes in files, not the prompt |
| Provider timeout | 600 s | A task must fit in one turn — atomic tasks matter more, not less |
| Worker concurrency | 2 processes | Parallelism across products is bounded upstream |
| Turns per session | 1 at a time (409) | One session per task |
| Session retention | 30 days after the last turn | GAOS stores the record itself |
| Async records | In memory, 24 h | Recovery must tolerate 404 (OQ-30) |
| Streaming, cancel | None through ai-manager | Poll, and wait out a turn that cannot be stopped |
| File upload | None | Only 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)
| Setting | Rule |
|---|---|
WORKSPACES_MANAGED_ROOT | Absolute, 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_FILE | A separate registry. The hand-written
workspaces.json is never rewritten |
WORKSPACE_PROVISION_PREFIX | e.g. gaos-; a provisioned id
must carry it |
WORKSPACE_ADMIN_TOKEN | Bearer for these routes only; the worker port stays private |
| Route | Body | Answers |
|---|---|---|
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 |
- Id:
^[a-z0-9][a-z0-9._-]{0,62}$plus the prefix; the folder isroot/id, mode 0750, refused if it is a symlink. - Allowlist: exactly
CLAUDE.mdand^\.claude/rules/[a-z0-9][a-z0-9._-]{0,80}\.md$. No.., no absolute path, no NUL, valid UTF-8 only; every target and its parent folders are checked withLstatand refused if they are symlinks. - Caps: 64 KiB per file, 256 KiB in total, 32 files, 512 KiB per request.
- All or nothing: every file is staged (
O_EXCL, write, fsync) before any is renamed into place, then the folder is fsynced. - Hot reload: the registry is the static file plus the provisioned one, behind
a lock; a new workspace is visible to
/v1/workspacesand to the next job without a restart.
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}/files | Proxied 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).