Skip to content

fix(mocactl): write Bob's config once when its two filenames are linked - #684

Merged
pdettori merged 1 commit into
mainfrom
fix/bob-config-dedupe
Nov 4, 2026
Merged

pdettori merged 1 commit into
mainfrom
fix/bob-config-dedupe

Conversation

@mrsabath

@mrsabath mrsabath commented Nov 3, 2026

Copy link
Copy Markdown
Member

Follow-up to the review of #677, which is already merged. Not a regression from it: #677 is what makes the case reachable, by giving Bob a second filename holding the same entry.

Summary

writeAgentConfig loads each config file through loadDoc → target(), which resolves symlinks. Bob's two filenames carry an identical entry, so keeping them in step with a link is a natural thing for a developer to do:

ln -s settings.json .bob/mcp.json

That leaves two Docs over one real file. Both merge the same key into the same bytes and so agree, but the file was considered twice:

configured Claude Code, OpenCode and IBM Bob: ..., .bob/settings.json, .bob/settings.json, ...

— the name reported twice, and the file written a second time for nothing.

The Markdown loop has guarded exactly this since CLAUDE.md became a link to AGENTS.md (agent-config.ts:1089, with a test at sbx-agent-config.test.ts:852). The JSON loop had no reason to until #676 gave Bob a second filename. This adds the same guard, keyed on the resolved path.

A seen-set rather than checking writes: the first of an aliased pair may be skipped by the unchanged-file check just below, which would let the second through.

Significance: low

Worth stating plainly, so this is reviewed at the right altitude.

  • Reaching it needs a hand-made symlink. up never creates one, the guide never suggests it, and bob mcp add does not do it.
  • The symptom is cosmetic. File content, sbx doctor and .sbx/agent-config.json were all correct already — the manifest records one entry per op regardless, since both Docs resolve to the same rel. What was wrong is a duplicated name in one line of output, plus a redundant write.

What argues for fixing it anyway is the asymmetry: the Markdown path has carried this guard, with a test, for a long time, and #676 is what made the JSON path able to hit the same case.

Testing

Verified the fix is load-bearing by reverting just the guard with the new test in place — changed then holds .bob/settings.json twice, and the test fails.

  • 202 tests pass across sbx-agent-config, sbx-up and sbx-doctor
  • new test asserts the name appears once, the link survives, both names still read the merged entry, and sbx rm leaves the developer's file and link as they were
  • tsc --noEmit and Prettier clean

Related

Bob's two filenames hold the same entry, so keeping them in step with a link
(`ln -s settings.json .bob/mcp.json`) is a natural thing for a developer to
do -- and it leaves `writeAgentConfig` with two Docs over one file, since
`loadDoc` resolves through `target()`. Both merge the same key into the same
bytes and so agree, but the file was considered twice: `up` named it twice in
`configured Claude Code, OpenCode and IBM Bob: ..., .bob/settings.json,
.bob/settings.json, ...` and wrote it a second time for nothing.

The Markdown loop has guarded exactly this since CLAUDE.md started being a
link to AGENTS.md; the JSON loop had no reason to until #676 gave Bob a
second filename. This adds the same guard, keyed on the resolved path.

Seen-set rather than "already in writes": the first of an aliased pair may
be skipped by the unchanged-file check below, which would let the second
through.

Verified by reverting the guard with the test in place: `changed` then holds
`.bob/settings.json` twice. Behaviour is otherwise unchanged -- the content
was always correct, and the manifest already recorded one entry per op,
since both Docs resolve to the same `rel`.

202 tests pass across sbx-agent-config, sbx-up and sbx-doctor. The two
failures in a full run are the known TUI flakes (overlay-onboarding,
overlay-credentials); all 21 overlay tests pass in isolation and this touches
no TUI code. tsc --noEmit and Prettier clean.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Mariusz Sabath <[email protected]>
@mrsabath
mrsabath requested a review from pdettori as a code owner November 3, 2026 16:58
@pdettori pdettori added the ready-for-ai-review Request automated AI code review from clawgenti label Nov 3, 2026

@ingpaolodettori-dev ingpaolodettori-dev left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small, well-scoped fix: dedupes the JSON write loop on the resolved path, mirroring the Markdown loop guard (agent-config.ts:1089). The new test covers the linked Bob pair end to end (single name in changed, link preserved, both names read the merged entry, doctor clean, sbx rm restores). One suggestion inline: make the guard check that aliased Docs agree, rather than assume it, since it applies to all five Docs.

Author: mrsabath (MEMBER — maintainer)
Areas reviewed: TypeScript (mocactl sbx agent-config + tests), security
Agent/IDE config (.claude/.vscode): none
Commits: 1 commit, signed-off: yes
CI status: passing. Exception: deploy-scripts-bash32 was cancelled because no macOS runner was available ("not acquired by Runner … capacity constraints"). That is infra, not this PR, which touches no shell.

// Seen, not "already in writes": the first of the pair may be skipped as unchanged below.
const seenDocs = new Set<string>();
for (const d of [mcp, settings, oc, bob, bobMcp]) {
if (seenDocs.has(d.abs)) continue;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: The guard covers all five Docs, not only the Bob pair, and "both merge the same key into the same bytes and so agree" holds for only some aliasings. It holds for .bob/mcp.json ↔ .bob/settings.json, and also for .mcp.json ↔ either Bob file, because CLAUDE_SERVER and BOB_SERVER are identical. It does not hold for .claude/settings.json ↔ .bob/settings.json: settings gets permissions.allow/deny + enabledMcpjsonServers, while bob gets mcpServers.sandbox, so finalText differs between the two Docs over the same file. With this change the first Doc wins and the second Doc's merge is silently dropped, while its recs still go into the manifest. Before this change the last write won, which silently dropped the Claude deny list, so this is not a regression; it is arguably safer now. But the case stays silent either way. Suggest checking agreement instead of assuming it: keep a Map<abs, body>, and when a later Doc over the same abs has a different finalText, throw ConfigConflict(d.rel, d.rel, is the same file as ${first.rel}, which needs different settings). A one-line test with ln -s ../.bob/settings.json .claude/settings.json would pin it.

@pdettori
pdettori merged commit 0d14005 into main Nov 4, 2026
23 of 24 checks passed
@pdettori
pdettori deleted the fix/bob-config-dedupe branch November 4, 2026 20:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-ai-review Request automated AI code review from clawgenti

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants