Skip to content

Commit 42fb816

Browse files
fix(workspace): honour a config disable regardless of runtime connectivity
Codex round 16. One finding, verified, and it is the mirror of round 9's. Round 9 handled the runtime saying "disabled" while the config said enabled — a synthesized status that a teardown produces. This is the reverse: the config says `enabled: false` while MCP still reports "connected" from live client state, because an IDE or a direct edit can disable the entry without stopping the running client. The disable check was nested inside the not-connected branch, so that case was skipped entirely — and for an unpinned entry the replacement path below would then have persisted it enabled again, undoing the very edit the user had just made. The check is lifted above the connectivity branch. The config's `enabled` flag is the only place a user expresses "off", so it is consulted before anything else; runtime connectivity answers a different question and cannot stand in for intent. The two sources disagree in both directions, and each direction cost a round to find. That is the argument for reading intent from one authority rather than inferring it from whatever signal is nearest. Residual, named rather than hidden: a client that is already connected keeps serving until MCP drops it. This flow stops attaching and stops re-enabling, but it does not tear down a live client on the strength of someone else's config edit. 1 test: a config disable is honoured while the runtime still reports connected — no attach, no persist, no reconnect. It fails with the check re-nested.
1 parent fd5f2f8 commit 42fb816

2 files changed

Lines changed: 48 additions & 29 deletions

File tree

‎packages/opencode/src/altimate/workspace/engine-sync.ts‎

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -606,36 +606,36 @@ async function run(): Promise<Outcome> {
606606
if (existing) {
607607
let connected = existing.status === "connected"
608608

609+
// Intent first, connectivity second. The config's `enabled` flag is the
610+
// only place a user expresses "off", and the two sources disagree in BOTH
611+
// directions: `MCP.status()` synthesizes "disabled" for a configured entry
612+
// that has no runtime status (so a teardown looks like a user disable), and
613+
// it keeps reporting "connected" from live client state after the config
614+
// has been set to disabled (so a real disable looked like nothing at all).
615+
// Gating on connectivity missed the second case entirely — and for an
616+
// unpinned entry the replacement path below would then have persisted it
617+
// enabled again, undoing the very edit the user made.
618+
//
619+
// `existingEntry` is always fresh, so `entry` already reflects disk.
620+
if (entry?.enabled === false) {
621+
// The user turned this entry off deliberately. Do NOT call `MCP.connect`
622+
// to "retry" it: that persists `enabled: true` into whichever config
623+
// owns the entry, so for a global `datamate` the first prompt in any
624+
// bound project would silently re-enable it for every other project.
625+
// Say what is unavailable and leave their choice alone.
626+
log.info("engine entry is explicitly disabled; leaving it alone", { workspaceId })
627+
await notify({
628+
title: "Workspace engine is disabled",
629+
message:
630+
`The "${DATAMATE_KEY}" MCP entry is disabled, so workspace "${binding.datamateName}" ` +
631+
`integration tools are unavailable. Enable it to use them.`,
632+
variant: "warning",
633+
})
634+
return { kind: "entry-disabled" }
635+
}
636+
637+
609638
if (!connected) {
610-
// `MCP.status()` synthesizes "disabled" for any CONFIGURED entry that has
611-
// no runtime status, and `MCP.remove` deletes the status — so every
612-
// rejection teardown makes the next turn look like a user disable. Read the
613-
// config's actual flag instead; only that is user intent.
614-
// The runtime status is authoritative for "not running"; the CONFIG is
615-
// authoritative for "the user turned it off" — and the two can disagree.
616-
// `MCP.disconnect` writes `enabled: false` to disk WITHOUT invalidating
617-
// Config, so a cached entry still says `enabled: true` immediately after a
618-
// user disconnects. Treating that as a synthesized status would reconnect
619-
// and persist it enabled again, undoing their disconnect — globally, if
620-
// the owning entry is global. Read the file before deciding.
621-
// `existingEntry` is always fresh now, so `entry` already reflects disk.
622-
const owning = entry
623-
if (existing.status === "disabled" && owning?.enabled === false) {
624-
// The user turned this entry off deliberately. Do NOT call `MCP.connect`
625-
// to "retry" it: that persists `enabled: true` into whichever config
626-
// owns the entry, so for a global `datamate` the first prompt in any
627-
// bound project would silently re-enable it for every other project.
628-
// Say what is unavailable and leave their choice alone.
629-
log.info("engine entry is explicitly disabled; leaving it alone", { workspaceId })
630-
await notify({
631-
title: "Workspace engine is disabled",
632-
message:
633-
`The "${DATAMATE_KEY}" MCP entry is disabled, so workspace "${binding.datamateName}" ` +
634-
`integration tools are unavailable. Enable it to use them.`,
635-
variant: "warning",
636-
})
637-
return { kind: "entry-disabled" }
638-
}
639639
if (isUrlEntry(entry)) {
640640
// Dead URL: nothing here can bring that process back — only the IDE can
641641
// restore its port. Fall through to a local spawn and report it below.

‎packages/opencode/test/altimate/workspace/engine-sync.test.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1428,3 +1428,22 @@ describe("INVARIANT — a cached success is re-probed and re-attributed", () =>
14281428
})
14291429
}
14301430
})
1431+
1432+
describe("ensure — round 16", () => {
1433+
test("a config disable is honoured even while the runtime is still connected", async () => {
1434+
// The mirror of the round-9 case. There the runtime said disabled and the
1435+
// config said enabled; here the config says disabled and the RUNTIME still
1436+
// says connected, because MCP reports live client state. Gating the disable
1437+
// check on connectivity skipped it entirely — and for an unpinned entry the
1438+
// replacement path would then persist it enabled again, undoing the disable.
1439+
const h = install({
1440+
existing: { type: "local", command: ["datamate", "start-stdio"], enabled: false },
1441+
statuses: [{ datamate: { status: "connected" } }],
1442+
tools: { datamate_dbt_build_model: 1 },
1443+
})
1444+
expect(await ensure("s1")).toEqual({ kind: "entry-disabled" })
1445+
expect(h.added, "attached over an entry the user had disabled").toHaveLength(0)
1446+
expect(h.persisted, "re-enabled an entry the user had disabled").toHaveLength(0)
1447+
expect(h.connects).toHaveLength(0)
1448+
})
1449+
})

0 commit comments

Comments
 (0)