Skip to content

gstack-approvals import --autoplan names an interactive /autoplan run "autoplan" when its directory has no run.json, so the run id never resolves and separate runs share one gate state #4402

Closed

Description

@exGeni

What happened

An interactive /autoplan session keeps its run in .gstack/tmp/autoplan (autoplan/SKILL.md:422) under the run id ${BRANCH}-${DATETIME} (line 428). The skill writes $_AP/gate.json itself (line 625) and appends the gate's decision rows to decisions.jsonl (lines 631-632; the rows come from gstack-gate decisions, bin/gstack-gate:89-97). In our run gate.json and every row carried that run id in run (the skill does not pin the value; lib/gate-list.ts:265 copies gate.json's run into each row). Nothing on this path writes a run.json, plan.md or plan-active.md into the directory (it does write a restore copy of the plan, <branch>-autoplan-restore-<datetime>.md, lines 427 and 433-438): in autoplan/SKILL.md and autoplan/sections/*.md only sections/unattended.md, the hand-off to the gstack-autoplan driver, mentions run.json, and the driver names that file in lib/autoplan-state.ts:96.

After the owner answered the gate, gstack-approvals import --autoplan .gstack/tmp/autoplan --by owner printed APPROVAL_IMPORTED: n=1, and the row's source is autoplan:autoplan@gate_rev=1. lib/approval-record.ts reads the run only from run.json (lines 331-335) and otherwise falls back to the directory name (line 340):

const runId = String(run.run ?? run.id ?? path.basename(runDir));

Every interactive run in a repository uses the same directory name, so every interactive run whose directory has no run.json is imported as run autoplan. That has three effects.

  1. The run id cannot be cited. docs/troubleshooting.md:2211-2213 says to import and "then cite the run id or the row id it printed". gstack-approvals plan-check --plan "Plan: approved: <run id>" refuses with PLAN_UNRESOLVED ("no approval row from autoplan run "), because lib/plan-record.ts:178-181 looks for sources that start with autoplan:<run id>@gate_rev=. gstack-approvals render --plan with that line ends in Plan check: PLAN_UNRESOLVED (gstack-approvals plan-check says why) (on a private repo; we did not try a public one).
  2. Separate runs share one gate state. For a row id, resolveApproved takes the run from the row's source (lib/plan-record.ts:203), and gateState (lines 177-185) answers with that run's highest gate revision and, within it, the newest answered row. Following a run's newer revision is the stated design (lines 172-175). The trouble is that every interactive approval row carries the same run in its source (autoplan:autoplan@gate_rev=N), so a different interactive run of the repository, imported on any branch (the store reads every branch's file), decides for the earlier one when its gate revision is higher, or when the revisions are equal and its answer is newer. In a scratch copy of the approval store, plan-check --plan "Plan: approved: a-f8be6d9b6686" printed PLAN: approved autoplan row=a-f8be6d9b6686; after we imported a simulated second interactive run (a .gstack/tmp/autoplan directory in a second checkout, without run.json, its gate_rev 1 answered p1e later), it printed row a-9d55f7f6d092 (autoplan:autoplan@gate_rev=1) is rejected.
  3. The row's text is wrong. It reads Approve the plan "the plan" (autoplan run autoplan, 9 decisions), the reviewed plan (sha256 unknown) and owner, relayed by unknown. reviewedPlan (lib/captain-brief.ts:37) finds no run.active_plan, plan-active.md or plan.md in the directory, and our answered rows have a reply but no answered_by, which lib/approval-record.ts:357-362 renders as "relayed by unknown" (gstack-gate decisions calls applyReply without an answeredBy, bin/gstack-gate:94; we did not confirm that this is the call that wrote our rows).

A path token, Plan: approved: .gstack/tmp/autoplan, resolves today, because runIdFor (lib/plan-record.ts:146-150) falls back to the same directory name; the only place we found it described is the header comment of lib/plan-record.ts (lines 5-7). It shares effect 2.

The docs that describe the import (autoplan/DRIVER.md:56 and the captain docs) run it "after answer", on the driver's output directory. We found no doc that says how an interactive run's approval should be recorded, or that its run id cannot be cited.

What we expected

Either an interactive run is imported under its own run id (the run its gate.json and rows carry), so the run-id citation works and two runs never share a gate state; or the import refuses a directory without run.json, and the docs say how to record an interactive approval.

For the first option, a possible change (not tested): in importAutoplan read run from gate.json (or from the first answered row; DecisionLike at line 312 would need run?: string) before falling back to the directory name, and make runIdFor in lib/plan-record.ts:146-150 read it the same way, so the path token keeps resolving. A --plan <file> option would give reviewedPlan a plan to hash.

In test/approval-record.test.ts the importAutoplan cases that import an answered gate use the autoplanRun helper, which writes run.json and plan-active.md (lines 321-322), or write run.json themselves (lines 351, 367); lines 392-398 use a directory without one, but with an unanswered gate, and expect APPROVAL_IMPORT_UNANSWERED. The other callers a code search found (test/autoplan-carry.test.ts, test/autoplan-ceo-only-driver.test.ts, test/capy-captain-flow.test.ts) import driver output or CEO-only and broken-run.json cases. We found no test that imports an answered gate from a directory without run.json.

Steps to reproduce

  1. Run /autoplan interactively in Claude Code and answer its final gate. .gstack/tmp/autoplan/ then holds gate.json and decisions.jsonl, each with "run": "<branch>-<datetime>" in our run, and no run.json.
  2. ~/.claude/skills/gstack/bin/gstack-approvals import --autoplan .gstack/tmp/autoplan --by owner, then gstack-approvals list --json to see the new row's id and its source autoplan:autoplan@gate_rev=1.
  3. gstack-approvals plan-check --plan "Plan: approved: <branch>-<datetime>": PLAN_UNRESOLVED.
  4. gstack-approvals plan-check --plan "Plan: approved: <row id>": PLAN: approved autoplan row=<row id>.
  5. Import a second interactive run of the same repository, from another worktree or clone, whose gate was rejected (we simulated it in a scratch store: a .gstack/tmp/autoplan directory in a second checkout, without run.json, gate_rev 1 answered p1e after the first). Step 4 now prints row <second row id> (autoplan:autoplan@gate_rev=1) is rejected.

Readiness report

gstack doctor 1.99.4.0
ok              install root    ~/.claude/skills/gstack: claude global current (1.99.4.0), agy global current (1.99.4.0), codex global current (1.99.4.0)
ok              rescue refs     none in ~/.claude/skills/gstack
ok              state root      ~/.gstack durable=yes (selected by default)
ok              bun             1.4.4 at /usr/local/bin/bun (floor 1.3.3, tested 1.4.2)
ok              hooks           15 hook(s) parse
ok              codex           codex-cli 0.160.1; self-locate ok; model gpt-6.1-sol (source: GSTACK_CODEX_MODEL)
ok              codex probe     cached MODEL_OK, 5h ago (not re-run; --live probes now)
ok              artifacts sync  status ok (mode full; queue 0)
ok              browse bundle   browse/dist built
ok              binaries        find-browse, design, pdf, gstack-global-discover launch (4 of 4)
ok              cso             native helper 1.99.4.0 (81fb9008351d)
ok              claude code     2.1.311 (Claude Code) at /usr/local/bin/claude
ok              session journal largest of 1: 18.5 MiB
ok              guard log       175 decisions (8 denied)
ok              CLAUDE.md       no gstack section lists skills (~/.claude/CLAUDE.md, <repo>/CLAUDE.md)
15 ok, 0 warn, 0 not configured, 0 fail

Environment

Activity

  1. capy-ai commented on Nov 16, 2026

    @capy-ai
    Contributor

    Thanks for tracing this through the code. On main (8c3c39b), lib/approval-record.ts:340 still falls back to the directory name when a run has no run.json, so every interactive /autoplan run imports as run autoplan and its id can't be cited or told apart. Reading the run id from gate.json before that fallback is a small, plainly correct fix, so we're taking it. It will be rebuilt on current main and linked here; gstack's tooling is frozen until November 21, so it lands after that.

  2. added
    S3
    on Nov 22, 2026
  3. capy-ai commented on Nov 22, 2026

    @capy-ai
    Contributor

    Picking this up. A maintainer agent working through a batch of fixes (our tracking thread GSTA-802) will first reproduce this on current main. If it reproduces, the agent fixes it on main and we'll close this issue with a link when the change lands. If it no longer reproduces, we'll close it and say what changed.

  4. capy-ai commented on Nov 22, 2026

    @capy-ai
    Contributor

    Thanks @exGeni. This reproduces on current main: an interactive /autoplan run (no run.json) imports as run autoplan, so separate runs share one gate state. We tried recording the run's own id, but ids like gst-4681-20261122-104500 trip gstack's privacy scanner (the digits read as a card or phone number), which would turn a working import into a refusal on numbered branches. So this is queued behind a related privacy-scanner fix, and the run-id change will come in its own PR using an id form the scanner accepts. We'll keep this issue open until then.

  5. added a commit that references this issue on Nov 23, 2026
  6. capy-ai commented on Nov 23, 2026

    @capy-ai
    Contributor

    Fixed by #4747 (0d6cc1b): an interactive /autoplan run is now imported under its own run id (from its gate rows) instead of autoplan, and new interactive run ids put autoplan between the branch name and the time stamp, so a numbered branch no longer trips the privacy check. Thanks for the report, @exGeni.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    S3

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions