Skip to content

Commit d5aff66

Browse files
authored
fix(codex): keep large AGENTS.md instructions visible (#125966)
* fix(codex): raise native project doc budget Default OpenClaw Codex threads to a bounded 128 KiB aggregate project-document budget so large AGENTS.md chains remain visible. Preserve explicit ordinary-thread overrides and keep restricted or lightweight turns at zero. * test(codex): refresh project doc config expectations
1 parent d1f58c4 commit d5aff66

13 files changed

Lines changed: 75 additions & 13 deletions

‎docs/plugins/codex-harness.md‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,18 @@ Changing auth order does not make a custom, Completions, HTTP, or
254254
request-overridden route Codex-compatible. Valid model-scoped Fast-mode and
255255
cutoff controls are runtime controls, not request overrides.
256256

257+
### Project instructions
258+
259+
Codex loads `AGENTS.md` files through native project-document discovery. For
260+
normal app-server threads, OpenClaw raises Codex's aggregate root-to-working-
261+
directory budget from the upstream 32 KiB default to a bounded 128 KiB so later
262+
scoped instructions are not silently clipped. Lightweight and restricted turns
263+
set the native project-document budget to zero instead.
264+
265+
This byte budget is separate from the character-based workspace bootstrap
266+
limits configured through `agents.defaults.bootstrapMaxChars` and
267+
`agents.defaults.bootstrapTotalMaxChars`.
268+
257269
### Compaction
258270

259271
Do not set `compaction.model` or `compaction.provider` on Codex-backed

‎extensions/codex/media-understanding-provider.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ describe("codex media understanding provider", () => {
330330
"features.multi_agent_v2": false,
331331
"features.plugins": false,
332332
"features.standalone_web_search": false,
333+
project_doc_max_bytes: 131_072,
333334
"tools.update_plan.enabled": false,
334335
web_search: "disabled",
335336
},
@@ -676,6 +677,7 @@ describe("codex media understanding provider", () => {
676677
"features.multi_agent_v2": false,
677678
"features.plugins": false,
678679
"features.standalone_web_search": false,
680+
project_doc_max_bytes: 131_072,
679681
"tools.update_plan.enabled": false,
680682
web_search: "disabled",
681683
},

‎extensions/codex/src/app-server/bounded-turn.test.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,9 @@ describe("runBoundedCodexAppServerTurn settled finalization isolation", () => {
367367
isolation: "private-stdio",
368368
}),
369369
).rejects.toThrow("hosted search turn returned no text");
370+
371+
const startParams = fake.request.mock.calls.find(([method]) => method === "thread/start")?.[1];
372+
expect(startParams).toMatchObject({ config: { project_doc_max_bytes: 131_072 } });
370373
});
371374

372375
it("still fails on a terminal error notification", async () => {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { mergeCodexThreadConfigs } from "./plugin-thread-config.js";
2+
import type { JsonObject } from "./protocol.js";
3+
4+
const CODEX_NATIVE_PROJECT_DOC_MAX_BYTES = 128 * 1024;
5+
6+
export function buildCodexProjectDocThreadConfig(config?: JsonObject): JsonObject {
7+
const defaults: JsonObject = { project_doc_max_bytes: CODEX_NATIVE_PROJECT_DOC_MAX_BYTES };
8+
return mergeCodexThreadConfigs(defaults, config) ?? defaults;
9+
}

‎extensions/codex/src/app-server/side-question.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,7 @@ describe("runCodexAppServerSideQuestion", () => {
663663
expect(forkParams?.approvalsReviewer).toBe("user");
664664
expect(forkParams?.cwd).toBe("/tmp/workspace");
665665
expect(forkParams?.config).toEqual({
666+
project_doc_max_bytes: 131_072,
666667
"features.goals": false,
667668
"tools.update_plan.enabled": false,
668669
"features.code_mode": true,

‎extensions/codex/src/app-server/thread-lifecycle.binding.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ function createParams(sessionFile: string, workspaceDir: string) {
114114
}
115115

116116
const DEFAULT_CODEX_RUNTIME_THREAD_CONFIG = {
117+
project_doc_max_bytes: 131_072,
117118
"features.goals": false,
118119
"tools.update_plan.enabled": false,
119120
"features.code_mode": true,

‎extensions/codex/src/app-server/thread-lifecycle.test.ts‎

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -360,13 +360,15 @@ describe("Codex ring-zero thread config", () => {
360360
dynamicTools: [],
361361
hostSystemAgentActive: true,
362362
nativeCodeModeEnabled: false,
363+
config: { project_doc_max_bytes: 64_000 },
363364
});
364365
const resume = buildThreadResumeParams(params, {
365366
appServer,
366367
dynamicTools: [],
367368
hostSystemAgentActive: true,
368369
nativeCodeModeEnabled: false,
369370
threadId: "thread-1",
371+
config: { project_doc_max_bytes: 64_000 },
370372
});
371373

372374
expect(start.environments).toEqual([]);
@@ -1434,6 +1436,7 @@ describe("Codex app-server native code mode config", () => {
14341436
});
14351437

14361438
expect(request.config).toEqual({
1439+
project_doc_max_bytes: 131_072,
14371440
"features.hooks": true,
14381441
apps: { _default: { enabled: false } },
14391442
mcp_servers: {
@@ -1588,6 +1591,7 @@ describe("Codex app-server native code mode config", () => {
15881591
);
15891592

15901593
expect(request.config).toEqual({
1594+
project_doc_max_bytes: 131_072,
15911595
"features.code_mode": true,
15921596
"features.code_mode_only": false,
15931597
"features.goals": false,
@@ -1717,6 +1721,7 @@ describe("Codex app-server native code mode config", () => {
17171721
});
17181722

17191723
expect(request.config).toEqual({
1724+
project_doc_max_bytes: 131_072,
17201725
"features.code_mode": true,
17211726
"features.code_mode_only": true,
17221727
"features.goals": false,
@@ -1740,6 +1745,7 @@ describe("Codex app-server native code mode config", () => {
17401745
});
17411746

17421747
expect(request.config).toEqual({
1748+
project_doc_max_bytes: 131_072,
17431749
"features.code_mode": true,
17441750
"features.code_mode_only": true,
17451751
"features.goals": false,
@@ -1799,6 +1805,7 @@ describe("Codex app-server native code mode config", () => {
17991805
});
18001806

18011807
expect(request.config).toEqual({
1808+
project_doc_max_bytes: 131_072,
18021809
"features.code_mode": true,
18031810
"features.code_mode_only": false,
18041811
"features.goals": false,
@@ -1825,6 +1832,7 @@ describe("Codex app-server native code mode config", () => {
18251832
});
18261833

18271834
expect(request.config).toEqual({
1835+
project_doc_max_bytes: 131_072,
18281836
"features.code_mode": false,
18291837
"features.code_mode_only": false,
18301838
"features.goals": false,
@@ -1846,6 +1854,7 @@ describe("Codex app-server native code mode config", () => {
18461854
});
18471855

18481856
expect(request.config).toEqual({
1857+
project_doc_max_bytes: 131_072,
18491858
"features.code_mode": false,
18501859
"features.code_mode_only": false,
18511860
"features.goals": false,
@@ -1887,8 +1896,17 @@ describe("Codex app-server native code mode config", () => {
18871896
});
18881897
});
18891898

1890-
it("keeps native Codex project docs enabled when context is not lightweight", () => {
1891-
const request = buildThreadResumeParams(
1899+
it("defaults native Codex project docs to 128 KiB while honoring explicit overrides", () => {
1900+
const defaultRequest = buildThreadStartParams(
1901+
createAttemptParams({ provider: "openai", bootstrapContextRunKind: "cron" }),
1902+
{
1903+
cwd: "/repo",
1904+
dynamicTools: [],
1905+
appServer: createAppServerOptions() as never,
1906+
developerInstructions: "test instructions",
1907+
},
1908+
);
1909+
const overrideRequest = buildThreadResumeParams(
18921910
createAttemptParams({ provider: "openai", bootstrapContextRunKind: "cron" }),
18931911
{
18941912
threadId: "thread-1",
@@ -1900,7 +1918,8 @@ describe("Codex app-server native code mode config", () => {
19001918
},
19011919
);
19021920

1903-
expect(request.config).toEqual({
1921+
expect(defaultRequest.config?.project_doc_max_bytes).toBe(131_072);
1922+
expect(overrideRequest.config).toEqual({
19041923
project_doc_max_bytes: 64_000,
19051924
"features.code_mode": true,
19061925
"features.code_mode_only": false,
@@ -2105,6 +2124,7 @@ describe("Codex app-server turn params", () => {
21052124
approvalPolicy: "on-request",
21062125
approvalsReviewer: "guardian_subagent",
21072126
config: {
2127+
project_doc_max_bytes: 131_072,
21082128
"features.code_mode": true,
21092129
"features.code_mode_only": false,
21102130
"features.goals": false,
@@ -3293,6 +3313,7 @@ describe("Codex app-server supervised branch lifecycle", () => {
32933313
excludeTurns: true,
32943314
developerInstructions: agentWorkspaceDeveloperInstructions,
32953315
config: {
3316+
project_doc_max_bytes: 131_072,
32963317
allow_login_shell: false,
32973318
shell_environment_policy: {
32983319
experimental_use_profile: false,
@@ -3312,6 +3333,7 @@ describe("Codex app-server supervised branch lifecycle", () => {
33123333
dynamicTools,
33133334
environments: [{ environmentId: "local", cwd: workspaceDir }],
33143335
config: {
3336+
project_doc_max_bytes: 131_072,
33153337
allow_login_shell: false,
33163338
shell_environment_policy: {
33173339
experimental_use_profile: false,

‎extensions/codex/src/app-server/thread-requests.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
shouldDisableCodexToolSearchForModel,
1212
} from "./dynamic-tool-profile.js";
1313
import { mergeCodexThreadConfigs } from "./plugin-thread-config.js";
14+
import { buildCodexProjectDocThreadConfig } from "./project-doc-thread-config.js";
1415
import {
1516
CODEX_OPENCLAW_DIRECT_DYNAMIC_TOOL_NAMESPACE,
1617
isJsonObject,
@@ -325,6 +326,7 @@ export function buildCodexRuntimeThreadConfig(
325326
directOnlyToolNamespaces?: readonly string[];
326327
} = {},
327328
): JsonObject {
329+
const configured = buildCodexProjectDocThreadConfig(config);
328330
// Native goal RPCs remain available through app-server, but the Codex goals
329331
// feature also starts autonomous turns. Keep it disabled until a run owner exists.
330332
const codeModeConfig: JsonObject = {
@@ -333,7 +335,7 @@ export function buildCodexRuntimeThreadConfig(
333335
};
334336
if (options.nativeCodeModeEnabled === false) {
335337
const disabledConfig = mergeCodexThreadConfigs(
336-
config,
338+
configured,
337339
CODEX_CODE_MODE_DISABLED_THREAD_CONFIG,
338340
CODEX_GOAL_CONTINUATION_DISABLED_THREAD_CONFIG,
339341
CODEX_NATIVE_UPDATE_PLAN_DISABLED_THREAD_CONFIG,
@@ -350,7 +352,7 @@ export function buildCodexRuntimeThreadConfig(
350352
if (options.nativeCodeModeOnlyEnabled === true) {
351353
const merged = mergeCodexThreadConfigs(
352354
codeModeConfig,
353-
config,
355+
configured,
354356
CODEX_GOAL_CONTINUATION_DISABLED_THREAD_CONFIG,
355357
CODEX_NATIVE_UPDATE_PLAN_DISABLED_THREAD_CONFIG,
356358
{
@@ -366,7 +368,7 @@ export function buildCodexRuntimeThreadConfig(
366368
}
367369
const merged = mergeCodexThreadConfigs(
368370
codeModeConfig,
369-
config,
371+
configured,
370372
CODEX_GOAL_CONTINUATION_DISABLED_THREAD_CONFIG,
371373
CODEX_NATIVE_UPDATE_PLAN_DISABLED_THREAD_CONFIG,
372374
) ?? {

‎extensions/codex/src/conversation-binding.test.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,7 @@ describe("codex conversation binding", () => {
741741
expect(requests[0]?.params.model).toBe("gpt-5.4-mini");
742742
expect(requests[0]?.params.personality).toBe("none");
743743
expect(requests[0]?.params.ephemeral).toBe(true);
744+
expect(requests[0]?.params.config).toMatchObject({ project_doc_max_bytes: 131_072 });
744745
expect(requests[0]?.params).not.toHaveProperty("modelProvider");
745746
await expect(readCodexAppServerBinding(sessionFile)).resolves.toMatchObject({
746747
authProfileId: "openai:default",
@@ -1020,7 +1021,11 @@ describe("codex conversation binding", () => {
10201021
expect(requests[1]?.params).toMatchObject({
10211022
threadId: "thread-native-child",
10221023
sandbox: "read-only",
1023-
config: { apps: { _default: { enabled: false } }, "features.apps": false },
1024+
config: {
1025+
project_doc_max_bytes: 131_072,
1026+
apps: { _default: { enabled: false } },
1027+
"features.apps": false,
1028+
},
10241029
});
10251030
await expect(consumeCodexAppServerLiveThread(client, "thread-native-child")).resolves.toEqual(
10261031
expect.objectContaining({ release: expect.any(Function) }),

‎extensions/codex/src/conversation-binding.ts‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ import {
5959
buildDisabledAppsConfigPatch,
6060
mergeCodexThreadConfigs,
6161
} from "./app-server/plugin-thread-config.js";
62+
import { buildCodexProjectDocThreadConfig } from "./app-server/project-doc-thread-config.js";
6263
import { assertCodexThreadStartResponse } from "./app-server/protocol-validators.js";
6364
import type {
6465
CodexServiceTier,
@@ -591,12 +592,10 @@ function codexConversationSandboxOrPermissions(
591592
const disabledApps = mergeCodexThreadConfigs(buildDisabledAppsConfigPatch(), {
592593
"features.apps": false,
593594
})!;
594-
if (networkProxy) {
595-
return {
596-
config: mergeCodexThreadConfigs(networkProxy.configPatch, disabledApps),
597-
};
598-
}
599-
return { sandbox, config: disabledApps };
595+
const config = buildCodexProjectDocThreadConfig(
596+
mergeCodexThreadConfigs(networkProxy?.configPatch, disabledApps),
597+
);
598+
return networkProxy ? { config } : { sandbox, config };
600599
}
601600

602601
async function requestNewConversationBindingThread(

0 commit comments

Comments
 (0)