Repository navigation
Conversation
…h 4 (garrytan#3539) gbrain's recommended setup for local agents on a Postgres brain is one resident `gbrain serve --http` on loopback, registered as an http MCP entry. gstack classified any http entry as a remote brain, so memory ingest staged transcripts for a brain admin's pull that never comes. - lib/gbrain-mcp-locality.ts: one rule. An http/url/sse entry is local when its URL is http(s) on a loopback host (localhost, 127.0.0.0/8, ::1) and the local gbrain config (GBRAIN_HOME honored) has an engine (pglite or a database_url) and no remote_mcp marker (JS-truthy, as in gbrain's isThinClient). A URL with userinfo or a `${` is never local (Claude Code expands ${VAR} in the url before connecting). Everything else is unchanged. - gstack-memory-ingest: isRemoteHttpMcpMode uses it (memoized), so the loopback case takes the gbrain import path and brainIsRemote no longer forces remote for it. - gstack-memory-ingest: entries left staged/remote-http are treated as not landed when the brain is local, so --probe counts them New and --incremental imports them. - gstack-gbrain-detect: all three tiers use the rule; the loopback case reports the existing local-stdio value. Tier 2 anchors on the `claude mcp list` line format and classifies the whole URL token (never cut at ")"), for (HTTP) and (SSE) lines; a line without a usable URL stays remote-http. A remote (SSE) line no longer falls through to local-stdio. With several gbrain servers, tier 2 prefers the exact `gbrain:` line, then the first gbrain[-_]* line, the same order as tier 3. - gbrain-local-status: hasRemoteOnlyGbrainMcp uses the same classifier, so detect never reports local-stdio next to thin-client. - gstack-skill-start: the jq hot path carries a conservative subset of the rule (canonical loopback spellings only, ASCII lowercasing; same config semantics). A table-driven test runs the shipped jq programs against the TS rule.
|
Merging to
After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here |
|
Thank you for this fix and the thorough write-up. A crew lane is picking it up to land on current main with Co-authored-by credit to you. |
…in, not Path 4 (#3539) (#3727) * test(memory): a loopback gbrain serve --http is a local brain (#3539) Tests from #3552. On main they fail: 21 locality/detect cases, 1 local-status case, 3 memory-ingest cases. Co-authored-by: Willy Morin <3635875+wmorin@users.noreply.github.com> Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * fix(memory): a loopback gbrain serve --http is a local brain, not Path 4 (#3539) gbrain's recommended setup for local agents on a Postgres brain is one resident `gbrain serve --http` on loopback, registered as an http MCP entry. gstack classified every http entry as a remote brain, so memory ingest staged transcripts for a brain admin's pull that never comes. - lib/gbrain-mcp-locality.ts: one rule. An http/url/sse entry is local when its URL is http(s) on a loopback host and the local gbrain config has an engine and no remote_mcp marker. A URL with userinfo or ${ is never local. - gstack-memory-ingest: the loopback case takes the gbrain import path, and entries left staged/remote-http import on the next local run. - gstack-gbrain-detect: all three tiers use the rule; tier 2 classifies the whole URL token of the claude mcp list line. - gbrain-local-status: hasRemoteOnlyGbrainMcp uses the same classifier. - gstack-skill-start: the jq hot path carries a conservative subset. - USING_GBRAIN_WITH_GSTACK.md: a loopback serve over this machine's engine is not Path 4. Ported from #3552 onto current main. Co-authored-by: Willy Morin <3635875+wmorin@users.noreply.github.com> Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * changelog: #3539 loopback gbrain serve fragment Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * test(memory): keep userinfo fixtures clear of the pregate secrets scan (#3539) The pregate secrets stage read four userinfo URLs in the locality test as basic-auth credentials (creds.basic_auth_url). Use the PASSWORD placeholder token and split the port-lookalike URLs so the same strings reach the rule. Co-authored-by: Willy Morin <3635875+wmorin@users.noreply.github.com> Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * changelog: note the 90-day window for stuck staged pages (#3539) Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * changelog: state the measured failing-first counts (#3539) Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * test(memory): bound the jq parity spawn with a timeout (#3539) test/spawnsync-timeout-tripwire.test.ts requires every sync spawn in the test trees to carry a timeout; the jq parity helper had none (remote pregate, tree 037200b). Co-authored-by: Willy Morin <3635875+wmorin@users.noreply.github.com> Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * test(setup-gbrain): the loopback Path 4 fixture over a local PGLite now reads local-stdio (#3539) The owned Path 4 fixture registers its fake brain at 127.0.0.1 and then runs gbrain init --pglite in the same HOME. Under the #3539 rule a loopback HTTP entry over this machine's own engine is a local brain, so detect reports local-stdio there. free-suite (7) on PR #3727 (run 41231145675) failed on the old remote-http expectation. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * fix(memory): count a loopback serve as local only over a Postgres brain (#3539) Path 4's split-engine setup pairs a remote brain with a local PGLite for code search; through a tunnel on a loopback port, the PGLite config made the remote brain read as local, so transcripts would import into the code-search PGLite and the trust-policy step would be skipped. The loopback rule now needs a Postgres config (a database_url, engine not pglite), which is the setup gbrain recommends the resident serve for. The setup-gbrain Path 4 fixture expects remote-http again, as on main. Decided by GStack Minder (Captain), 2026-10-31. Co-authored-by: Willy Morin <3635875+wmorin@users.noreply.github.com> Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> --------- Co-authored-by: Willy Morin <3635875+wmorin@users.noreply.github.com> Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
|
Thanks @wmorin. Your diagnosis drove the fix. We rewrote it on current main in #3727, merged as b257eff (v1.93.29.0), and credited you with Co-authored-by. One change from your version: the loopback rule applies only when this machine's gbrain config is a Postgres brain ( |
Why (in your own words)
gbrain's recommended setup for local agents on a Postgres brain is one resident
gbrain serve --httpon loopback, registered bygbrain bootstrap harnessas anhttpMCP entry (http://127.0.0.1:3131/mcp). gstack treated every http entry as a Path 4 remote brain. So/sync-gbrainstaged transcripts under~/.gstack/transcripts/run-*for a brain admin's pull that never happens, and skippedgbrain import. The brain is on the same machine, so nothing was imported. Pages staged that way also stayed stuck after switching back to stdio:--probecounted themUnchangedand--incrementalwrote 0.This keeps #2352's one-delivery-path-per-transport design. It only changes which machine an http entry is taken to point at. An http entry counts as local when its URL is http(s) on a loopback host and this machine's gbrain config has an engine and no
remote_mcpmarker. Pages leftstaged/remote-httpare imported on the next local run.The fix targets Postgres brains, the setup in the issue. A PGLite brain held open by a live
gbrain serveis still skipped by/sync-gbrain: gbrain reports itengine-lockedand the memory stage only runs onokortimeout. This PR does not address that case.Live evidence
The issue's sandbox repro, using a PGLite brain under
GBRAIN_HOME, thehttp://127.0.0.1:3131/mcpentry thatgbrain bootstrap harnesswrites, gbrain 0.60.472.0, bun 1.4.4 and Claude Code 2.1.311. The script runs issue steps 1-3, plus a "stuck" variant that runs step 3 with origin/main and then with the branch in the same sandbox. Output is trimmed to the relevant lines;$SBis the sandbox. No server listens on 3131, because the rule reads config only.Before (origin/main 9e3308f):
After (this branch), fresh sandbox, same http entry:
Stuck state: the "before" run left
{"status":"staged","source_id":"remote-http"}. The branch then runs in the same sandbox with the same http entry. (On origin/main this probe printsNew: 0/Unchanged: 1.)The new tests were run on an origin/main export with
bin/unchanged, then on this branch.lib/gbrain-mcp-locality.tshad to be copied in with the tests, because the new unit file imports it. That means the unit cases for the helper itself pass on main too; the failures below are thebin/andlib/gbrain-local-status.tsbehavior.The cases that pass on main include the "stays remote" ones: a non-loopback URL, a loopback URL with
remote_mcp, theclaude mcp listlines that must never read as local, and a remote exactgbrain:line listed before a loopbackgbrain-a:line. They pin the behavior that must not change.Scope
lib/gbrain-mcp-locality.ts(new) holds the rule. Anhttp/url/sseentry (or a bareurl) is local when the URL ishttp:/https:on a loopback host (localhost,127.0.0.0/8,::1) andgbrainConfigDir()/config.json(honorsGBRAIN_HOME) hasengine: "pglite"or a non-blankdatabase_url, with noremote_mcpmarker. A marker counts when it is JS-truthy, as in gbrain'sisThinClient. A URL with userinfo (user@,user:pw@) or containing${is never local: Claude Code expands${VAR}inurlbefore it connects, sohttp://${X}@127.0.0.1/mcpcan dial any host. Every other entry is classified as before. The rule reads files only and makes no network calls.bin/gstack-memory-ingest.ts:isRemoteHttpMcpMode()uses the rule, so a loopback serve takes thegbrain importpath. It is memoized because the change check below now calls it once per state entry. Entries withstatus: "staged"andsource_id: "remote-http"count as not landed when the mode is local, so they are imported again. While the brain is remote they stay Unchanged, as before.brainIsRemote()itself is unchanged.bin/gstack-gbrain-detect: all three tiers use the rule. The loopback case reports the existinglocal-stdiovalue, sosync-gbrain's trust-policy gate andsetup-gbrain's Path 4 shortcut need no change. Tier 2 is the live path on current Claude Code: 2.1.311 rejectsclaude mcp get --json(unknown option '--json'), so tier 1 never answers. Tier 2 now anchors on theclaude mcp listline format (gbrain…: <url> (HTTP)or(SSE)) and classifies the whole URL token. It never cuts the token at), which would readhttp://127.0.0.1)@evil.com/mcp(hostevil.com) as loopback. A line with no usable URL keeps the oldremote-httpanswer. This also fixes a pre-existing false local: a remote(SSE)line has nohttpword and used to fall through tolocal-stdio. With several gbrain servers, tier 2 now prefers the exactgbrain:line and falls back to the firstgbrain-*/gbrain_*line, the same order as tier 3 (and memory-ingest, which readsmcpServers.gbrain). Before, it took the firstgbrain*line in list order, so a loopbackgbrain-alisted before a remotegbrainread as local.lib/gbrain-local-status.ts:hasRemoteOnlyGbrainMcp()uses the same classifier instead of its own transport-only copy. detect no longer printsgbrain_mcp_mode: local-stdionext togbrain_local_status: thin-clientfor the same loopback entry; a locked or broken local engine keeps its precise status.bin/gstack-skill-start: the jq hot path applies the rule, soARTIFACTS_SYNCno longer printsremote-modefor a loopback serve. The jq copy is a conservative subset of the TS rule, not an exact mirror. The config half has the same semantics. The URL half accepts only canonical loopback spellings (localhost,127.a.b.cwith valid decimal octets,[::1], a valid port), lowercased withascii_downcase(the regex"i"flag would case-foldſtosand accepthttpſ://). Like TS, it rejects userinfo and any URL containing${. Other spellings TS accepts (127.1,0x7f.1, a trailing dot) stay remote in jq, which is the old answer.test/gbrain-mcp-locality.test.ts(new) has the rule cases,claude mcp listline cases, and a table-driven parity run of the shipped jq programs against the TS rule: config must match exactly, and jq may never say local where TS says remote. There are also loopback, truncation,(SSE)and multi-server ordering cases intest/gstack-gbrain-detect-mcp-mode.test.ts, loopback cases intest/gbrain-local-status.test.ts, and stuck-entry cases intest/gstack-memory-ingest.test.ts.bun run typecheck(clean),bun run typecheck:test("819 known diagnostics, none new"),bun run skill:check(clean), andshellcheck -S warning bin/gstack-skill-start(the same 4 warnings as origin/main). The four touched test files together: 314 pass, 5 skip, 1 fail. The failure (#2394 … parity: probe post-attribution count…) fails the same way on origin/main on this machine.gbrain serve --http, Postgres or PGLite. No server listens in the repro. With a live serve, a PGLite brain is held by that one process. gbrain reportsengine-locked, and/sync-gbrainskips the memory stage as before (see Why).bun run testsuite, Windows, paid evals, and/sync-gbrainend to end in Claude Code.Not changed here (follow-ups):
gstack-config set gbrain_mcp_mode local|remote-http) for setups the rule does not cover, e.g. an SSH tunnel to a remote brain on a loopback port.USING_GBRAIN_WITH_GSTACK.md, setup-gbrain): add a line saying a shared loopback serve over this machine's engine is a local setup, not Path 4.gstack-config endpoint-hashstill hashes a loopback URL instead of returninglocal. sync-gbrain's trust gate is skipped now (the mode is notremote-http), but/setup-gbrainstep 9.5 and write-back gating still key on the sha8.brainIsRemote()still treats any non-PGLitedatabase_urlas remote, including a Postgres on localhost.~/.gstack/transcripts/run-*staging copies are not pruned once their pages are imported locally. If~/.gstackis later wired as a federated source, the same transcript could exist in two sources.Liveness proof (required for external contributors)
Checklist
GSTACK PRtyped live into a real surface) or PR author is @garrytan (owner exemption)Fixes #3539