# Unattended runs: the artifact contract A gstack skill runs *unattended* when a parent agent starts it with `GSTACK_SESSION_KIND=unattended` and reads its artifacts instead of its prose. This page is the contract between that parent and the run: what the session kind changes, which files a run writes, how the parent decides whether the run finished, and how it reads the result without reading any markdown. The session kinds are: `interactive` (a human answers prompts), `headless` (`GSTACK_HEADLESS`, `CI`, the eval harness; a question BLOCKs), `spawned` (an orchestrator subagent; the recommended option is auto-chosen) and `unattended` (this page). `unattended` is honored only as the explicit `GSTACK_SESSION_KIND=unattended` override, which outranks `GSTACK_HEADLESS` so a parent can drive a run inside CI. Nothing in the test or eval harness sets it, so `headless` keeps its BLOCK semantics. ## What the session kind changes `gstack-skill-start` prints `SESSION_KIND: unattended`, `UNATTENDED_SESSION: true` and the `unattended-session` instruction block (`GSTACK_INSTRUCTION_BEGIN: unattended-session ` through `GSTACK_INSTRUCTION_END`), then applies these rules for the whole skill: - **No prompts.** The update check, upgrade offer, telemetry and sync consent, onboarding tips and routing blocks are suppressed exactly as they are for `spawned`. An unanswered consent is `off`. - **No publishing or sync, enforced at the writers.** Usage analytics are not written (`TELEMETRY_WRITE: skipped (unattended session)`), the artifacts repo is neither pulled nor pushed (`ARTIFACTS_SYNC: skipped (unattended session; mode= queue= retained)`), the sync spool is not fed (`gstack-brain-enqueue` is a no-op, and `gstack-review-log` says `review-log: sync skipped (unattended session)` on stderr), and `gstack-skill-end` drains nothing. Inherited enabled settings and pending queue work are left for the next human session. The upgrade offer becomes one line at skill end, read from the local cache: `UPGRADE_AVAILABLE: ; run /gstack-upgrade` (`+ (main at )` when main moved commits past the checkout without a new version). - **Questions decide themselves, gates do not.** A question with a `(recommended)` option takes it and appends the choice to `decisions.jsonl` with `kind: "auto"`. A question with no recommendation, any consent, any destructive or irreversible option, and the final approval gate are appended with `kind: "approval"` and `status: "pending"`. The skill ends at its next gate with the pending list rendered; it never approves and never publishes. - **State root durability is reported.** `STATE_ROOT: durable=yes|no` (`no` when the host sets `GSTACK_EPHEMERAL=1`). On an ephemeral root the run says `learnings: skipped (state root is ephemeral; set GSTACK_STATE_ROOT)` and `timing: analytics skipped (...)` instead of writing to a disk that vanishes. Point `GSTACK_STATE_ROOT` at a durable directory when you want cross-run history (see [state-root.md](state-root.md)). - **The autoplan publication guard is named, not faked.** On hosts that do not execute Claude Code hooks, and in every unattended session, `gstack-skill-start` prints `autoplan guard: not enforced by this host; publication order is unverified (GUARD_NOT_INSTALLED)` once. `gstack-artifact validate` requires that line in an unattended run's `review-record.md`. Claude Code's deny-on-absent behavior is unchanged. An unknown `GSTACK_SESSION_KIND` value coerces to `interactive` and says so: `SESSION_KIND: interactive (unknown kind '')`. ## The terminal line A run that writes a record ends with one line the parent greps: ``` GSTACK_RESULT: skill= status= run= ``` `status` is one of `complete`, `gate_pending`, `incomplete`, `interrupted` or `refused`; `run` is where the run's record is. `/autoplan` always ends `gate_pending` when it reaches the final gate, because the gate is written and never approved. Pure queries (`gstack-artifact schema`, `gstack-gate render`) print no result line. Not every workflow writes this line or a run directory today: - **`/autoplan`** writes the full run directory below through `gstack-autoplan`, and `gstack-artifact validate` checks it. It is the only skill with steps and helpers that write `run.json`, `decisions.jsonl` and `gate.json`. - **Workflow commands** `gstack-pregate`, `gstack-regen`, `gstack-restamp` and `gstack-ship-queue` print their own line, with `run=` naming their own record (the pregate receipt, the regen worktree, the restamp journal, the queue record), not a run directory. - **A refused launch.** Any skill whose install check refuses it at startup prints `GSTACK_RESULT: skill= status=refused run=-` and stops. - **`/ship`** ends with `gstack-ship-receipt result --pr ` (or `--body .gstack/tmp/ship-receipt.md` after the handoff section). It binds the receipt to the branch head, writes `/ship/runs/-/` (`ship-run.json` with `head`, `pr`, `base`, `version`, `queue_mode`, `session_kind`, `receipt` as the path of the copied `ship-receipt.md`, and `receipt_source`; it is a /ship record, not the `run` v1 manifest below, so read it directly: `gstack-artifact validate` does not apply) and prints `GSTACK_RESULT: skill=ship status=complete run=`. When gh cannot read the PR it prints `GSTACK_RESULT: skill=ship status=incomplete run=-` (exit 1). A receipt that is missing or names another head prints `GSTACK_RESULT: skill=ship status=refused run=-` with `QUEUE_RECEIPT_MISSING` or `QUEUE_RECEIPT_STALE` on stderr (exit 3); a run that stops before publication prints the same refused line itself. A parent's merge check is then mechanical: take `run=` from the last result line, read `ship-run.json`, and compare its `head` to the PR head. `gstack-ship-queue ready`, `train build` and `verify --train` make the same comparison from the PR body ([ship-policy.md](ship-policy.md#ship-before-ready)), which is why an unattended /ship may update the body of a PR that already exists: when an open PR for the branch exists and HEAD is its pushed head, Step 18 takes the pr-body section's existing-PR path and posts the body (receipt first) and title through `gstack-post`. That is the one publication the unattended rules allow; it never runs `pr-create`, never pushes a commit, never runs `gh pr ready` (the existing-PR path's draft-state items concern an early PR an unattended run never opens), and a branch with no open PR, or whose PR head is not HEAD, takes the handoff section. `result --pr ` also refuses `QUEUE_RECEIPT_STALE` when HEAD is not the PR's pushed head. When the run committed anything (a CHANGELOG entry, generated tests), the parent pushes those commits itself, then reruns the receipt write, the body post and `result` at the pushed head: a receipt for an unpushed head is `QUEUE_RECEIPT_STALE` to the queue. The receipt's `review_loop` object (`passes`, `blocking_found`, `deferred`, `noted`, `fixed`, `scope`), written from `gstack-review-scope summary`, is the review loop's machine-readable outcome, and the summary line a parent reads prints it as `passes= blocking_found= deferred=`; the PR body lists the deferred issues under `## Deferred findings` and the below-floor items under `## Review notes` ([review-policy.md](review-policy.md)). When the parent merges the base in or fixes a test after the receipt was written, it runs `gstack-ship-receipt carry --pr --base ` instead of another /ship: `CARRY: carried from to ()` plus the `GSTACK_RESULT: skill=ship status=complete run=` line means the receipt now names HEAD with a `carry` object holding the `git range-diff` evidence (`ship-run.json` gains `carried_from` and `carry_reason`); `CARRY: current` means nothing moved; `CARRY: refused (RECEIPT_CARRY_PRODUCT_CHANGED)` or `(RECEIPT_CARRY_REFUSED)` with the refused result line means the product diff changed or the reviewed head left HEAD's history, so /ship runs again ([ship-policy.md](ship-policy.md#receipt-carry)). - **Every other workflow skill** (`/review`, `/qa`, `/design-review`, `/spec`, `/land-and-deploy` and the rest) gets the session rules above (no prompts, approvals stay pending, nothing published), but has no step that writes a run directory or prints the line, so a parent should not wait for either. `/eval-plan` asks for a `gate_pending` line at its spend gate, but no helper writes its `gate.json` yet (`gstack-gate` renders and parses a gate list; it does not create one). `/cso` skips the shared startup, so these session rules do not reach it at all. Read each skill's own record instead: the review-log rows (`gstack-review-read`) for `/review` and the `qa-report-*.md` file for `/qa`. For a `/ship` run from before the result line, read the receipt instead: when the run did not push (an unattended run must not), read the receipt file in the child's checkout with `gstack-ship-receipt read --body .gstack/tmp/ship-receipt.md --json`; use `gstack-ship-receipt read --pr --json` only once a PR exists. In both cases compare the receipt's `head` to the branch SHA (`git rev-parse HEAD` in the child's checkout): `read` does not check that the receipt is current, so an older PR's receipt reads as valid; `result` does. Every workflow command shares one exit table: `0` ok, `1` fail, `2` usage, `3` refused or needs a flag. Error lines end with a result code in parentheses, for example `findings.jsonl:12: ... (ARTIFACT_SCHEMA)`; each code has an anchor in [troubleshooting.md](troubleshooting.md#unattended-runs-and-artifacts) with a `fix:` clause. Grep the code, not the prose. ## The run directory `/autoplan` writes these files; the next section shows how a parent reads them. | File | Schema | Contents | |------|--------|----------| | `run.json` | `run` v1 | The manifest: `run` id, `status`, `required_phases`, each phase's `native` and `outside` outcome (`status`, `model`, `provider`), input `snapshot` hashes, `counts`, every artifact's `path` (relative to the run directory) and `sha256`, `session_kind`, `gate_rev`, `deviations`, `consumed_by`. | | `decisions.jsonl` | `decisions` v1 | One row per decision: `id` (`-