GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(server): reject oversized goal objectives before dispatch (#23033) · pingdotgg/t3code@42ca7c0

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps/server/src/orchestration-v2
    • Adapters
      • CodexAdapterV2.test.ts
      • CodexAdapterV2.ts
    • RunExecutionService.test.ts
  • packages
    • effect-codex-app-server/src
      • schema.ts
    • provider-core/src/server
      • failure.test.ts
      • failure.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.test.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.test.ts
+102Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { historyResponseItems } from "@t3tools/provider-core/server/handoffBudget";
2+
import { makeProviderFailure } from "@t3tools/provider-core/server/failure";
23
import {
34
makeProviderTextDeltaCoalescer,
45
type ProviderTextDeltaUpdate,
@@ -8184,6 +8185,107 @@ describe("CodexAdapterV2 post-settle continuation", () => {
81848185
),
81858186
);
81868187

8188+
it.effect("rejects an oversized /goal objective before any goal request", () =>
8189+
Effect.gen(function* () {
8190+
const oversized = "x".repeat(4001);
8191+
const requests: string[] = [];
8192+
const harness = yield* makeCodexReplayHarness(
8193+
makeCodexReplayTranscript({ scenario: "goal-oversized", entries: sessionStart }),
8194+
() => Effect.void,
8195+
(method) =>
8196+
Effect.sync(() => {
8197+
requests.push(method);
8198+
}),
8199+
);
8200+
const start = yield* harness.runtime
8201+
.startTurn(yield* goalTurnInput(harness, `/goal ${oversized}`))
8202+
.pipe(Effect.result);
8203+
8204+
assert.deepEqual(
8205+
requests.filter((method) => method.startsWith("thread/goal/") || method === "turn/start"),
8206+
[],
8207+
);
8208+
assert.equal(start._tag, "Failure");
8209+
if (start._tag === "Failure") {
8210+
const { message } = makeProviderFailure({ cause: start.failure });
8211+
assert.match(message, /4,?001/u);
8212+
assert.match(message, /4,?000/u);
8213+
}
8214+
}).pipe(
8215+
Effect.scoped,
8216+
Effect.provide(
8217+
Layer.mergeAll(
8218+
IdAllocator.layer,
8219+
McpProviderSessions.layer,
8220+
NodeServices.layer,
8221+
NodeCrypto.layer,
8222+
),
8223+
),
8224+
),
8225+
);
8226+
8227+
it.effect("sends a /goal objective at the 4000 character limit unchanged", () =>
8228+
Effect.gen(function* () {
8229+
const atLimit = "y".repeat(4000);
8230+
const goal = (status: string) => ({ ...codexGoal(status, 0), objective: atLimit });
8231+
const transcript = makeCodexReplayTranscript({
8232+
scenario: "goal-at-limit",
8233+
entries: [
8234+
...sessionStart,
8235+
...request(3, "thread/goal/get", { threadId: nativeThreadId }, { goal: null }),
8236+
...request(
8237+
4,
8238+
"thread/goal/set",
8239+
{ threadId: nativeThreadId, objective: atLimit, status: "paused" },
8240+
{ goal: goal("paused") },
8241+
),
8242+
...withReplayRequestId(
8243+
codexReplayPreamble({
8244+
nativeThreadId,
8245+
nativeTurnId: "goal-turn-limit",
8246+
prompt: atLimit,
8247+
sentPrompt: `Start working toward this goal: ${atLimit}`,
8248+
}).slice(5),
8249+
5,
8250+
),
8251+
...request(
8252+
6,
8253+
"thread/goal/set",
8254+
{ threadId: nativeThreadId, status: "active" },
8255+
{ goal: goal("active") },
8256+
),
8257+
notification("goal complete", "thread/goal/updated", {
8258+
threadId: nativeThreadId,
8259+
turnId: "goal-turn-limit",
8260+
goal: goal("complete"),
8261+
}),
8262+
notification("turn done", "turn/completed", {
8263+
threadId: nativeThreadId,
8264+
turn: makeCodexReplayTurn({ id: "goal-turn-limit", status: "completed" }),
8265+
}),
8266+
],
8267+
});
8268+
const harness = yield* makeCodexReplayHarness(transcript);
8269+
yield* harness.runtime.startTurn(yield* goalTurnInput(harness, `/goal ${atLimit}`));
8270+
yield* harness.firstTerminal;
8271+
8272+
assert.deepEqual(
8273+
harness.terminalEvents().map((event) => event.status),
8274+
["completed"],
8275+
);
8276+
}).pipe(
8277+
Effect.scoped,
8278+
Effect.provide(
8279+
Layer.mergeAll(
8280+
IdAllocator.layer,
8281+
McpProviderSessions.layer,
8282+
NodeServices.layer,
8283+
NodeCrypto.layer,
8284+
),
8285+
),
8286+
),
8287+
);
8288+
81878289
it.effect("settles a run held for the next goal turn when Stop arrives in between", () =>
81888290
Effect.gen(function* () {
81898291
const prompt = "Keep going";
Collapse file

‎apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts
+23Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -900,6 +900,28 @@ const isTerminalProviderTurn = (turn: OrchestrationV2ProviderTurn): boolean =>
900900
turn.status === "failed" ||
901901
turn.status === "cancelled");
902902

903+
class CodexGoalObjectiveTooLongError extends Schema.TaggedError<CodexGoalObjectiveTooLongError>()(
904+
"CodexGoalObjectiveTooLongError",
905+
{ length: Schema.Number, limit: Schema.Number },
906+
) {
907+
override get message() {
908+
return `The goal objective is ${this.length} characters; Codex supports at most ${this.limit}. Shorten it and send /goal again. The current goal was not changed.`;
909+
}
910+
}
911+
912+
function validateCodexGoalObjective(objective: string) {
913+
let length = 0;
914+
for (const _ of objective) length++;
915+
return length > CodexSchema.MAX_THREAD_GOAL_OBJECTIVE_CHARS
916+
? Effect.fail(
917+
new CodexGoalObjectiveTooLongError({
918+
length,
919+
limit: CodexSchema.MAX_THREAD_GOAL_OBJECTIVE_CHARS,
920+
}),
921+
)
922+
: Effect.void;
923+
}
924+
903925
type CodexThreadGoal = CodexSchema.V2ThreadGoalUpdatedNotification["goal"];
904926

905927
const CODEX_GOAL_STATUSES = {
@@ -6801,6 +6823,7 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
68016823
turnInput: ProviderAdapter.ProviderAdapterV2TurnInput,
68026824
command: OrchestrationV2GoalCommand,
68036825
) {
6826+
if (command.type === "set") yield* validateCodexGoalObjective(command.objective);
68046827
const threadId = yield* getNativeThreadId(turnInput.providerThread);
68056828
rootProviderThreads.set(threadId, turnInput.providerThread);
68066829
const readGoal = client
Collapse file

‎apps/server/src/orchestration-v2/RunExecutionService.test.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/RunExecutionService.test.ts
+30Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import * as Layer from "effect/Layer";
3636
import * as Option from "effect/Option";
3737
import * as Ref from "effect/Ref";
3838
import * as Stream from "effect/Stream";
39+
import { CodexAppServerRequestError } from "effect-codex-app-server/errors";
3940
import { SqlError, classifySqliteError } from "effect/sql/SqlError";
4041

4142
import { toPersistenceSqlError } from "../persistence/Errors.ts";
@@ -2686,6 +2687,35 @@ it.effect("refreshes pull requests after a provider stream exits with an error",
26862687
}),
26872688
);
26882689

2690+
it.effect("records a provider's input rejection at turn start in the terminal error", () =>
2691+
Effect.gen(function* () {
2692+
const rejection = "goal objective must be at most 4000 characters";
2693+
const { written, observed } = yield* captureRootRunTermination({
2694+
key: "start-failure:input-rejected",
2695+
shouldFinalizeRun: () => Effect.succeed(true),
2696+
events: () => Stream.never,
2697+
afterStart: (closed) => Deferred.succeed(closed, undefined),
2698+
startTurn: (turnInput) =>
2699+
Effect.fail(
2700+
new ProviderAdapter.ProviderAdapterTurnStartError({
2701+
driver,
2702+
threadId: turnInput.threadId,
2703+
providerThreadId: turnInput.providerThread.id,
2704+
runId: turnInput.runId,
2705+
cause: new CodexAppServerRequestError({
2706+
code: -32600,
2707+
errorMessage: rejection,
2708+
method: "thread/goal/set",
2709+
}),
2710+
}),
2711+
),
2712+
});
2713+
assert.deepEqual(observed, ["run:failed", "pull-requests-refreshed"]);
2714+
const error = written.find((item) => item.type === "error");
2715+
assert.include(error?.failure.message ?? "", rejection);
2716+
}),
2717+
);
2718+
26892719
it.effect.each(["failure", "defect", "interrupt-failure", "ownership-lost"] as const)(
26902720
"stops the live provider and background work before settling an ingestion %s",
26912721
(failureMode) =>
Collapse file

‎packages/effect-codex-app-server/src/schema.ts‎

Copy file name to clipboard
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
export * from "./_generated/schema.gen.ts";
22
export * from "./_generated/meta.gen.ts";
33
export * from "./_generated/namespaces.gen.ts";
4+
5+
// Mirrors codex_protocol::protocol::MAX_THREAD_GOAL_OBJECTIVE_CHARS, which the
6+
// generated schema does not carry. Codex counts Unicode scalar values (Rust
7+
// `chars()`), not UTF-16 code units.
8+
export const MAX_THREAD_GOAL_OBJECTIVE_CHARS = 4_000;
Collapse file

‎packages/provider-core/src/server/failure.test.ts‎

Copy file name to clipboardExpand all lines: packages/provider-core/src/server/failure.test.ts
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,16 @@ it("keeps unrecognized reasons and provider text out of category messages", () =
146146
{ _tag: "ProviderAdapterProtocolError", reason: "private-config" },
147147
{ _tag: "ProviderAdapterProtocolError", reason: "constructor" },
148148
{ _tag: "constructor", cause: "private-config" },
149+
{
150+
_tag: "CodexAppServerRequestError",
151+
method: "thread/goal/set",
152+
message: "thread not found: private-thread",
153+
},
154+
{
155+
_tag: "CodexAppServerRequestError",
156+
method: "turn/start",
157+
message: "goal objective must be at most 4000 characters",
158+
},
149159
]) {
150160
assert.equal(
151161
makeProviderFailure({ cause: { _tag: "ProviderAdapterTurnStartError", cause } }).message,
Collapse file

‎packages/provider-core/src/server/failure.ts‎

Copy file name to clipboardExpand all lines: packages/provider-core/src/server/failure.ts
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ const PROVIDER_FAILURE_CATEGORIES: Partial<
6161
},
6262
};
6363

64+
// codex_protocol::protocol::validate_thread_goal_objective
65+
const CODEX_GOAL_VALIDATION_MESSAGE =
66+
/^goal objective must (?:not be empty|be at most \d{1,6} characters)$/u;
67+
6468
const PROVIDER_FAILURE_REASONS: Record<ProviderAdapterFailureReason, string> = {
6569
previous_turn_active: "the previous turn is still running",
6670
attachment_unreadable: "an attachment could not be read",
@@ -108,8 +112,22 @@ function curatedCauseMessages(cause: unknown): {
108112
case "ClaudeSettingsLaunchArgError":
109113
case "ClaudeMcpRegistrationTimeoutError":
110114
case "CursorModelUnavailableError":
115+
case "CodexGoalObjectiveTooLongError":
111116
case "ProviderSetupError":
112117
return { known: stringField(cause, "message"), category: categoryMessage() };
118+
case "CodexAppServerRequestError": {
119+
// Only Codex's fixed-shape goal validation text is actionable and
120+
// safe to show; other request error text stays hidden.
121+
const rejection = stringField(cause, "message");
122+
if (
123+
(cause as Record<string, unknown>).method === "thread/goal/set" &&
124+
rejection !== undefined &&
125+
CODEX_GOAL_VALIDATION_MESSAGE.test(rejection)
126+
) {
127+
return { known: `Codex rejected the goal: ${rejection}.`, category: categoryMessage() };
128+
}
129+
break;
130+
}
113131
case "AcpProcessExitedError": {
114132
const exit = `provider process exited${processExitStatus(cause)}`;
115133
const stage = category === undefined ? `The ${exit}` : `${category.summary}: the ${exit}`;

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.