diff --git a/apps/server/src/workflows/WorkflowStore.test.ts b/apps/server/src/workflows/WorkflowStore.test.ts index 8931cb08105f8..594e8074ee3f9 100644 --- a/apps/server/src/workflows/WorkflowStore.test.ts +++ b/apps/server/src/workflows/WorkflowStore.test.ts @@ -249,6 +249,30 @@ 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; + 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"); + assert.equal(step?.detail, "a".repeat(1_999)); + assert.equal(run?.detail, "a".repeat(1_999)); + }), + ), +); + 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..3fdd50321923a 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,11 @@ 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("outer", { cause: `${"a".repeat(1_992)}\u{1F680}tail` })), + `outer: ${"a".repeat(1_992)}`, + ); +}); 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); }), });