From 28f1546cd0e9332c8778d803f749867bc915a7a0 Mon Sep 17 00:00:00 2001 From: Sanchit Rk <0xsanchit@gmail.com> Date: Wed, 11 Nov 2026 22:17:30 +0530 Subject: [PATCH 1/3] fix: show project MCP servers as sessions merge them settings.read now returns the merged mcp.json servers the harness connects to, and the project settings page draws its rows from them, so an override or entry the runtime rejects no longer shows the wrong state. Turning on a user server that is off in the user file now writes { enabled: true } instead of dropping the override. The connectors section says only that mcp.json has errors; Advanced keeps the detail. Co-Authored-By: Claude Opus 5.5 --- apps/contract/src/contract.ts | 6 +++ apps/web/src/widgets/session/config.tsx | 50 +++++-------------- apps/widget/src/codework.ts | 10 ++++ packages/codework/src/server/contract.ts | 13 +++++ packages/codework/src/server/handlers.ts | 21 ++++++++ .../test/__artifacts__/server.settings.json | 9 +++- packages/codework/test/server.test.ts | 9 +++- packages/harness/src/settings/settings.ts | 28 ++++++++--- 8 files changed, 100 insertions(+), 46 deletions(-) diff --git a/apps/contract/src/contract.ts b/apps/contract/src/contract.ts index 3e81fa0e..15428f1a 100644 --- a/apps/contract/src/contract.ts +++ b/apps/contract/src/contract.ts @@ -139,6 +139,12 @@ export const SettingsFile = Schema.Struct({ retry: Schema.Struct({ maxRetries: Schema.Int, baseDelayMs: Schema.Int, maxDelayMs: Schema.Int }), }), ), + /** For `mcp.json`: the servers as sessions use them, user and project merged. */ + servers: Schema.optionalKey( + Schema.Array( + Schema.Struct({ name: Schema.String, from: Schema.Literals(["user", "project"]), enabled: Schema.Boolean }), + ), + ), }); export type SettingsFile = typeof SettingsFile.Type; diff --git a/apps/web/src/widgets/session/config.tsx b/apps/web/src/widgets/session/config.tsx index 581788b7..a8d1d44c 100644 --- a/apps/web/src/widgets/session/config.tsx +++ b/apps/web/src/widgets/session/config.tsx @@ -250,11 +250,8 @@ interface McpRow { readonly from: "project" | "user"; readonly detail: Detail; readonly enabled: boolean; - /** The project entry only turns the user's server on or off. */ - readonly override: boolean; } -/** Where a server runs, as a line: its own description, else its command or URL. */ /** A server's line: its own description as prose, else its URL or command as code. */ interface Detail { readonly text: string; @@ -268,10 +265,10 @@ const detailOf = (config: Readonly>): Detail => { return { text: typeof config.command === "string" ? [config.command, ...args].join(" ") : "", code: true }; }; -const isOverride = (config: Readonly>) => - config.command === undefined && config.url === undefined && config.type === undefined; - -/** The MCP servers sessions in this project connect to: the project's own, and the user's it can turn off. */ +/** + * The MCP servers sessions in this project connect to: the project's own, and the user's it can turn off. + * Which servers there are and whether each is on come from the server, merged as sessions merge them. + */ export function Mcp({ projectId }: { readonly projectId: string }) { const project = useFile(projectId, "mcp"); const user = useFile(undefined, "mcp"); @@ -279,36 +276,16 @@ export function Mcp({ projectId }: { readonly projectId: string }) { if (project === undefined || user === undefined) return null; const own = record(record(project.value).mcpServers); const theirs = record(record(user.value).mcpServers); - const servers: Array = []; - for (const [name, raw] of Object.entries(theirs)) { - const config = record(raw); - const local = record(own[name]); - const override = name in own && isOverride(local); - if (name in own && !override) continue; - servers.push({ - name, - from: "user", - detail: detailOf(config), - enabled: (override ? local.enabled : config.enabled) !== false, - override, - }); - } - for (const [name, raw] of Object.entries(own)) { - const config = record(raw); - if (isOverride(config)) continue; - servers.push({ - name, - from: "project", - detail: detailOf(config), - enabled: config.enabled !== false, - override: false, - }); - } + const servers: Array = (project.servers ?? []).map((server) => ({ + ...server, + detail: detailOf(record((server.from === "project" ? own : theirs)[server.name])), + })); servers.sort((a, b) => a.name.localeCompare(b.name)); const toggle = (server: McpRow, enabled: boolean) => { - // Turning a user server back on drops the project's override rather than leaving `enabled: true`. + // Back at the user's own value, an override that only held `enabled` is dropped rather than repeated. const keys = Object.keys(record(own[server.name])); - if (server.from === "user" && enabled && keys.every((key) => key === "enabled")) + const theirsEnabled = record(theirs[server.name]).enabled !== false; + if (server.from === "user" && enabled === theirsEnabled && keys.every((key) => key === "enabled")) return void set(["mcpServers", server.name]).catch(() => undefined); void set(["mcpServers", server.name, "enabled"], enabled).catch(() => undefined); }; @@ -354,9 +331,8 @@ export function Mcp({ projectId }: { readonly projectId: string }) { } > - {project.error !== undefined && ( - {project.error}} /> - )} + {/* Only that it is broken: the Advanced section below shows what is wrong. */} + {project.error !== undefined && mcp.json has errors} />} {yours.length > 0 && ( {yours.map(row)} diff --git a/apps/widget/src/codework.ts b/apps/widget/src/codework.ts index d2bae8da..cf2b5bb7 100644 --- a/apps/widget/src/codework.ts +++ b/apps/widget/src/codework.ts @@ -580,6 +580,16 @@ export const Api = RpcGroup.make( * defaults for a project's file, the defaults for the user's. Absent when a lower file is broken. */ inherited: Schema.optionalKey(Inherited), + /** For `mcp.json`: the servers as sessions use them, user and project merged. */ + servers: Schema.optionalKey( + Schema.Array( + Schema.Struct({ + name: Schema.String, + from: Schema.Literals(["user", "project"]), + enabled: Schema.Boolean, + }), + ), + ), }), error: SettingsFileErrors, }), diff --git a/packages/codework/src/server/contract.ts b/packages/codework/src/server/contract.ts index 7b38ddf3..b6572c91 100644 --- a/packages/codework/src/server/contract.ts +++ b/packages/codework/src/server/contract.ts @@ -536,6 +536,19 @@ export const Api = RpcGroup.make( * defaults for a project's file, the defaults for the user's. Absent when a lower file is broken. */ inherited: optional(Inherited), + /** + * For `mcp.json`: the servers as sessions use them, user and project merged; entries the runtime + * skips are left out. `from` is the file that defines the server, not one that only overrides it. + */ + servers: optional( + Schema.Array( + Schema.Struct({ + name: Schema.String, + from: Schema.Literals(["user", "project"]), + enabled: Schema.Boolean, + }), + ), + ), }), error: SettingsFileErrors, }), diff --git a/packages/codework/src/server/handlers.ts b/packages/codework/src/server/handlers.ts index b8f2386e..75c8ef94 100644 --- a/packages/codework/src/server/handlers.ts +++ b/packages/codework/src/server/handlers.ts @@ -6,6 +6,7 @@ import { EventRegistry, EventSchema, Mcp, + McpConfig, ModelCatalog, Project, PromptSchema, @@ -346,6 +347,14 @@ export const layer = Contract.Api.toLayer( : projectId === undefined ? Option.some(Settings.defaults) : yield* settings.load(undefined).pipe(Effect.option); + // The servers as sessions merge them, so a list drawn from this never disagrees with a run. + const merged = + file !== "mcp" + ? undefined + : yield* McpConfig.load({ + userDir: target.userDir, + ...(target.root === undefined ? {} : { root: target.root }), + }); return { path: target.path, source: current.source, @@ -354,6 +363,18 @@ export const layer = Contract.Api.toLayer( ...("value" in parsed ? { value: parsed.value } : {}), ...(Option.isSome(problem) ? { error: problem.value.detail } : {}), ...(Option.isSome(below) ? { inherited: { retry: below.value.retry } } : {}), + ...(merged === undefined + ? {} + : { + servers: merged.servers.map((server) => ({ + name: server.name, + from: + server.file === target.path && target.scope === "project" + ? ("project" as const) + : ("user" as const), + enabled: server.config.enabled !== false, + })), + }), }; }), "settings.write": Effect.fnUntraced(function* ({ projectId, file, source, version }) { diff --git a/packages/codework/test/__artifacts__/server.settings.json b/packages/codework/test/__artifacts__/server.settings.json index 98823726..acb0c1ee 100644 --- a/packages/codework/test/__artifacts__/server.settings.json +++ b/packages/codework/test/__artifacts__/server.settings.json @@ -48,7 +48,14 @@ "project": { "path": "/app/.codework/mcp.json", "source": "{\n\t\"mcpServers\": {\n\t\t\"echo\": {\n\t\t\t\"enabled\": false\n\t\t}\n\t}\n}\n", - "error": null + "error": null, + "servers": [ + { + "name": "echo", + "from": "user", + "enabled": false + } + ] }, "orphan": { "_tag": "SettingsError", diff --git a/packages/codework/test/server.test.ts b/packages/codework/test/server.test.ts index 6e9d83d7..0369eeb6 100644 --- a/packages/codework/test/server.test.ts +++ b/packages/codework/test/server.test.ts @@ -764,7 +764,12 @@ describe("server", () => { broken: { error: broken.error, fixed: fixed.version === removed.version }, mcp: { user: { path: userMcp.path, file: fileOf(userMcp.path) }, - project: { path: projectMcp.path, source: projectMcp.source, error: projectMcp.error ?? null }, + project: { + path: projectMcp.path, + source: projectMcp.source, + error: projectMcp.error ?? null, + servers: projectMcp.servers, + }, orphan, borrowed, }, @@ -788,6 +793,8 @@ describe("server", () => { expect(afterRefusals).toBe(afterRemove); expect(broken.error).toContain("retry.maxRetries"); expect(projectMcp.error).toBeUndefined(); + // The user server, as sessions merge it: defined by the user, off through the project override. + expect(projectMcp.servers).toEqual([{ name: "echo", from: "user", enabled: false }]); expect(orphan._tag).toBe("SettingsError"); expect(borrowed._tag).toBe("SettingsError"); expect(missing._tag).toBe("ProjectNotFoundError"); diff --git a/packages/harness/src/settings/settings.ts b/packages/harness/src/settings/settings.ts index 035af780..9b9bad9e 100644 --- a/packages/harness/src/settings/settings.ts +++ b/packages/harness/src/settings/settings.ts @@ -157,6 +157,8 @@ export interface Target { readonly scope: "user" | "project"; /** The user layer's directory, which a project `mcp.json` is checked against. */ readonly userDir: string; + /** For a project file: the folder holding its `.codework`, where sessions read the project layer. */ + readonly root?: string; } /** @@ -171,18 +173,30 @@ export const locate = Effect.fn("Settings.locate")(function* (input: { readonly kind: Target["kind"]; }) { const userDir = input.userConfigDir ?? input.home; - const directory = - input.hostDir === undefined - ? userDir - : hostPath.join((yield* projectRoot(input.hostDir, input.home)) ?? input.hostDir, Global.appConfigDir); - const scope: Target["scope"] = input.hostDir === undefined ? "user" : "project"; + const root = + input.hostDir === undefined ? undefined : ((yield* projectRoot(input.hostDir, input.home)) ?? input.hostDir); + const directory = root === undefined ? userDir : hostPath.join(root, Global.appConfigDir); + const scope: Target["scope"] = root === undefined ? "user" : "project"; + const placed = root === undefined ? {} : { root }; if (input.kind === "mcp") - return { path: hostPath.join(directory, "mcp.json"), kind: input.kind, scope, userDir } satisfies Target; + return { + path: hostPath.join(directory, "mcp.json"), + kind: input.kind, + scope, + userDir, + ...placed, + } satisfies Target; const candidates = settingsIn(directory); const existing = yield* Effect.findFirst(candidates, (path) => fileSystem.exists(path).pipe(Effect.orElseSucceed(() => false)), ); - return { path: Option.getOrElse(existing, () => candidates[0]!), kind: input.kind, scope, userDir } satisfies Target; + return { + path: Option.getOrElse(existing, () => candidates[0]!), + kind: input.kind, + scope, + userDir, + ...placed, + } satisfies Target; }); export class SettingsError extends Schema.TaggedError()("SettingsError", { From 7ac8435e5670dfe04a90989d78fda90868b3c853 Mon Sep 17 00:00:00 2001 From: Sanchit Rk <0xsanchit@gmail.com> Date: Thu, 12 Nov 2026 01:58:21 +0530 Subject: [PATCH 2/3] fix(server): name the test model in the CodeWork fixtures; run live tests on Ubuntu Since a run needs a model named in settings when no provider is configured, the scripted CodeWork the app tests start never ran a prompt, so most suites failed in their shared setup. The fixture now writes the test model into its home, and the recovery suite names it in the settings it writes itself. The live machine suites use Ubuntu only: the long-lived machine is `ubuntu` in place of the retired `fedora`. Their artifacts are regenerated for that name and for the current thread statuses. Co-Authored-By: Claude Opus 5.5 --- .../__artifacts__/sync.machines.deleted.json | 9 +- .../sync.machines.partition.json | 6 +- .../__artifacts__/sync.machines.restored.json | 6 +- .../sync.machines.revisions.json | 1 - .../__artifacts__/sync.machines.several.json | 6 +- .../__artifacts__/sync.machines.shuffle.json | 78 +++++------ .../__artifacts__/sync.machines.store.json | 6 +- apps/server/test/fixtures/codework.ts | 10 ++ apps/server/test/machines/orb.ts | 6 +- .../test/recovery.machines.live.test.ts | 4 +- apps/server/test/sync.machines.live.test.ts | 124 +++++++++--------- 11 files changed, 137 insertions(+), 119 deletions(-) diff --git a/apps/server/test/__artifacts__/sync.machines.deleted.json b/apps/server/test/__artifacts__/sync.machines.deleted.json index 9e4c5c73..41b20234 100644 --- a/apps/server/test/__artifacts__/sync.machines.deleted.json +++ b/apps/server/test/__artifacts__/sync.machines.deleted.json @@ -1,7 +1,7 @@ { "changed": [ { - "machineId": "", + "machineId": "", "full": false, "items": 1, "project": [], @@ -27,7 +27,7 @@ "session": [ { "id": "", - "machine_id": "", + "machine_id": "", "organization_id": "personal", "space_id": "", "slug": "", @@ -42,7 +42,7 @@ }, { "id": "", - "machine_id": "", + "machine_id": "", "organization_id": "personal", "space_id": "", "slug": "", @@ -73,6 +73,7 @@ "foundation": null, "placement_space_id": null, "placement_dir": null, + "parked": 0, "restarts": 0, "attempt": null, "run_state": "idle", @@ -86,7 +87,7 @@ "tokens_output": 1, "tokens_cache_read": 0, "tokens_cache_write": 0, - "status": "attention", + "status": "working", "status_at": "