Skip to content

Commit 19f8eae

Browse files
fix(workspace): mask the engine's error text and match the notice to what is callable
- Mask each gap's `detail` when the report is parsed (control characters collapsed, then `Telemetry.maskString`, the same treatment as subprocess stderr), so the attach toast and the attach log both carry the masked text. - Warn when fewer declared tools are callable than were declared, even with an empty report (two raw keys that sanitise to one catalog entry). With no report nothing is claimed, so that case stays `info`. - Re-announce when a gap's integration or error text changes under the same reason, so the toast never keeps stale remediation. - Log a warning when a report is present but malformed and is dropped. - The real-engine e2e test removes its temporary HOME. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_0172qrhMa5TQgETASi5hxMqD
1 parent 3fa055b commit 19f8eae

5 files changed

Lines changed: 73 additions & 9 deletions

File tree

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ import {
5858
type McpStatus,
5959
type Outcome,
6060
type Toast,
61+
UNFULFILLED_META_KEY,
6162
} from "./engine-types"
6263

6364
export * from "./engine-types"
@@ -708,11 +709,17 @@ async function reconcile(sessionID: string, directory: string, state: DirectoryS
708709
// an equal-count tool swap that changes only the extension share must still
709710
// re-announce. (bot review)
710711
// A gap whose reason changed (a connection fixed, a binary still absent)
711-
// is a new verdict too, so the reasons are in the signature.
712-
const gaps = (missingReport ?? []).map((u) => `${u.key}=${u.reason}`).join(",")
712+
// is a new verdict too, so the reasons are in the signature — and so are the
713+
// integration and the error text, which the toast's remediation is built
714+
// from. (multi-model review)
715+
const gaps = JSON.stringify((missingReport ?? []).map((u) => [u.integrationId, u.key, u.reason, u.detail ?? ""]))
713716
const signature = `attached:${workspace.key}:${outcome.available}:${outcome.declared ?? "?"}:${gaps}:${extServed}`
714717
if (rec.announced === signature) return
715718
rec.announced = signature
719+
// A report that is present but malformed is dropped whole (no gap is
720+
// claimed); say so in the log, or the missing reasons are a silent mystery.
721+
if (unfulfilled === undefined && meta?.[UNFULFILLED_META_KEY] !== undefined)
722+
log.warn("workspace engine report was malformed; showing no gaps", { workspaceId: workspace.id })
716723
log.info("workspace engine attached", {
717724
workspaceId: workspace.id,
718725
available: outcome.available,
@@ -726,7 +733,13 @@ async function reconcile(sessionID: string, directory: string, state: DirectoryS
726733
await notify({
727734
title: `Workspace "${workspace.name}"`,
728735
message: `${headline}${describeMissing(missingReport ?? [])}${describeExtensionServed(extServed)}`,
729-
variant: missingReport !== undefined && missingReport.length > 0 ? "warning" : "info",
736+
// Severity follows what is callable, not only what is reported: two raw
737+
// keys that sanitise to one catalog entry leave the headline short with an
738+
// empty report. With no report nothing is claimed, so that stays info.
739+
variant:
740+
(missingReport?.length ?? 0) > 0 || (unfulfilled !== undefined && !!declared && served < declared.keys.length)
741+
? "warning"
742+
: "info",
730743
})
731744
}
732745

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
// derived MCP entry, and the pure predicates over them. Nothing here performs
55
// I/O or reads ambient state.
66
import { DATAMATE_KEY } from "@/altimate/datamate-transport"
7+
import { Telemetry } from "@/telemetry"
78

89
/** Oldest engine this client works against.
910
*
@@ -254,6 +255,14 @@ export type Unfulfilled = {
254255
detail?: string
255256
}
256257

258+
/** The engine's error text as the toast and the log may carry it: control
259+
* characters collapsed and masked the way subprocess stderr is (`mcp/index.ts`).
260+
* The engine allowlists what it sends at the version floor; this is the
261+
* client's own guard, not a second allowlist. (multi-model review) */
262+
function cleanDetail(detail: string): string {
263+
return Telemetry.maskString(detail.replace(/[\u0000-\u001f\u007f]+/g, " ").trim())
264+
}
265+
257266
/** The engine's report out of a tools/list `_meta`. Undefined when there is
258267
* none, or it is malformed: the caller then knows nothing about gaps, which
259268
* is not the same as knowing there are none. */
@@ -271,7 +280,8 @@ export function parseUnfulfilled(meta: Record<string, unknown> | undefined): Unf
271280
// malformed report, not a report with one field dropped. Fails closed like
272281
// the fields above. (codex)
273282
if (detail !== undefined && typeof detail !== "string") return undefined
274-
out.push({ key, integrationId: id, reason, ...(detail ? { detail } : {}) })
283+
const shown = detail ? cleanDetail(detail) : ""
284+
out.push({ key, integrationId: id, reason, ...(shown ? { detail: shown } : {}) })
275285
}
276286
return out
277287
}

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

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,9 @@ describe("beforeTurn — what a turn boundary does", () => {
492492
})
493493
await beforeTurn("s1")
494494
expect(h.toasts[0].message).toBe("1 of 2 declared integration tools available.")
495+
// Fewer callable than declared is a shortfall the user should notice even
496+
// though the engine reported nothing. (multi-model review)
497+
expect(h.toasts[0].variant).toBe("warning")
495498
})
496499

497500
test("a collision across the ordinary and extension groups is one entry, counted once", async () => {
@@ -512,16 +515,21 @@ describe("beforeTurn — what a turn boundary does", () => {
512515
{ key: "get_projects", integrationId: "vscode-power-user", reason: "no-bridge" },
513516
{ key: "run_model", integrationId: "vscode-power-user", reason: "no-bridge" },
514517
]
515-
const h = install({ meta: { [UNFULFILLED_META_KEY]: report } })
518+
// Only the served keys are declared, so nothing but the no-bridge entries
519+
// could make this warn.
520+
const h = install({
521+
declared: { keys: ["dbt_build_model", "dbt_compile_model"], extensionKeys: ["get_projects", "run_model"] },
522+
meta: { [UNFULFILLED_META_KEY]: report },
523+
})
516524
await beforeTurn("s1")
517525
expect(settledOutcome("s1")).toEqual({
518526
kind: "attached",
519527
available: 2,
520-
declared: 3,
528+
declared: 2,
521529
missing: [],
522530
unfulfilled: report,
523531
})
524-
expect(h.toasts[0].message).toBe("2 of 3 declared integration tools available.")
532+
expect(h.toasts[0].message).toBe("2 of 2 declared integration tools available.")
525533
expect(h.toasts[0].variant).toBe("info")
526534
})
527535

@@ -566,6 +574,22 @@ describe("beforeTurn — what a turn boundary does", () => {
566574
expect(h.toasts[1].message).toContain("no usable connection: gh_list_prs")
567575
})
568576

577+
test("a gap whose error text changed under the same reason is announced again", async () => {
578+
// The remediation in the toast is the detail; a stale one sends the user
579+
// after the wrong fix. (multi-model review)
580+
const gap = (detail: string) => ({
581+
[UNFULFILLED_META_KEY]: [{ key: "gh_list_prs", integrationId: "github-mcp", reason: "spawn-failed", detail }],
582+
})
583+
const h = install({ meta: gap("spawn docker ENOENT") })
584+
await beforeTurn("s1")
585+
await beforeTurn("s1")
586+
expect(h.toasts).toHaveLength(1)
587+
h.meta = gap("spawn failed (EACCES)")
588+
await beforeTurn("s1")
589+
expect(h.toasts).toHaveLength(2)
590+
expect(h.toasts[1].message).toContain("(spawn failed (EACCES)): gh_list_prs")
591+
})
592+
569593
test("the outcome carries the declared extension groups, and only when the allowlist names any", async () => {
570594
// The awareness section names extension tools under their integration; the
571595
// groups ride the attach outcome so precedence never makes a second lookup.

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,21 @@ describe("messages", () => {
218218
expect(parseUnfulfilled(meta(undefined))).toEqual([{ key: "x", integrationId: "i", reason: "exception" }])
219219
})
220220

221+
test("a detail is masked and flattened before anything shows or logs it", () => {
222+
// The engine allowlists what it sends; the client still masks it the way
223+
// it masks subprocess stderr, and never passes control characters on to a
224+
// toast or a log line. (multi-model review)
225+
const detailOf = (detail: string) =>
226+
parseUnfulfilled({
227+
[UNFULFILLED_META_KEY]: [{ key: "x", integrationId: "i", reason: "spawn-failed", detail }],
228+
})?.[0]?.detail
229+
expect(detailOf("spawn docker ENOENT")).toBe("spawn docker ENOENT")
230+
expect(detailOf("connect ECONNREFUSED 127.0.0.1:5432")).toBe("connect ECONNREFUSED 127.0.0.1:5432")
231+
expect(detailOf("spawn /home/someone/bin/my-server ENOENT")).not.toContain("/home/someone")
232+
expect(detailOf("line one\n\u001b[31mline two\u0007")).toBe("line one [31mline two")
233+
expect(detailOf("\n\t")).toBeUndefined()
234+
})
235+
221236
test("the engine's report is read out of tools/list _meta, and nothing is invented", () => {
222237
const report = [
223238
{ key: "a", integrationId: "jira", reason: "invalid-connection" },

‎packages/opencode/test/mcp/engine-unfulfilled.e2e.test.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// ALTIMATE_ENGINE_E2E_ROOT=/path/to/altimate-mcp-engine bun test test/mcp/engine-unfulfilled.e2e.test.ts
1010
import http from "node:http"
1111
import path from "node:path"
12-
import { mkdtempSync, mkdirSync, writeFileSync, existsSync, readdirSync, readFileSync } from "node:fs"
12+
import { mkdtempSync, mkdirSync, writeFileSync, existsSync, readdirSync, readFileSync, rmSync } from "node:fs"
1313
import { tmpdir } from "node:os"
1414
import { describe, expect, test } from "bun:test"
1515
import { Effect } from "effect"
@@ -186,8 +186,9 @@ describe.skipIf(!runnable)("engine unfulfilled report through the MCP service",
186186
MCP.Service.use((mcp: MCPNS.Interface) =>
187187
Effect.gen(function* () {
188188
const api = yield* Effect.promise(fakeAltimateApi)
189+
let home: string | undefined
189190
try {
190-
const home = isolatedHome(api.url)
191+
home = isolatedHome(api.url)
191192
yield* mcp.add("datamate", {
192193
type: "local",
193194
command: [node, cli!, "start-stdio", "--datamate", DATAMATE_ID],
@@ -234,6 +235,7 @@ describe.skipIf(!runnable)("engine unfulfilled report through the MCP service",
234235
expect(yield* mcp.listMeta("datamate")).toBeUndefined()
235236
} finally {
236237
api.close()
238+
if (home) rmSync(home, { recursive: true, force: true })
237239
}
238240
}),
239241
),

0 commit comments

Comments
 (0)