Skip to content

Commit da1eab0

Browse files
t3dotggclaude
andauthored
chore: make agent mistakes fail early (#26167)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 6d82a22 commit da1eab0

19 files changed

Lines changed: 490 additions & 570 deletions

‎.github/workflows/agent-context-budget.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,5 @@ jobs:
5151
echo "Accepted by the agent-context-increase label."
5252
exit 0
5353
fi
54-
echo "::error file=$BUDGET::Agent context grew compared to main. Cut the added text, or ask a maintainer to add the agent-context-increase label."
54+
echo "::error file=$BUDGET::Agent context grew compared to main. Cut the added text and rerun the evals that cover it (evals/README.md), or ask a maintainer to add the agent-context-increase label."
5555
exit 1

‎AGENTS.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ An empty database is a bad test. Seed your worktree's `.t3` with a copy of real
9898

9999
## Verifying
100100

101-
- Before you push, run `vp run check:changed`. It runs CI's fast checks for changed files: format, lint, knip, typecheck of affected packages and dependents, and tests beside changes. CI still runs the full test suites.
101+
- Before you push, run `vp run check:changed`. It runs CI's fast checks for changed files: format, lint, knip, typecheck of affected packages and dependents, tests beside changes, and the cross-file checks those miss. CI still runs the full test suites.
102102
- While you iterate, run `vp test run <files>`. For big files, add `-t "<name>"`.
103103
- Use `vp run typecheck`, not `npx tsc`; it caches per package. Both run tsc-rs (`typescript` is the `@tsc-rs/typescript` drop-in).
104104
- Run `node -e` snippets from `apps/server` or the owning package. `effect` does not resolve from the repo root.

‎apps/mobile/src/features/threads/PendingUserInputCard.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ import { useMarkdownPreviewStyles } from "../files/FileMarkdownPreview";
2626
import { useLiveThreadLinkLabels } from "../../state/entities";
2727
import {
2828
isPendingUserInputOptionSelected,
29-
type PendingUserInput,
3029
type PendingUserInputDraftAnswer,
31-
} from "../../lib/threadActivity";
30+
} from "@t3tools/client-runtime/state/pending-user-input";
31+
import type { PendingUserInput } from "../../lib/threadActivity";
3232

3333
export interface PendingUserInputCardProps {
3434
readonly environmentId: EnvironmentId;

‎apps/mobile/src/features/threads/ThreadDetailScreen.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,10 @@ import { appAtomRegistry } from "../../state/atom-registry";
157157
import { threadStreamHaptics } from "./threadStreamHaptics";
158158
import { useAtomCommand } from "../../state/use-atom-command";
159159
import { useDelayedStatus } from "../../lib/useDelayedStatus";
160+
import type { PendingUserInputDraftAnswer } from "@t3tools/client-runtime/state/pending-user-input";
160161
import type {
161162
PendingApproval,
162163
PendingUserInput,
163-
PendingUserInputDraftAnswer,
164164
ThreadFeedEntry,
165165
ThreadFeedLatestRun,
166166
} from "../../lib/threadActivity";

‎apps/mobile/src/lib/threadActivity.test.ts‎

Lines changed: 0 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@ import {
3131
type ThreadFeedCache,
3232
type ThreadFeedEntry,
3333
type ThreadFeedLatestRun,
34-
togglePendingUserInputOptionSelection,
35-
setPendingUserInputCustomAnswer,
36-
isPendingUserInputOptionSelected,
37-
buildPendingUserInputAnswers,
3834
} from "./threadActivity";
3935

4036
const threadId = ThreadId.make("thread-1");
@@ -1368,17 +1364,6 @@ describe("retained v2 feed presentation", () => {
13681364
});
13691365
});
13701366

1371-
const singleSelectQuestion = {
1372-
id: "runtime",
1373-
header: "Runtime",
1374-
question: "Which runtime should be used?",
1375-
options: [
1376-
{ label: "Go", description: "One binary" },
1377-
{ label: "Node.js", description: "Reuse TypeScript" },
1378-
],
1379-
multiSelect: false,
1380-
} as const;
1381-
13821367
describe("subagent continued by a later turn", () => {
13831368
const run2 = RunId.make("run-2");
13841369
const at = (second: number) => `2026-10-09T10:00:${String(second).padStart(2, "0")}.000Z`;
@@ -1454,95 +1439,6 @@ describe("subagent continued by a later turn", () => {
14541439
});
14551440
});
14561441

1457-
describe("pending user input answers", () => {
1458-
it("preserves exact editor text, including a deliberately cleared answer", () => {
1459-
const question = { ...singleSelectQuestion, initialAnswer: " Proposed message\n" };
1460-
expect(
1461-
buildPendingUserInputAnswers([question], {
1462-
runtime: { customAnswer: question.initialAnswer },
1463-
}),
1464-
).toEqual({ runtime: question.initialAnswer });
1465-
expect(
1466-
buildPendingUserInputAnswers([question], {
1467-
runtime: { customAnswer: " Edited message\n\n" },
1468-
}),
1469-
).toEqual({ runtime: " Edited message\n\n" });
1470-
expect(buildPendingUserInputAnswers([question], { runtime: { customAnswer: "" } })).toEqual({
1471-
runtime: "",
1472-
});
1473-
expect(buildPendingUserInputAnswers([question], { runtime: { customAnswer: " \n" } })).toEqual({
1474-
runtime: " \n",
1475-
});
1476-
expect(setPendingUserInputCustomAnswer(question, { selectedOptionValues: ["Go"] }, "")).toEqual(
1477-
{ customAnswer: "" },
1478-
);
1479-
});
1480-
});
1481-
1482-
describe("provider question values", () => {
1483-
const question = {
1484-
...singleSelectQuestion,
1485-
allowCustomAnswer: false,
1486-
options: [
1487-
{ label: "Same label", value: " exact first ", description: "First" },
1488-
{ label: "Same label", value: "second", description: "Second" },
1489-
],
1490-
} as const;
1491-
1492-
it("submits raw option values and distinguishes duplicate labels", () => {
1493-
const first = togglePendingUserInputOptionSelection(question, undefined, " exact first ");
1494-
expect(isPendingUserInputOptionSelected(question, first, " exact first ")).toBe(true);
1495-
expect(isPendingUserInputOptionSelected(question, first, "second")).toBe(false);
1496-
expect(buildPendingUserInputAnswers([question], { runtime: first })).toEqual({
1497-
runtime: " exact first ",
1498-
});
1499-
expect(togglePendingUserInputOptionSelection(question, first, "Same label")).toBe(first);
1500-
});
1501-
1502-
it("rejects arbitrary text when the provider only accepts offered options", () => {
1503-
expect(setPendingUserInputCustomAnswer(question, undefined, "Other")).toEqual({});
1504-
expect(
1505-
buildPendingUserInputAnswers([question], { runtime: { customAnswer: "Other" } }),
1506-
).toBeNull();
1507-
expect(
1508-
buildPendingUserInputAnswers([question], { runtime: { selectedOptionValues: ["unknown"] } }),
1509-
).toBeNull();
1510-
expect(
1511-
buildPendingUserInputAnswers([question], {
1512-
runtime: { selectedOptionValues: ["second"], customAnswer: "stale draft" },
1513-
}),
1514-
).toEqual({ runtime: "second" });
1515-
});
1516-
});
1517-
1518-
it("accepts ready attachment-only answers while preserving selected options", () => {
1519-
const question = {
1520-
id: "q",
1521-
header: "Spec",
1522-
question: "Provide a specification",
1523-
options: [{ label: "Yes", description: "Approve" }],
1524-
multiSelect: false,
1525-
};
1526-
expect(buildPendingUserInputAnswers([question], { q: { attachmentCount: 1 } })).toEqual({
1527-
q: "",
1528-
});
1529-
expect(
1530-
buildPendingUserInputAnswers([question], {
1531-
q: { attachmentCount: 1, selectedOptionValues: ["Yes"] },
1532-
}),
1533-
).toEqual({ q: "Yes" });
1534-
expect(
1535-
buildPendingUserInputAnswers([question], {
1536-
q: { attachmentCount: 1, attachmentsBlocked: true },
1537-
}),
1538-
).toBeNull();
1539-
expect(
1540-
buildPendingUserInputAnswers([{ ...question, allowCustomAnswer: false }], {
1541-
q: { attachmentCount: 1 },
1542-
}),
1543-
).toBeNull();
1544-
});
1545-
15461442
it("stops stranded thinking after a steer and follows the next thought or tool", () => {
15471443
const at = "2026-06-20T00:00:02.000Z";
15481444
const thought = (id: string): OrchestrationV2TurnItem => ({

‎apps/mobile/src/lib/threadActivity.ts‎

Lines changed: 0 additions & 162 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import type {
22
ThreadPendingApproval,
33
ThreadPendingUserInput,
4-
ThreadUserInputQuestion,
54
} from "@t3tools/client-runtime/state/thread-requests";
65
import { turnItemIsWorkspacePreparation } from "@t3tools/client-runtime/state/turn-item-presentation";
76
import type { ThreadCheckpointSummary } from "@t3tools/client-runtime/state/thread-checkpoints";
@@ -81,13 +80,6 @@ import {
8180
export type PendingApproval = ThreadPendingApproval;
8281
export type PendingUserInput = ThreadPendingUserInput;
8382

84-
export interface PendingUserInputDraftAnswer {
85-
readonly selectedOptionValues?: ReadonlyArray<string>;
86-
readonly customAnswer?: string;
87-
readonly attachmentCount?: number;
88-
readonly attachmentsBlocked?: boolean;
89-
}
90-
9183
export interface ThreadFeedActivity {
9284
readonly id: string;
9385
readonly createdAt: string;
@@ -406,73 +398,6 @@ function isUserInputActivityGroup(entry: ThreadFeedActivityGroup): boolean {
406398
return entry.activities.some((activity) => activity.workEntry.questionAnswer !== undefined);
407399
}
408400

409-
function normalizeDraftAnswer(value: string | undefined): string | null {
410-
if (typeof value !== "string") return null;
411-
const trimmed = value.trim();
412-
return trimmed.length > 0 ? trimmed : null;
413-
}
414-
415-
function resolvePendingUserInputOptionValue(
416-
question: ThreadUserInputQuestion,
417-
value: string,
418-
): string | null {
419-
if (question.options.some((option) => option.value === value)) {
420-
return value;
421-
}
422-
423-
const label = value.trim();
424-
return label.length > 0 &&
425-
question.options.some((option) => option.value === undefined && option.label.trim() === label)
426-
? label
427-
: null;
428-
}
429-
430-
function normalizeSelectedOptionValues(
431-
question: ThreadUserInputQuestion,
432-
value: ReadonlyArray<string> | undefined,
433-
): ReadonlyArray<string> {
434-
if (!Array.isArray(value)) {
435-
return [];
436-
}
437-
438-
return Array.from(
439-
new Set(
440-
value
441-
.map((entry) => resolvePendingUserInputOptionValue(question, entry))
442-
.filter((entry): entry is string => entry !== null),
443-
),
444-
);
445-
}
446-
447-
function resolvePendingUserInputAnswer(
448-
question: ThreadUserInputQuestion,
449-
draft: PendingUserInputDraftAnswer | undefined,
450-
): string | ReadonlyArray<string> | null {
451-
if (draft?.attachmentsBlocked) return null;
452-
const customAnswer =
453-
question.allowCustomAnswer === false
454-
? null
455-
: question.initialAnswer !== undefined
456-
? (draft?.customAnswer ?? null)
457-
: normalizeDraftAnswer(draft?.customAnswer);
458-
if (customAnswer !== null && customAnswer.length > 0) {
459-
return customAnswer;
460-
}
461-
462-
const selectedOptionValues = normalizeSelectedOptionValues(question, draft?.selectedOptionValues);
463-
if (question.multiSelect) {
464-
return selectedOptionValues.length > 0
465-
? selectedOptionValues
466-
: (customAnswer ??
467-
(question.allowCustomAnswer !== false && (draft?.attachmentCount ?? 0) > 0 ? "" : null));
468-
}
469-
return (
470-
selectedOptionValues[0] ??
471-
customAnswer ??
472-
(question.allowCustomAnswer !== false && (draft?.attachmentCount ?? 0) > 0 ? "" : null)
473-
);
474-
}
475-
476401
function capitalizePhrase(value: string): string {
477402
const trimmed = value.trim();
478403
return trimmed.length === 0 ? value : `${trimmed.charAt(0).toUpperCase()}${trimmed.slice(1)}`;
@@ -1974,93 +1899,6 @@ function liveToolActivitySummary(activity: ThreadFeedActivity, presentTense: boo
19741899
return activity.detail ?? activity.summary;
19751900
}
19761901

1977-
export function setPendingUserInputCustomAnswer(
1978-
question: ThreadUserInputQuestion,
1979-
draft: PendingUserInputDraftAnswer | undefined,
1980-
customAnswer: string,
1981-
): PendingUserInputDraftAnswer {
1982-
if (question.allowCustomAnswer === false) {
1983-
return draft ?? {};
1984-
}
1985-
1986-
const selectedOptionValues =
1987-
question.initialAnswer !== undefined || customAnswer.trim().length > 0
1988-
? undefined
1989-
: normalizeSelectedOptionValues(question, draft?.selectedOptionValues);
1990-
return {
1991-
customAnswer,
1992-
...(selectedOptionValues && selectedOptionValues.length > 0 ? { selectedOptionValues } : {}),
1993-
};
1994-
}
1995-
1996-
export function isPendingUserInputOptionSelected(
1997-
question: ThreadUserInputQuestion,
1998-
draft: PendingUserInputDraftAnswer | undefined,
1999-
optionValue: string,
2000-
): boolean {
2001-
if (question.allowCustomAnswer !== false && normalizeDraftAnswer(draft?.customAnswer)) {
2002-
return false;
2003-
}
2004-
2005-
const resolvedOptionValue = resolvePendingUserInputOptionValue(question, optionValue);
2006-
return (
2007-
resolvedOptionValue !== null &&
2008-
normalizeSelectedOptionValues(question, draft?.selectedOptionValues).includes(
2009-
resolvedOptionValue,
2010-
)
2011-
);
2012-
}
2013-
2014-
export function togglePendingUserInputOptionSelection(
2015-
question: ThreadUserInputQuestion,
2016-
draft: PendingUserInputDraftAnswer | undefined,
2017-
optionValue: string,
2018-
): PendingUserInputDraftAnswer {
2019-
const resolvedOptionValue = resolvePendingUserInputOptionValue(question, optionValue);
2020-
if (resolvedOptionValue === null) {
2021-
return draft ?? {};
2022-
}
2023-
2024-
if (question.multiSelect) {
2025-
const selectedOptionValues = normalizeSelectedOptionValues(
2026-
question,
2027-
draft?.selectedOptionValues,
2028-
);
2029-
const nextSelectedOptionValues = selectedOptionValues.includes(resolvedOptionValue)
2030-
? selectedOptionValues.filter((value) => value !== resolvedOptionValue)
2031-
: [...selectedOptionValues, resolvedOptionValue];
2032-
2033-
return {
2034-
customAnswer: "",
2035-
...(nextSelectedOptionValues.length > 0
2036-
? { selectedOptionValues: nextSelectedOptionValues }
2037-
: {}),
2038-
};
2039-
}
2040-
2041-
return {
2042-
customAnswer: "",
2043-
selectedOptionValues: [resolvedOptionValue],
2044-
};
2045-
}
2046-
2047-
export function buildPendingUserInputAnswers(
2048-
questions: ReadonlyArray<ThreadUserInputQuestion>,
2049-
draftAnswers: Record<string, PendingUserInputDraftAnswer>,
2050-
): Record<string, string | ReadonlyArray<string>> | null {
2051-
const answers: Record<string, string | ReadonlyArray<string>> = {};
2052-
2053-
for (const question of questions) {
2054-
const answer = resolvePendingUserInputAnswer(question, draftAnswers[question.id]);
2055-
if (answer === null) {
2056-
return null;
2057-
}
2058-
answers[question.id] = answer;
2059-
}
2060-
2061-
return answers;
2062-
}
2063-
20641902
interface ThreadFeedBuild {
20651903
readonly rows: ReadonlyArray<OrchestrationV2ProjectedTurnItem>;
20661904
readonly attempts: ReadonlyArray<OrchestrationV2RunAttempt> | undefined;

‎apps/mobile/src/state/use-selected-thread-requests.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import {
4242
setPendingUserInputCustomAnswer,
4343
togglePendingUserInputOptionSelection,
4444
type PendingUserInputDraftAnswer,
45-
} from "../lib/threadActivity";
45+
} from "@t3tools/client-runtime/state/pending-user-input";
4646
import { appAtomRegistry } from "./atom-registry";
4747
import { useSelectedThreadPendingRequests } from "./use-thread-detail";
4848
import { useThreadSelection } from "./use-thread-selection";

‎apps/server/src/provider/AgentContextBudget.test.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,10 @@ it.effect("agent context matches the committed budget", () =>
123123
),
124124
};
125125

126-
expect(measured).toEqual(budget);
126+
expect(
127+
measured,
128+
"Set agentContextBudget.json to the measured values. Before you cut text to fit, run the evals that cover it (evals/README.md).",
129+
).toEqual(budget);
127130
}).pipe(
128131
Effect.provide(
129132
McpHttpServer.layerTools.pipe(

‎apps/web/src/components/chat/ChatComposer.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ import {
241241
type ThreadShell,
242242
} from "../../types";
243243
import { type ComposerPromptHistoryPosition } from "./composerPromptHistory";
244-
import type { PendingUserInputDraftAnswer } from "../../pendingUserInput";
244+
import type { PendingUserInputDraftAnswer } from "@t3tools/client-runtime/state/pending-user-input";
245245
import type {
246246
LatestProposedPlanState,
247247
PendingApproval,

‎apps/web/src/components/chat/ComposerPendingUserInputPanel.tsx‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@ import { memo, use, useEffect, useEffectEvent, useRef, useState } from "react";
33
import { BackgroundThreadContext } from "./backgroundThread";
44
import { useStableCallback } from "~/hooks/useStableCallback";
55
import { type PendingUserInput } from "../../session-logic";
6-
import {
7-
derivePendingUserInputProgress,
8-
type PendingUserInputDraftAnswer,
9-
} from "../../pendingUserInput";
6+
import type { PendingUserInputDraftAnswer } from "@t3tools/client-runtime/state/pending-user-input";
7+
import { derivePendingUserInputProgress } from "../../pendingUserInput";
108
import { CheckboxMark } from "../ui/checkbox";
119
import { Collapsible, CollapsiblePanel, CollapsibleTrigger } from "../ui/collapsible";
1210
import { Kbd } from "../ui/kbd";

0 commit comments

Comments
 (0)