Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions apps/server/src/workflows/WorkflowStore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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* () {
Expand Down
9 changes: 7 additions & 2 deletions apps/server/src/workflows/WorkflowStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand Down
21 changes: 20 additions & 1 deletion apps/server/src/workflows/Workflows.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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)}`,
);
});
9 changes: 4 additions & 5 deletions apps/server/src/workflows/workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)}`,
);
};

Expand Down Expand Up @@ -537,7 +536,7 @@ const waitClaimed = Effect.fnUntraced(function* <A, I>(
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);
}),
});
Expand Down
Loading