Skip to content

memory-ingest: transcripts get no source isolation / repo-scope / trust enforcement → land in default (federated) or the code source; dream then mines them #2140

Closed

Description

@exGeni

Summary

gstack-memory-ingest ingests coding-agent transcripts with no source isolation, no repo/workspace scope, and no trust enforcement — contrary to what setup-gbrain documents. The practical result: transcript pages land in the default source (often federated) or in the current repo's code source, and gbrain's dream/extract cycle then mines every one of them as if it were curated knowledge. On a real corpus this smears unrelated context across the brain and produced a ~21M-token blowup the first time dream ran over the ingested transcripts (had to delete everything afterward).

Versions: gstack 1.58.5.0, gbrain 0.42.42.0.

What the docs promise

  • setup-gbrain/SKILL.md:1456-1470 — transcript ingest default scope is "current repo only, last 90 days", and "Per-repo trust policies still apply."
  • setup-gbrain/SKILL.md:1330 — read-only repos are skipped (but "enforced by the future auto-import hook … not here").
  • setup-gbrain/memory.md:35-37 — "Repos under a deny trust policy … are skipped — neither code nor transcripts from those repos ingest."

What the code actually does

  1. Global walk, no repo/workspace filter. walkClaudeCodeProjects / walkCodexSessions (bin/gstack-memory-ingest.ts:362-423) enumerate all of ~/.claude/projects/* and ~/.codex/sessions/*. preparePages (:1130-1191) filters only on mtime-dedup, optional secret-scan, and "unattributed" (no cwd/git_remote). There is no current-repo scope and no date floor beyond the 90-day window (--all-history removes even that).
  2. No trust enforcement. The binary never reads ~/.gstack/gbrain-repo-policy.json. gstack-gbrain-repo-policy's own header says the tier is "enforced at the caller level; this binary just stores the decision." Nothing in gstack-memory-ingest or gstack-gbrain-sync consults it, so deny/read-only repos are not skipped for transcripts.
  3. No source isolation. Ingest calls gbrain import <stagingDir> --no-embed --json (bin/gstack-memory-ingest.ts:1419) with no --source-id. gbrain's resolver only auto-adopts a source when exactly one non-default source exists (src/commands/import.ts:131-146, sole_non_default tier). With multiple registered sources, transcripts route to default (which is commonly federated) — or, when GBRAIN_SOURCE/.gbrain-source is active, to the current code source. Never to a dedicated, isolated transcript source.
  4. The cycle then mines them. dream/extract run per-source and do a full walk with no type filter (src/core/cycle/extract-facts.ts:184 → engine.getAllSlugs(); sourceId scoping at :98). Every type: transcript page is treated as fact/take source material → one LLM call per page/chunk → the token blowup, plus low-quality facts smeared into the brain.

Note: gstack-config set transcript_ingest_mode off does not stop this at sync time — transcript_ingest_mode is referenced only in the setup-gbrain skill files, never read by bin/gstack-gbrain-sync.ts or bin/gstack-memory-ingest.ts. The only effective off-switch is gstack-gbrain-sync --no-memory / --code-only.

Repro (no writes)

# 1. Brain has >1 registered non-default source (typical multi-project setup).
gbrain sources list
# 2. A bare sync runs the global transcript walk and imports with no --source-id:
gstack-gbrain-sync --incremental   # -> runMemoryIngest -> gbrain import <dir> (no --source-id)
# 3. Resulting transcript pages carry source_id = 'default' (or the CWD code source),
#    not an isolated transcript source. dream/extract over that source then mine them.

Suggested fixes

  1. Route transcripts to a dedicated --source-id (default a non-federated source, e.g. transcripts-<workspace>), never default/the code source.
  2. Enforce repo-trust + an actual scope before the walk: honor gbrain-repo-policy.json (skip deny/read-only), default to current-repo, and support a hard date floor — matching what setup-gbrain already promises.
  3. Let the cycle exclude type: transcript (or make transcript ingest opt-in to mining), so dream/extract don't burn tokens treating raw transcripts as curated knowledge.
  4. Make transcript_ingest_mode=off actually gate the sync memory stage (today it's docs-only).

Related

Pairs with #2104 (staging inside GSTACK_HOME's gitignore=* repo → git-aware import sees 0 files). Together: when the staging bug is fixed, transcripts will flow — and without this issue's scoping/isolation they'll flow into the wrong source and get mined.

Activity

  1. xg-gh-25 commented on Jul 1, 2026

    @xg-gh-25

    This is the "trust-enforcement gap" pattern — the tool documents a boundary ("per-repo trust policies apply") but the code path skips the check entirely, so the boundary doesn't actually exist at runtime. SwarmAI hit an adjacent variant when our early memory-ingest honored CONTEXT.md exclusions for files but not for git submodules, so a deny-policy submodule's commit messages would still land in the brain. The symptom was identical: documented promise ("submodules under deny are skipped") vs actual behavior (submodule content skipped, but metadata ingested).

    Your § What the code actually does (point 2) is the smoking gun — gstack-memory-ingest never reads gbrain-repo-policy.json, so there's no enforcement layer even when the policy file is correct. The policy is "enforced at the caller level" per the binary's own header, but the caller (gstack-gbrain-sync → runMemoryIngest) doesn't do the check either. So the boundary collapses to a no-op.

    Why your Suggested Fix #2 is the right one: Threading the trust policy into the walk (before it touches the filesystem) is the only safe order. If you filter after the walk, there's a TOCTOU window where a transcript from a deny repo gets staged, and a concurrent dream run might mine it before the filter removes it. If you filter at import time, gbrain has already paid the I/O cost to read the file. Filtering at walk time (skip ~/.claude/projects/X if X's remote is under deny) is the cheapest correct boundary — no I/O wasted, no race.

    Two follow-on notes that may save time:

    1. Your § Related pairs this with memory-ingest stages inside GSTACK_HOME (gitignore=* repo) → gbrain git-aware import sees 0 files → silent false-success #2104 (staging inside gitignore). There's a third bug in the cluster that you didn't mention but is implied by your Repro step 3: when GBRAIN_SOURCE / .gbrain-source is active (the current code source), transcripts from other repos land in the current repo's code source. That's a cross-contamination bug on top of the no-isolation bug. The fix for Project-local .claude/skills/gstack install breaks /browse and setup can report false success #3 (dedicated transcript source) would also resolve this — transcripts never touch a code source, so GBRAIN_SOURCE can't redirect them.

    2. Suggested Fix Fix project-local /browse installs and harden setup #4 (make transcript_ingest_mode=off actually gate sync) is the fastest kill-switch for users who hit this bug before the code fix lands. Today the only working off-switch is --no-memory (which also disables file-based memory, not just transcripts), so a user who wants file-based memory but no transcript mining has no option. Reading gstack-config get transcript_ingest_mode in runMemoryIngest (default: on) and skipping the transcript walk when off would unblock them immediately.

    The 21M-token blowup you hit (§ Summary) is the production lesson here: when a trust boundary is documented but not enforced, the cost of the false-positive is unbounded — the user believes they're protected, so they don't monitor for leakage, and by the time they notice (token bill / quality degradation) the damage is done. For any memory/context tool, unenforced trust is worse than no trust promise at all.


    Traced similar trust-gap in SwarmAI early memory-ingest (submodule metadata leak). Discussion: T-MEM

  2. time-attack commented on Jul 15, 2026

    @time-attack
    Contributor

    @exGeni Transcript discovery still lacks repository trust enforcement and a dedicated non-federated source, allowing transcripts to enter default or code sources and later be mined.

  3. garrytan commented on Aug 15, 2026

    @garrytan
    Owner

    Partial progress: v1.65.0.0 (#2577) enforces the per-repo trust policy at the gbrain-sync code-import chokepoint — deny refuses, read-only skips code ingest, unreadable store fails closed, and the egress receipt names the decision (bin/gstack-gbrain-sync.ts via lib/gbrain-repo-policy-client.ts, pinned by test/gbrain-repo-policy.test.ts). The ingest-path source-isolation ask in this issue remains open.

  4. chris-conte commented on Sep 1, 2026

    @chris-conte

    Point 3 (no source isolation) still reproduces at current HEAD (e76f65a8). The spawn site has moved since this was filed — bin/gstack-memory-ingest.ts:1419 is now :1778-1787 — and still passes no source:

    // bin/gstack-memory-ingest.ts:1778-1787
    const child = spawnGbrainAsync(
      [
        "import",
        stagingDir,
        "--no-embed",
        ...(includeGitignored ? ["--include-gitignored"] : []),
        "--json",
      ],
      { baseEnv },
    );

    grep -- '--source-id\|--source"' bin/gstack-memory-ingest.ts returns nothing. The staged frontmatter (:765-779) carries agent:, session_id:, cwd:, git_remote:, source_path: — no gbrain source either, so there is nothing downstream to recover the routing from.

    Four things I can add to the report.

    1. The sibling write paths already do this correctly

    Suggested fix 1 isn't a new pattern for this repo — it's the one the other two gbrain-writing paths already follow:

    // bin/gstack-gbrain-sync.ts:1062 — the code sync targets its registered source
    const walkArgs = ["sync", "--strategy", "code", "--source", sourceId];
    # bin/gstack-gbrain-source-wireup:343-344 — and probes --help first for version safety
    if gbrain sync --help 2>/dev/null | grep -q -- '--source'; then
      sync_cmd=(gbrain sync --source "$id")

    The wireup even documents this exact hazard class in the comment directly above (:335-337, the #2662 note): an unsourced call "resolves against the brain's DEFAULT source" and can silently misroute. Memory ingest is the same class on the import path, without the probe.

    2. It is silent twice over

    The pass summary (printBulkResult, bin/gstack-memory-ingest.ts:2382-2402) reports written / skipped / failed counts but never a destination. So the misroute is invisible at write time and unattributable afterward — once the pages are in default there is no source id by which to exclude the transcript corpus or query it on its own, and default is federated, so it participates in every unscoped search.

    Worth fixing even if routing stays as-is: printing the destination source in the summary would have made this self-reporting.

    3. The auto-adopt tier's boundary is unchanged at current gbrain

    The sole_non_default tier you cite is still the only rescue path at current gbrain HEAD (6bf8db90, 0.47.9.0), and its boundary is the same — src/core/source-resolver.ts:313, if (rows.length !== 1) return null. So it fires only on a brain with exactly one non-default source; with zero, or with two or more (any real multi-project setup), it cannot fire and the import seeds default.

    One thing that has changed since your report makes it narrower still: the #3070 emptiness guard (:314-319) disables the tier once default holds any active page. So on a brain where the transcript ingest has already run a single time, the tier is permanently off from then on — the first unsourced import seeds default, and that seeding is itself what disqualifies the only mechanism that would have rescued the next one.

    4. Self-contained repro

    Scratch brain, nothing touched outside $HOME (progress lines elided):

    export HOME=/tmp/repro-home
    mkdir -p $HOME/.claude/projects/-tmp-demo
    printf '{"type":"user","message":{"role":"user","content":"hello"},"timestamp":"2026-09-01T10:00:00Z","cwd":"/tmp/demo"}\n{"type":"assistant","message":{"role":"assistant","content":"hi"},"timestamp":"2026-09-01T10:00:01Z"}\n' > $HOME/.claude/projects/-tmp-demo/aaaa1111.jsonl
    gbrain init --pglite --no-embedding
    mkdir -p $HOME/src-a $HOME/src-b
    gbrain sources add source-a --path $HOME/src-a --force
    gbrain sources add source-b --path $HOME/src-b --force
    
    # from a gstack checkout:
    bun bin/gstack-memory-ingest.ts --bulk --include-unattributed --sources transcript
    [memory-ingest] staged 1 pages → /tmp/repro-home/.gstack/.staging-ingest-2522074-1788224920881; running gbrain import...
    Found 1 markdown files
    [1] transcripts/claude-code/_unattributed/2026-09-01-aaaa1111
    [memory-ingest] gbrain import: 1 imported, 0 unchanged, 0 failed
    
    $ gbrain sources list
    SOURCES
    ───────
      default               federated          1 pages  never synced
      source-a              unset              0 pages  never synced
      source-b              unset              0 pages  never synced
    

    The page landed in default, neither registered source moved, and nothing in the output mentions a source.

    Field data

    Matching your ~21M-token dream blowup from the other end: on one multi-source install this accumulated roughly 900 transcript pages in default over about two months, close to half of them near-empty session stubs. Retrieval there was pinned to --source default, so searches kept surfacing months-old transcripts as top hits — including descriptions of components that had since been deleted, which agents then had to recognize and discard in their own logs. Cleanup required manual page deletion, not a config change.

    Smallest version of suggested fix 1

    If the dedicated-source design in fix 1 is more than you want to take at once, the routing half is one argument plus the existing probe:

    // bin/gstack-memory-ingest.ts:1780
    "import", stagingDir, "--source-id", <id>,

    guarded by gbrain import --help | grep -q -- '--source-id', mirroring bin/gstack-gbrain-source-wireup:343-344, so older gbrains degrade to today's behavior. Note import's flag is --source-id, not sync's --source.

    Happy to open a PR for the routing + summary-destination part if that's useful — I'd leave the trust-enforcement and cycle-exclusion points (2 and 4) to you, since they're larger design calls.

  5. capy-ai commented on Oct 4, 2026

    @capy-ai
    Contributor

    Memory ingest now imports each transcript into a machine-local, non-federated gbrain source for its own repository, and transcripts with no attributable repository stay local instead of landing in the default source. Fixed in v1.91.19.0 (#3025).

    To upgrade: run /gstack-upgrade in Claude Code, then start a new session.

    If you still see this, please reopen with ./setup --status output.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions