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
25 changes: 25 additions & 0 deletions apps/server/src/workflows/WorkflowStore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,31 @@ it.effect("counts what waits on a person, and finds the run's latest agent threa
),
);

it.effect("a long step result is cut without leaving half an emoji", () =>
withStore(
Effect.gen(function* () {
const store = yield* WorkflowStore.WorkflowStore;
yield* store.stepStarted("r1", "write", "step");
yield* store.stepResult("r1", "write", `${"a".repeat(7_998)}\u{1F680}tail`);
const [step] = yield* store.steps("r1");
// The cut is of the JSON text, which opens with a quote.
assert.equal(WorkflowStore.jsonValue(step?.result_json ?? "null"), `"${"a".repeat(7_998)}…`);
}),
),
);

it.effect("what a long agent step said is cut without leaving half an emoji", () =>
withStore(
Effect.gen(function* () {
const store = yield* WorkflowStore.WorkflowStore;
yield* store.stepStarted("r1", "write", "agent");
yield* store.stepResult("r1", "write", null, `${"a".repeat(7_999)}\u{1F680}tail`);
const [step] = yield* store.steps("r1");
assert.equal(step?.said, `${"a".repeat(7_999)}…`);
}),
),
);

it.effect("one buffered signal goes to one wait, and a claimed wait keeps what woke it", () =>
withStore(
Effect.gen(function* () {
Expand Down
14 changes: 7 additions & 7 deletions apps/server/src/workflows/WorkflowStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
WorkflowRunStatus,
WorkflowStep,
} from "@t3tools/contracts";
import { splitsSurrogatePair } from "@t3tools/shared/assistantCitations";
import * as Context from "effect/Context";
import * as DateTime from "effect/DateTime";
import * as Duration from "effect/Duration";
Expand Down Expand Up @@ -130,6 +131,10 @@ const WAKE_REDONE_AFTER = Duration.seconds(30);
// Long enough for a sender's retries, short enough that the table stays small.
// Enough to read what a step said; the page that shows it is not a place for a whole report.
const STEP_RESULT_KEPT = 8_000;
const stepResultCut = (text: string) => {
const end = splitsSurrogatePair(text, STEP_RESULT_KEPT) ? STEP_RESULT_KEPT - 1 : STEP_RESULT_KEPT;
return `${text.slice(0, end)}…`;
};
const SIGNAL_IDS_KEPT = Duration.days(7);
const REFERENCE_TITLE_KEPT = 300;
const idsKeptUntil = Effect.map(DateTime.now, (at) =>
Expand Down Expand Up @@ -909,15 +914,10 @@ export const make = Effect.gen(function* () {
),
stepResult: Effect.fn("WorkflowStore.stepResult")(function* (runId, name, value, said) {
const full = jsonText(value);
const kept =
full.length <= STEP_RESULT_KEPT ? full : jsonText(`${full.slice(0, STEP_RESULT_KEPT)}…`);
const kept = full.length <= STEP_RESULT_KEPT ? full : jsonText(stepResultCut(full));
const words = said?.trim() ?? "";
const keptSaid =
words === ""
? null
: words.length <= STEP_RESULT_KEPT
? words
: `${words.slice(0, STEP_RESULT_KEPT)}…`;
words === "" ? null : words.length <= STEP_RESULT_KEPT ? words : stepResultCut(words);
yield* sql`
UPDATE workflow_steps SET result_json = ${kept}, said = ${keptSaid}
WHERE run_id = ${runId} AND name = ${name}
Expand Down
Loading