From baf455a5a6585787aef0c798851b1e31ef0091e9 Mon Sep 17 00:00:00 2001 From: "Nick T." <73005126+tiliakoos@users.noreply.github.com> Date: Mon, 23 Nov 2026 20:07:14 -0500 Subject: [PATCH 1/2] fix(server): workflow failure reasons no longer end in a broken character Workflow error text, unreadable wait signal errors, and paused or failed details cut at 2,000 units could end in a lone surrogate when an emoji straddled the limit. Those cuts now stop one unit earlier. --- .../src/workflows/WorkflowStore.test.ts | 29 ++++++++ apps/server/src/workflows/WorkflowStore.ts | 9 ++- apps/server/src/workflows/Workflows.test.ts | 68 ++++++++++++++++++- apps/server/src/workflows/workflow.ts | 9 ++- 4 files changed, 107 insertions(+), 8 deletions(-) diff --git a/apps/server/src/workflows/WorkflowStore.test.ts b/apps/server/src/workflows/WorkflowStore.test.ts index 8931cb08105f8..b83cc090e9aaa 100644 --- a/apps/server/src/workflows/WorkflowStore.test.ts +++ b/apps/server/src/workflows/WorkflowStore.test.ts @@ -249,6 +249,35 @@ it.effect("what a long agent step said is cut without leaving half an emoji", () ), ); +it.effect("a long failure detail is cut without leaving half an emoji", () => + withStore( + Effect.gen(function* () { + const store = yield* WorkflowStore.WorkflowStore; + const hub = yield* MilestoneHub.MilestoneHub; + yield* store.runStarted({ + runId: "r1", + workflow: "fail", + version: 1, + engineTag: "fail@1", + idempotencyKey: "k", + input: {}, + }); + yield* store.stepStarted("r1", "work", "step"); + const detail = `${"a".repeat(1_999)}\u{1F680}tail`; + yield* store.stepEnded("r1", "work", "failed", detail); + yield* store.runPaused("r1", detail); + const [step] = yield* store.steps("r1"); + const run = yield* store.run("r1"); + const { events } = yield* hub.recent(); + const paused = events.find((event) => event.type === "workflow.run_paused"); + const expected = "a".repeat(1_999); + assert.equal(step?.detail, expected); + assert.equal(run?.detail, expected); + assert.equal(paused?.type === "workflow.run_paused" ? paused.reason : undefined, expected); + }), + ), +); + it.effect("one buffered signal goes to one wait, and a claimed wait keeps what woke it", () => withStore( Effect.gen(function* () { diff --git a/apps/server/src/workflows/WorkflowStore.ts b/apps/server/src/workflows/WorkflowStore.ts index e73af2ba9bcf5..79dfd1dc3de36 100644 --- a/apps/server/src/workflows/WorkflowStore.ts +++ b/apps/server/src/workflows/WorkflowStore.ts @@ -135,6 +135,11 @@ const stepResultCut = (text: string) => { const end = splitsSurrogatePair(text, STEP_RESULT_KEPT) ? STEP_RESULT_KEPT - 1 : STEP_RESULT_KEPT; return `${text.slice(0, end)}…`; }; +const DETAIL_KEPT = 2_000; +export const detailCut = (text: string) => + text.length <= DETAIL_KEPT + ? text + : text.slice(0, splitsSurrogatePair(text, DETAIL_KEPT) ? DETAIL_KEPT - 1 : DETAIL_KEPT); const SIGNAL_IDS_KEPT = Duration.days(7); const REFERENCE_TITLE_KEPT = 300; const idsKeptUntil = Effect.map(DateTime.now, (at) => @@ -498,7 +503,7 @@ export const make = Effect.gen(function* () { }), runPaused: Effect.fn("WorkflowStore.runPaused")(function* (runId, detail, held) { const at = yield* now; - const reason = detail.slice(0, 2000); + const reason = detailCut(detail); const paused = yield* sql` UPDATE workflow_runs SET status = 'paused', detail = ${reason}, pauses = pauses + 1, @@ -594,7 +599,7 @@ export const make = Effect.gen(function* () { Effect.andThen( sql` UPDATE workflow_steps - SET status = ${status}, detail = ${detail === null ? null : detail.slice(0, 2000)}, ended_at = ${at} + SET status = ${status}, detail = ${detail === null ? null : detailCut(detail)}, ended_at = ${at} WHERE run_id = ${runId} AND name = ${name} `, // A step that finished is progress: the next pause is the first in a row again. diff --git a/apps/server/src/workflows/Workflows.test.ts b/apps/server/src/workflows/Workflows.test.ts index 74d3e01bacd9e..3ce195c8a22a1 100644 --- a/apps/server/src/workflows/Workflows.test.ts +++ b/apps/server/src/workflows/Workflows.test.ts @@ -22,7 +22,18 @@ import * as TestClock from "effect/testing/TestClock"; import { daily, every, Tick, webhook, WebhookRequest } from "./triggers.ts"; import { issues, pullRequests } from "./forgeApi.ts"; import { cancel, runs, signalAll, start } from "./stepServices.ts"; -import { type InRun, invoke, skip, sleep, step, stop, title, wait, workflow } from "./workflow.ts"; +import { + type InRun, + invoke, + skip, + sleep, + step, + stop, + text, + title, + wait, + workflow, +} from "./workflow.ts"; import { type AgentResult, WorkflowAgentError, WorkflowAgents } from "./WorkflowAgents.ts"; import WorkflowsMigration from "../persistence/Migrations/110_Workflows.ts"; import * as WorkflowEngine from "./WorkflowEngine.ts"; @@ -2264,3 +2275,58 @@ it.effect("a workflow can take an agent's failure as an answer and go on", () => ); }).pipe(Effect.provide(NodeServices.layer), Effect.scoped), ); + +it("error text cuts at 2,000 units without leaving half an emoji", () => { + assert.equal(text(`${"a".repeat(1_999)}\u{1F680}tail`), "a".repeat(1_999)); + assert.equal(text(new Error(`${"a".repeat(1_999)}\u{1F680}tail`)), "a".repeat(1_999)); + assert.equal( + text(new Error("outer", { cause: `${"a".repeat(1_992)}\u{1F680}tail` })), + `outer: ${"a".repeat(1_992)}`, + ); +}); + +it.effect("a long unreadable wait signal error is cut without leaving half an emoji", () => + Effect.gen(function* () { + const detailed = yield* Deferred.make(); + const store = Layer.effect( + WorkflowStore.WorkflowStore, + Effect.map(WorkflowStore.make, (real) => + WorkflowStore.WorkflowStore.of({ + ...real, + stepDetail: (runId, name, detail) => + Effect.tap(real.stepDetail(runId, name, detail), () => + Deferred.succeed(detailed, undefined), + ), + }), + ), + ); + const strict = workflow( + "strict-wait", + { version: 1, payload: Schema.Struct({}), returns: Schema.String }, + () => + Effect.map( + wait("input", { + returns: Schema.String.check( + Schema.makeFilter((value) => (value === "ok" ? true : value)), + ), + }), + Option.getOrElse(() => ""), + ), + ); + const { boot } = yield* harness(store); + yield* boot( + Effect.gen(function* () { + const workflows = yield* Workflows.Workflows; + const { runId } = yield* workflows.start("strict-wait", {}, { idempotencyKey: "w1" }); + yield* workflows.waitFor(runId, status("waiting")); + const prefix = "It was signalled with a value it cannot read, and waits again: "; + const bad = `${"a".repeat(1_999 - prefix.length)}\u{1F680}tail`; + yield* workflows.signal({ runId, wait: "input" }, bad, { id: "w-bad" }); + yield* Deferred.await(detailed); + const { steps } = yield* workflows.get(runId); + assert.equal(steps[0]?.detail, `${prefix}${"a".repeat(1_999 - prefix.length)}`); + }), + [strict], + ); + }).pipe(Effect.provide(NodeServices.layer), Effect.scoped), +); diff --git a/apps/server/src/workflows/workflow.ts b/apps/server/src/workflows/workflow.ts index 3359307875999..bad9b9f513a97 100644 --- a/apps/server/src/workflows/workflow.ts +++ b/apps/server/src/workflows/workflow.ts @@ -101,7 +101,7 @@ export const claim = (name: string, cleanup = false) => /** An error as one line for a person, with what caused it when the error only wraps something. */ export const text = (error: unknown): string => { - if (typeof error === "string") return error.slice(0, 2000); + if (typeof error === "string") return WorkflowStore.detailCut(error); if (typeof error !== "object" || error === null) return String(error); // Also an error that came back from the journal, which is its fields and no longer an Error. const fields = error as { @@ -115,9 +115,8 @@ export const text = (error: unknown): string => { : typeof fields.reason === "string" ? fields.reason : "Unknown error"; - return (fields.cause === undefined ? message : `${message}: ${text(fields.cause)}`).slice( - 0, - 2000, + return WorkflowStore.detailCut( + fields.cause === undefined ? message : `${message}: ${text(fields.cause)}`, ); }; @@ -537,7 +536,7 @@ const waitClaimed = Effect.fnUntraced(function* ( name: `wait/${name}/again/${again}`, execute: Effect.gen(function* () { yield* run.store.waitReopened(run.runId, name, token); - yield* run.store.stepDetail(run.runId, name, problem.slice(0, 2000)); + yield* run.store.stepDetail(run.runId, name, WorkflowStore.detailCut(problem)); yield* deliverEarly(next, token); }), }); From f654f2ce7cd88419a167514365ebf243cbb9d949 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Tue, 24 Nov 2026 01:35:33 +0000 Subject: [PATCH 2/2] test(server): keep one regression case per truncation path The store test covers the stored step and run details, and the text() test covers the string and cause paths that every other site reuses. Co-Authored-By: Claude Opus 5.5 --- .../src/workflows/WorkflowStore.test.ts | 9 +--- apps/server/src/workflows/Workflows.test.ts | 47 ------------------- 2 files changed, 2 insertions(+), 54 deletions(-) diff --git a/apps/server/src/workflows/WorkflowStore.test.ts b/apps/server/src/workflows/WorkflowStore.test.ts index b83cc090e9aaa..594e8074ee3f9 100644 --- a/apps/server/src/workflows/WorkflowStore.test.ts +++ b/apps/server/src/workflows/WorkflowStore.test.ts @@ -253,7 +253,6 @@ it.effect("a long failure detail is cut without leaving half an emoji", () => withStore( Effect.gen(function* () { const store = yield* WorkflowStore.WorkflowStore; - const hub = yield* MilestoneHub.MilestoneHub; yield* store.runStarted({ runId: "r1", workflow: "fail", @@ -268,12 +267,8 @@ it.effect("a long failure detail is cut without leaving half an emoji", () => yield* store.runPaused("r1", detail); const [step] = yield* store.steps("r1"); const run = yield* store.run("r1"); - const { events } = yield* hub.recent(); - const paused = events.find((event) => event.type === "workflow.run_paused"); - const expected = "a".repeat(1_999); - assert.equal(step?.detail, expected); - assert.equal(run?.detail, expected); - assert.equal(paused?.type === "workflow.run_paused" ? paused.reason : undefined, expected); + assert.equal(step?.detail, "a".repeat(1_999)); + assert.equal(run?.detail, "a".repeat(1_999)); }), ), ); diff --git a/apps/server/src/workflows/Workflows.test.ts b/apps/server/src/workflows/Workflows.test.ts index 3ce195c8a22a1..3fdd50321923a 100644 --- a/apps/server/src/workflows/Workflows.test.ts +++ b/apps/server/src/workflows/Workflows.test.ts @@ -2278,55 +2278,8 @@ it.effect("a workflow can take an agent's failure as an answer and go on", () => it("error text cuts at 2,000 units without leaving half an emoji", () => { assert.equal(text(`${"a".repeat(1_999)}\u{1F680}tail`), "a".repeat(1_999)); - assert.equal(text(new Error(`${"a".repeat(1_999)}\u{1F680}tail`)), "a".repeat(1_999)); assert.equal( text(new Error("outer", { cause: `${"a".repeat(1_992)}\u{1F680}tail` })), `outer: ${"a".repeat(1_992)}`, ); }); - -it.effect("a long unreadable wait signal error is cut without leaving half an emoji", () => - Effect.gen(function* () { - const detailed = yield* Deferred.make(); - const store = Layer.effect( - WorkflowStore.WorkflowStore, - Effect.map(WorkflowStore.make, (real) => - WorkflowStore.WorkflowStore.of({ - ...real, - stepDetail: (runId, name, detail) => - Effect.tap(real.stepDetail(runId, name, detail), () => - Deferred.succeed(detailed, undefined), - ), - }), - ), - ); - const strict = workflow( - "strict-wait", - { version: 1, payload: Schema.Struct({}), returns: Schema.String }, - () => - Effect.map( - wait("input", { - returns: Schema.String.check( - Schema.makeFilter((value) => (value === "ok" ? true : value)), - ), - }), - Option.getOrElse(() => ""), - ), - ); - const { boot } = yield* harness(store); - yield* boot( - Effect.gen(function* () { - const workflows = yield* Workflows.Workflows; - const { runId } = yield* workflows.start("strict-wait", {}, { idempotencyKey: "w1" }); - yield* workflows.waitFor(runId, status("waiting")); - const prefix = "It was signalled with a value it cannot read, and waits again: "; - const bad = `${"a".repeat(1_999 - prefix.length)}\u{1F680}tail`; - yield* workflows.signal({ runId, wait: "input" }, bad, { id: "w-bad" }); - yield* Deferred.await(detailed); - const { steps } = yield* workflows.get(runId); - assert.equal(steps[0]?.detail, `${prefix}${"a".repeat(1_999 - prefix.length)}`); - }), - [strict], - ); - }).pipe(Effect.provide(NodeServices.layer), Effect.scoped), -);