Commit 72e28fd
committed
fix(#204): preview.7 — per-node isolated cwd to defeat stale .mcp.json discovery
Vincent 06:11 UAT preview.6 still shows from=grok测试员 on receiver. 通信龙
self-grep root cause: Grok CLI auto-reads cwd .mcp.json AND ALSO uses our
ACP session/new mcpServers injection → two commhub MCP servers coexist;
the stale stdio one (Vincent's grok-build/.mcp.json had COMMHUB_ALIAS=
grok测试员 from a prior anet start) wins the LLM's hello message.
Phase 1 design (双重 review PASS by 通信龙 + 通信牛):
- Option E (ACP protocol control field): @zed-industries/agent-client-protocol
@0.4.5 NewSessionRequest schema has only _meta/cwd/mcpServers — no
replaceProjectMcpServers / mcpDiscoveryMode / noProjectMcp. OUT.
- Option D (grok CLI flag): grok agent stdio --help is just -h/--help.
grok mcp manages ~/.grok/config.toml independently. No mcp-config-path
flag. OUT.
- Option B (isolated cwd, ACP-friendly): pass per-node isolated dir via
ACP session/new's existing cwd field. Per-node mirrors top-level user
files via symlink (so LLM Read('./README.md') still works) but skips
.mcp.json so cwd discovery finds nothing. Hub-side callerAlias from
ntok tokenName (commhub-server src/index.ts:446, 通信牛 d1d867e) does
attribution. Multi-node concurrent-spawn safe by construction. PICKED.
- Option A (.mcp.json rewrite): would pollute Vincent's project — NOT.
Implementation:
1. New file agent-node/src/grok-isolated-cwd.ts exporting pure helper
prepareGrokIsolatedCwd({ userCwd, nodeId, alias, home?, onWarn? }):
{ cwd, isolated, symlinked, skipped, error? }
- mkdirSync recursive at `<home>/.anet/nodes/<sanitisedNodeKey>/grok-cwd/`
- readdirSync(userCwd), skip .mcp.json, symlink the rest (idempotent
existsSync check, per-entry try/catch — single failure does not abort
the loop, warn() is invoked and the loop continues)
- On mkdir/readdir failure, returns { isolated:false, cwd:userCwd, error }
so the caller transparently falls back to userCwd (preview.6 behaviour;
no regression).
- sanitiseNodeKey: regex /[^A-Za-z0-9._-]/g → `_` — defends against weird
alias chars sneaking path separators through (test verifies the resolved
dir stays under home/).
2. agent-node/src/cli.ts processWithGrok refactored: ~30 LOC inline block
replaced with ~10 LOC helper call. cwd field of runGrokAcpTurn() now
uses isolatedResult.cwd. preview.6 ACP HTTP MCP injection unchanged
(that's still our only commhub MCP source; the isolated cwd just stops
Grok from also reading stale cwd .mcp.json).
3. agent-node/package.json: 2.4.7-preview.6 → 2.4.7-preview.7 (no publish,
工程马 cascades on Phase 4).
Phase 2 verification:
- agent-node/src/grok-isolated-cwd.test.ts (NEW, 197 lines, **11 tests, all
passing**): creates per-node dir / alias fallback / nodeKey sanitisation /
.mcp.json skipped / files+dirs symlinked / idempotent restart / re-run
freshness (new files picked up) / mkdir failure fallback / readdir failure
fallback / per-entry symlink failure warn-not-throw / two-node concurrency
isolation.
- bun test src/: **77/77 pass** (66 pre-existing + 11 new). No regressions.
- bun build src/cli.ts: 0.59MB / 0 errors.
- Docker minimal smoke (/tmp/issue-204-p7-smoke/run-minimal.sh):
installed version: agent-node v2.4.7-preview.7
hub up 2s, SSE connected 2s, alias source log present
MINIMAL SMOKE PASS
Why not full Docker E2E here:
Phase 2 self-test was originally a 7-case Docker harness that needed real
Grok + xAI auth to exercise the LLM-side hello message. 通信龙 + I agreed
(after a hung 10-second timeout on the first attempt) that:
- The isolated-cwd ALGORITHM itself is pure fs ops — unit-testable cleanly.
- The end-to-end attribution proof needs a real Grok agent + xAI quota.
- Phase 3 测试马 owns the real-Grok 5-case Docker matrix (he has the auth).
This gives us: deterministic Phase 2 in 10min + decisive Phase 3 in 45min,
instead of brittle Phase 2 dragging on retries.
Refs:
- #204 root cause: 通信龙 self-grep finding (cwd .mcp.json + ACP injection
double-spawn)
- Phase 1 design 双 review PASS: 通信龙 + 通信牛
- 通信牛 d1d867e: commhub-server /mcp callerAlias from ntok tokenName
- preview.6 (abefbe8): ACP HTTP MCP transport switch (kept as the in-band
attribution mechanism; preview.7 just defeats the OTHER cwd-discovered
commhub MCP that was shadowing it)1 parent dfb8323 commit 72e28fd
4 files changed
Lines changed: 348 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1335 | 1335 | | |
1336 | 1336 | | |
1337 | 1337 | | |
| 1338 | + | |
| 1339 | + | |
| 1340 | + | |
| 1341 | + | |
| 1342 | + | |
| 1343 | + | |
| 1344 | + | |
| 1345 | + | |
| 1346 | + | |
| 1347 | + | |
| 1348 | + | |
| 1349 | + | |
| 1350 | + | |
| 1351 | + | |
| 1352 | + | |
| 1353 | + | |
| 1354 | + | |
| 1355 | + | |
| 1356 | + | |
| 1357 | + | |
| 1358 | + | |
| 1359 | + | |
| 1360 | + | |
| 1361 | + | |
| 1362 | + | |
| 1363 | + | |
| 1364 | + | |
| 1365 | + | |
| 1366 | + | |
1338 | 1367 | | |
1339 | 1368 | | |
1340 | 1369 | | |
1341 | 1370 | | |
1342 | | - | |
| 1371 | + | |
1343 | 1372 | | |
1344 | 1373 | | |
1345 | 1374 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
0 commit comments