Skip to content

brain-sync: a skill started with an empty project slug queues projects//timeline.jsonl, and that one path refuses every later artifacts sync of that repository #4445

Closed

Description

@exGeni

What happened

When a skill starts in a directory where gstack-slug resolves an empty slug (we reproduce it with the working directory /), gstack-timeline-log writes ~/.gstack/projects/timeline.jsonl and spools the artifact path projects//timeline.jsonl (double slash). On the next drain, gstack-brain-sync stages the file as projects/timeline.jsonl, gstack-brain-sync-index.py sees a requested path that is not in the index, and the whole batch is refused. Every record in the spool is refused with it, so one bad record stops the artifacts sync for every project that shares that artifacts repository. A plain retry does not clear it.

Our part, stated first: two /codex runs that subagents of ours started outside any checkout wrote the records; starting skills there was our own choice. We did not record those runs' working directories (both timeline rows carry "branch":"unknown", which does not by itself say which directory it was); / is the only directory where we could reproduce an empty slug, and it reproduces the whole chain below. We also did not set GSTACK_SESSION_KIND=unattended for those runs; docs/unattended.md:27-33 says gstack-brain-enqueue is a no-op in such a session (the gate is bin/gstack-brain-enqueue:38), which would have kept the record out of the spool. GSTACK_PROJECT_SLUG would also have given the run a slug. The report is about what gstack does when neither is set, not about whether to run there.

What we saw on 1.99.5.0 on 2026-11-17: two runs (11:53Z and 13:06Z) left two spool records with the path projects//timeline.jsonl. From 13:06Z, gstack-brain-sync --status showed "status": "error" with staged artifact validation refused; index and queue preserved; inspect before retrying, the queue depth grew (46), gstack-doctor warned artifacts sync status error, and gstack-brain-sync --once printed BRAIN_SYNC: staged artifact validation refused: requested/index path mismatch; inspect exact path spellings and unrelated staged entries. What cleared it: gstack-brain-sync --drop-queue --yes, unstaging and deleting the stray projects/timeline.jsonl, --discover-new, then --once (status ok, pushed after rebase).

Two separate gaps are in this, and they can be fixed independently:

  1. An empty slug is not handled: nothing between gstack-slug and the writers refuses or replaces it, so a path with an empty component reaches the spool.
  2. The refusal does not name the path, and the bad record is never dropped or held, so the status does not tell the user which record to remove and the sync stays refused.

Steps to reproduce

Hermetic: a throwaway GSTACK_HOME with its own git repo, a local bare remote, a synthetic allowlist and the brain worktree pointed at an absent path inside the fixture; nothing touches a real ~/.gstack. Run on main at 169eb9c (VERSION 1.99.5.0, the same version as our install), and against the install, with the same result.

BIN=<a gstack tree>/bin
unset GSTACK_PROJECT_SLUG GSTACK_SESSION_KIND        # either would hide the problem
R=$(mktemp -d); git init -q --bare -b main "$R/remote.git"
H=$(mktemp -d); git -C "$H" init -q -b main
git -C "$H" config user.email [email protected]; git -C "$H" config user.name x
git -C "$H" remote add origin "$R/remote.git"
echo seed > "$H/.seed"; git -C "$H" add .seed; git -C "$H" commit -qm seed; git -C "$H" push -q origin main
printf 'projects/*/timeline.jsonl
projects/*/learnings.jsonl
' > "$H/.brain-allowlist"
export GSTACK_HOME=$H GSTACK_STATE_ROOT=$H GSTACK_BRAIN_WORKTREE=$H/absent-worktree
"$BIN/gstack-config" set artifacts_sync_mode full

# one healthy record, then one skill start from /
mkdir -p "$H/projects/foo-bar"; echo '{"skill":"x"}' > "$H/projects/foo-bar/timeline.jsonl"
"$BIN/gstack-brain-enqueue" projects/foo-bar/timeline.jsonl
( cd / && "$BIN/gstack-slug"; "$BIN/gstack-timeline-log" '{"skill":"codex","event":"started","branch":"unknown"}' )
cat "$H"/.brain-queue.d/*
"$BIN/gstack-brain-sync" --once; "$BIN/gstack-brain-sync" --status

Output (trimmed):

SLUG=
BRANCH=unknown
{"file":"projects/foo-bar/timeline.jsonl","ts":"..."}
{"file":"projects//timeline.jsonl","ts":"..."}
BRAIN_SYNC: staged artifact validation refused: requested/index path mismatch; inspect exact path spellings and unrelated staged entries
{"status": "error", ... "message": "staged artifact validation refused; index and queue preserved; inspect before retrying"}
{"queue_depth":2,"last_push":"never","mode":"full"}

A later healthy record (another project's learnings.jsonl, enqueued afterwards) is refused with the same message and the queue depth grows to 3. Without the seed commit the same input stops one step earlier with index verification Git command failed; that is a property of an empty throwaway repo, not part of this report.

What the code does (all at 169eb9c)

  • bin/gstack-slug:576: SLUG="${SLUG:-$(basename "$PROJECT_DIR" | tr -cd 'a-zA-Z0-9._-')}". For / the basename is /, and the character filter leaves an empty string. Nothing after it checks for an empty result (the marker branch at :443-454 does reject "", . and .., but the main flow does not).
  • bin/gstack-timeline-log:20-24, 68, 74: eval "$(gstack-slug)", then mkdir -p "$GSTACK_HOME/projects/$SLUG", the append to projects/$SLUG/timeline.jsonl and gstack-brain-enqueue "projects/$SLUG/timeline.jsonl", with no check that $SLUG is non-empty. bin/gstack-learnings-log:47,131,134 and bin/gstack-review-log:34,154,172 have the same projects/$SLUG pattern (the review log takes its slug from gstack-slug --get REPO_SLUG, which is empty in the same case). bin/gstack-skill-start:286, :722 and :731 already use ${SLUG:-unknown}, so a fallback name is an existing convention.
  • bin/gstack-brain-enqueue:32-33: the only check on the path itself is that the argument is not empty.
  • bin/gstack-brain-sync-index.py:99-114: verify() compares the requested paths with the index and refuses with requested/index path mismatch; inspect exact path spellings and unrelated staged entries when requested - entries.keys() is not empty (:113-114). The path is not named; the handler at :155-157 prints only the colliding component names (empty here) and that sentence.
  • bin/gstack-brain-sync:1056-1059: on that refusal it writes status error with staged artifact validation refused; index and queue preserved; inspect before retrying and prints the script's message to stderr. The queue is preserved by design, and the error row of docs/gbrain-sync-errors.md says "the queue is kept and retried"; the retry hits the same record each time.

Expected

  1. A skill started where the slug is empty should not write or spool a projects//... path: either a fallback slug (unknown, as gstack-skill-start already uses) or no write at all.
  2. A single malformed queue record should not stop the whole drain with a message that names nothing. Rejecting or holding such a path before staging (so it never reaches the index check), with a counted notice (the classification JSON already lists the paths) (as the unmatched/invalid classification at bin/gstack-brain-sync:312-323 and :462-474 already does for other bad records, and as hold() in the index script does for case collisions), would fit the existing design; the refusal for unexplained index differences can stay, since preserving the index there is deliberate. Naming the offending path in --status and in the error row would already let the user fix it without reading the script.

We do not know which of these you prefer, and a dropped record alone would not unstage Git's normalized entry, so the check has to happen before staging. (1) alone would stop this input; (2) would also cover any other path spelling the verifier cannot reconcile.

Docs

The docs at 169eb9c do not cover this case. The error row at docs/gbrain-sync-errors.md:44 lists the causes as "a git index lock, a commit hook, a git add failure"; a refused path spelling is not named there (we do not claim the row is meant to be exhaustive), and --drop-queue --yes is documented there for the blocked row (:42) and for held files (:80), not for error. docs/state-root.md does not say what happens when the slug is empty.

Related

We searched open and closed issues and PRs for projects//timeline.jsonl, requested/index path mismatch, staged artifact validation refused, empty slug and queue-stuck wording and found no report of this. Neighbours that are not the same defect: #3658 (case-collision check blocks a clone), #3220 and #3254 (case-colliding project paths, held instead of ok), #2549 (silent drop of unmatched queue entries), #4418 (an idle status after a failed push).

Readiness report

gstack-doctor run after we recovered (the incident run showed warn artifacts sync status error):

gstack doctor 1.99.5.0
ok              state root      ~/.gstack durable=yes (selected by default)
ok              bun             1.4.4 (floor 1.3.3, tested 1.4.2)
ok              hooks           15 hook(s) parse
ok              artifacts sync  status ok (mode full; queue 0)
ok              claude code     2.1.311 (Claude Code)
13 ok, 2 warn, 0 not configured, 0 fail

(Two unrelated warns omitted: codex project unregistered; CLAUDE.md skill list. The full output is trimmed to the lines that bear on this report.)

Environment

  • Host and version: Claude Code 2.1.311
  • OS: Linux 7.0 (x86_64), Docker container
  • gstack: installed 1.99.5.0 (0326b144); claims checked against main at 169eb9c, also VERSION 1.99.5.0; the reproduction above ran against a git archive of that commit and against the install, with the same result
  • artifacts_sync_mode: full

Activity

  1. capy-ai commented on Nov 17, 2026

    @capy-ai
    Contributor

    Thanks, and thanks for the hermetic repro. I confirmed both gaps at main e0c4136 by reading the code: bin/gstack-slug:576 can produce an empty slug with no check after it, and bin/gstack-timeline-log:24,68,74 writes and enqueues projects/$SLUG/... unguarded. Since one bad record stops artifacts sync for every project sharing the repository, this is on our fix list. We'll link the fix here when it lands.

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

    @capy-ai
    Contributor

    Fixed in #4455 (bc64f5e). gstack-brain-enqueue now refuses a path with an empty, . or .. component, so an empty slug no longer queues projects//timeline.jsonl. A malformed record that is already queued is dropped before staging, the rest of the queue syncs, and the drop is reported in --status, on stderr and in ~/.gstack/.brain-sync-drops.json. Thanks again for the hermetic repro.

  4. capy-ai commented on Nov 17, 2026

    @capy-ai
    Contributor

    This fix is on main as bc64f5e and ships in the next gstack release.

  5. added a commit that references this issue on Nov 17, 2026
    bc64f5e
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

    S3bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions