diff --git a/apps/web/src/components/ChatView.browser.test.tsx b/apps/web/src/components/ChatView.browser.test.tsx index a0458f9e80280..7e1274543e6d1 100644 --- a/apps/web/src/components/ChatView.browser.test.tsx +++ b/apps/web/src/components/ChatView.browser.test.tsx @@ -284,6 +284,8 @@ it("an interrupted image-only first send of a new thread says it may not have be .element() .dispatchEvent(new ClipboardEvent("paste", { clipboardData, bubbles: true, cancelable: true })); await expect.element(page.getByRole("img", { name: "shot.png" })).toBeVisible(); + // The thumbnail is visible while compression still blocks sending. + await expect.element(page.getByRole("button", { name: "Preview shot.png" })).toBeEnabled(); await userEvent.keyboard("{Enter}"); await vi.waitFor(() => expect(launch.calls).toHaveLength(1)); await userEvent.keyboard("next draft"); diff --git a/packages/client-runtime/src/work-log/itemDetail.test.ts b/packages/client-runtime/src/work-log/itemDetail.test.ts index c7a6f043a3bb9..3b19c7f644c45 100644 --- a/packages/client-runtime/src/work-log/itemDetail.test.ts +++ b/packages/client-runtime/src/work-log/itemDetail.test.ts @@ -182,3 +182,27 @@ describe("MCP app tool output", () => { expect(turnItemOutputText(bounded)).toBe("chart\n[image]"); }); }); + +describe("MCP results with the SDK's _meta", () => { + const meta = { "io.modelcontextprotocol/serverInfo": { name: "T3 Code", version: "1" } }; + const structuredContent = { + check: "Server tests 7", + message: "expected [ 60 ]\nto equal [ 59 ]", + }; + it.each([ + [ + "text and structured content", + { content: JSON.stringify(structuredContent), structuredContent }, + ], + ["text blocks only", { content: [{ type: "text", text: "Server tests: 7 passed" }] }], + [ + "text blocks and structured content", + { content: [{ type: "text", text: JSON.stringify(structuredContent) }], structuredContent }, + ], + ])("reads %s the same with or without _meta", (_shape, result) => { + const plain = turnItemOutputText(toolItem(result)); + const withMeta = turnItemOutputText(toolItem({ ...result, _meta: meta })); + expect(withMeta).toBe(plain); + expect(withMeta).not.toContain("serverInfo"); + }); +}); diff --git a/packages/client-runtime/src/work-log/itemDetail.ts b/packages/client-runtime/src/work-log/itemDetail.ts index 2630f89dc2ef9..67aef9b0e9d3a 100644 --- a/packages/client-runtime/src/work-log/itemDetail.ts +++ b/packages/client-runtime/src/work-log/itemDetail.ts @@ -40,7 +40,10 @@ function textFromBlocks( if (typeof resource.text === "string") return resource.text; if (typeof resource.uri === "string") return resource.uri; } - const keys = Object.keys(value).filter((key) => key !== "isError" && key !== "is_error"); + // MCP SDKs stamp `_meta` with server info on every result; it is never the tool's output. + const keys = Object.keys(value).filter( + (key) => key !== "isError" && key !== "is_error" && key !== "_meta", + ); if (keys.length === 1 && keys[0] === "content") return textFromBlocks(value.content, depth + 1, imageBlocks); if (keys.length === 2 && keys.includes("content") && keys.includes("structuredContent")) { diff --git a/packages/source-control-core/src/server/pullRequestChecks.test.ts b/packages/source-control-core/src/server/pullRequestChecks.test.ts index 583f3fa7a012d..4d320389cc5b5 100644 --- a/packages/source-control-core/src/server/pullRequestChecks.test.ts +++ b/packages/source-control-core/src/server/pullRequestChecks.test.ts @@ -227,6 +227,45 @@ describe("check log excerpts", () => { lines: 1, }, { chunks: ["one\ntw", "o\nthree"], text: "one\ntwo\nthree", lines: 3 }, + { + chunks: [ + [ + " ❯ ~effect/Effect/successCont ../../node_modules/.pnpm/effect@4.1.3/node_modules/effect/dist/esm/Effect.js:1:1", + " ❯ FiberImpl.runLoop ../../node_modules/.pnpm/effect@4.1.3/node_modules/effect/dist/esm/internal/fiberRuntime.js:1:1", + "##[start-action display=Install dependencies;id=install]", + "##[end-action id=install;outcome=success;conclusion=success;duration_ms=900]", + "Post job cleanup.", + "Cleaning up orphan processes", + " ❯ runAssertion src/example.test.ts:10:5", + ].join("\n"), + ], + text: " ❯ runAssertion src/example.test.ts:10:5", + lines: 7, + }, + { + chunks: [ + [ + "##[error]TypeError: boom", + " at Object. (/home/runner/work/app/node_modules/foo/index.js:1:1)", + " at Object. (/home/runner/work/app/src/build.js:2:2)", + ].join("\n"), + ], + text: "##[error]TypeError: boom\n at Object. (/home/runner/work/app/src/build.js:2:2)", + lines: 3, + }, + { + chunks: [ + [ + "##[start-action display=Install dependencies;id=install]", + "##[end-action id=install;outcome=success;conclusion=success;duration_ms=900]", + "##[start-action display=Build;id=build]", + "##[error]The action has timed out.", + "##[end-action id=build;outcome=failure;conclusion=failure;duration_ms=1250]", + ].join("\n"), + ], + text: "##[error]The action has timed out.\n##[end-action id=build;outcome=failure;conclusion=failure;duration_ms=1250]", + lines: 5, + }, ])("strips formatting and counts lines across chunks %#", ({ chunks, text, lines }) => { expect(excerptCheckLog(chunks)).toEqual({ _tag: "excerpt", @@ -236,6 +275,42 @@ describe("check log excerpts", () => { }); }); + it("does not let noise consume error context or tail slots", () => { + const noise = [ + " ❯ FiberImpl.runLoop ../../node_modules/.pnpm/effect@4.1.3/node_modules/effect/dist/esm/internal/fiberRuntime.js:1:1", + "##[start-action display=Install dependencies;id=install]", + "##[end-action id=install;outcome=success;conclusion=success;duration_ms=900]", + "Post job cleanup.", + "Cleaning up orphan processes", + ]; + const expected = [ + "##[group]Run vp test", + "before 1", + "before 2", + "before 3", + "##[error]Assertion failed", + "after 1", + "after 2", + "after 3", + ...Array.from({ length: 20 }, (_, i) => `tail ${i}`), + ]; + const result = excerptCheckLog([ + [ + ...expected.slice(0, 4), + ...noise, + ...expected.slice(4, 5), + ...noise, + ...expected.slice(5), + ...noise, + ].join("\n"), + ]); + + expect(result.text).toBe(expected.join("\n")); + expect(result.totalLines).toBe(expected.length + noise.length * 3); + // Every real line is present, so dropped noise alone does not mark the excerpt truncated. + expect(result.truncated).toBe(false); + }); + it("keeps error context, its Run header and the tail within both budgets", () => { const lines = [ "##[group]Run vp test", diff --git a/packages/source-control-core/src/server/pullRequestChecks.ts b/packages/source-control-core/src/server/pullRequestChecks.ts index b0fb3e45ed65a..32cce0f2823e6 100644 --- a/packages/source-control-core/src/server/pullRequestChecks.ts +++ b/packages/source-control-core/src/server/pullRequestChecks.ts @@ -117,9 +117,17 @@ export const CHECK_LOG_EXCERPT_BUDGET = { } as const; type Line = { index: number; text: string }; +// A failed composite step's end marker is the only record of which nested step failed. +const isLogNoise = (text: string) => + (/^\s*(?:❯|at)\s/.test(text) && /node_modules[\\/]/.test(text)) || + /^##\[start-action /.test(text) || + /^##\[end-action .*outcome=(?:success|skipped)\b/.test(text) || + /^(?:Post job cleanup\.|Cleaning up orphan processes)/.test(text); + export class CheckLogExcerpt { private pending = ""; private totalLines = 0; + private noiseLines = 0; private clipped = false; private afterError = 0; private header: Line | undefined; @@ -150,6 +158,10 @@ export class CheckLogExcerpt { .replace(/^\d{4}-\d\d-\d\dT[\d:.]+Z\s?/, "") .replace(/\r$/, ""), }; + if (isLogNoise(line.text)) { + this.noiseLines++; + return; + } // Step names do not appear in the log; a section failed when it carries ##[error]. if (line.text.startsWith("##[group]Run ")) { if (this.failedSection) this.failedTail = this.tail; @@ -208,7 +220,7 @@ export class CheckLogExcerpt { _tag: "excerpt", text: lines.join("\n"), totalLines: this.totalLines, - truncated: this.clipped || lines.length < this.totalLines, + truncated: this.clipped || lines.length < this.totalLines - this.noiseLines, }; } } diff --git a/packages/source-control-github/src/server/GitHubRest.test.ts b/packages/source-control-github/src/server/GitHubRest.test.ts index 48d49199eb85f..b664991adc72b 100644 --- a/packages/source-control-github/src/server/GitHubRest.test.ts +++ b/packages/source-control-github/src/server/GitHubRest.test.ts @@ -722,11 +722,35 @@ describe("GitHub check failures", () => { check_run_url: "https://api.github.com/repos/acme/web/check-runs/123", steps: [{ name: "Run lint", conclusion: "failure" }], }; + const exitOneAnnotation = { + path: ".github", + start_line: 0, + annotation_level: "failure", + message: "Process completed with exit code 1.", + }; it.effect("sees the signed log redirect itself and follows it without Authorization", () => { const { layer, calls, fetch } = fetchHarness((url) => { if (url.includes("/annotations")) return json([ + { + path: ".github", + start_line: 0, + annotation_level: "failure", + message: "Process completed with exit code 1.", + }, + { + path: ".github", + start_line: 0, + annotation_level: "failure", + message: "Process completed with exit code 137.", + }, + { + path: ".github/workflows/ci.yml", + start_line: 0, + annotation_level: "failure", + message: "Process completed with exit code 1.", + }, { path: "a.ts", start_line: 4, annotation_level: "failure", message: "bad code" }, { path: "budget.json", start_line: 0, annotation_level: "failure", message: "grew" }, ]); @@ -736,7 +760,9 @@ describe("GitHub check failures", () => { headers: { location: "https://blob.example/log?signature=secret" }, }); if (url.startsWith("https://blob.example/")) - return new Response("2026-10-30T12:00:00Z ##[error]bad code\n"); + return new Response( + "2026-10-30T12:00:00Z ##[error]bad code\n##[error]Process completed with exit code 1.\n", + ); return json(job); }); return Effect.gen(function* () { @@ -746,10 +772,16 @@ describe("GitHub check failures", () => { attempt: 1, failedSteps: ["Run lint"], annotations: [ + { path: ".github", startLine: 0, message: "Process completed with exit code 137." }, { path: "a.ts", startLine: 4, message: "bad code" }, { path: "budget.json", startLine: 0, message: "grew" }, ], - log: { _tag: "excerpt", text: "##[error]bad code", totalLines: 1, truncated: false }, + log: { + _tag: "excerpt", + text: "##[error]bad code\n##[error]Process completed with exit code 1.", + totalLines: 2, + truncated: false, + }, }); expect(result).not.toHaveProperty("required"); const authorization = (call: (typeof calls)[number]) => @@ -770,7 +802,7 @@ describe("GitHub check failures", () => { it.effect("reads an untouched job from an earlier attempt after a rerun", () => { const { layer } = harness((request) => request.url.includes("/annotations") - ? json([]) + ? json([exitOneAnnotation]) : request.url.endsWith("/logs") ? new Response("##[error]bad code\n") : json(job), @@ -783,6 +815,9 @@ describe("GitHub check failures", () => { }); expect(result).toMatchObject({ attempt: 1, + annotations: [ + { path: ".github", startLine: 0, message: "Process completed with exit code 1." }, + ], log: { _tag: "excerpt", text: "##[error]bad code" }, }); }).pipe(Effect.provide(layer)); @@ -816,14 +851,27 @@ describe("GitHub check failures", () => { ])("returns $reason for $name without extra reads", (test) => { const { layer, requests } = harness((request) => request.url.includes("/annotations") - ? json([]) + ? json([exitOneAnnotation]) : request.url.endsWith("/logs") ? json({ message: "Unavailable" }, { status: test.logStatus }) : json(test.job), ); return Effect.gen(function* () { const read = yield* makeGitHubCheckFailureReader; - expect((yield* read(input)).log).toEqual({ _tag: "unavailable", reason: test.reason }); + const result = yield* read(input); + expect(result.log).toEqual({ _tag: "unavailable", reason: test.reason }); + expect(result.annotations).toEqual( + test.requests === 3 + ? [ + { + path: ".github", + startLine: 0, + level: "failure", + message: exitOneAnnotation.message, + }, + ] + : [], + ); expect(requests).toHaveLength(test.requests); }).pipe(Effect.provide(layer)); }); diff --git a/packages/source-control-github/src/server/gitHubCheckFailures.ts b/packages/source-control-github/src/server/gitHubCheckFailures.ts index e673988115bae..873bf394ad458 100644 --- a/packages/source-control-github/src/server/gitHubCheckFailures.ts +++ b/packages/source-control-github/src/server/gitHubCheckFailures.ts @@ -165,12 +165,21 @@ export const makeGitHubCheckFailureReader = Effect.gen(function* () { status: JOB_CONCLUSIONS[job.conclusion ?? ""] ?? "neutral", attempt: job.run_attempt, failedSteps: failedSteps.slice(0, 20).map((name) => name.slice(0, 300)), - annotations: annotations.slice(0, 20).map((annotation) => ({ - path: annotation.path.slice(0, 1024), - startLine: annotation.start_line, - level: annotation.annotation_level, - message: annotation.message.slice(0, 300), - })), + annotations: annotations + .filter( + // Only drop exit 1 when the delivered excerpt already contains it. + (annotation) => + annotation.message !== "Process completed with exit code 1." || + log._tag !== "excerpt" || + !log.text.includes(annotation.message), + ) + .slice(0, 20) + .map((annotation) => ({ + path: annotation.path.slice(0, 1024), + startLine: annotation.start_line, + level: annotation.annotation_level, + message: annotation.message.slice(0, 300), + })), log, } satisfies PullRequestCheckFailure; });