fix(server): Codex threads get the whole T3 orchestration instructions #18415
main fromrefs/pull/18415/head·merged by juliusmarminge View on GitHubProblem#
Codex threads receive the T3 orchestration instructions with the middle cut out (#18411).
Codex caps each turn/start.additionalContext value at 1,000 tokens, counted as ceil(UTF-8 bytes / 4), and replaces the middle of anything longer with a marker such as …704 tokens truncated…. The client gets no error. T3_CODE_ORCHESTRATION_INSTRUCTIONS is 6,813 bytes and is sent as one entry, so 2,813 bytes never arrive: the end of the schedule_task guidance, the request_secret rule, the thread-link rule, and nearly all of "Choose the workspace before starting a new thread". Claude threads get the full text.
#13547 split runtime and tool guidance into separate entries to stay under this cap and added a test that measured every entry. #2829 added the orchestration entry at 5,147 bytes, and the size check was removed in the same change, so nothing has caught it since.
Change#
orchestrationInstructions.tsauthors the instructions as four self-contained sections.T3_CODE_ORCHESTRATION_INSTRUCTIONSis now the sections joined, so every other provider gets the same wording as before. The only textual difference is one added blank line between the delegated-review bullet and theschedule_taskbullet.buildCodexAdditionalContextsends one entry per section, keyedt3_code_orchestration_01to_04. Codex emits entries in sorted key order, so the zero-padded numbering keeps the authored order.t3_code_runtimeandt3_code_toolsare unchanged.CodexDeveloperInstructions.test.tsgets the size check back, in the same plain style #13547 used. It measures every valuebuildCodexAdditionalContextreturns, for each tool-availability combination, and names the entry and the overage when one is too big. A second test checks that the sorted entries are the authored sections in order and that together they equal the combined instructions.
Entry sizes against the 4,000-byte cap:
| Entry | Before | After |
|---|---|---|
| orchestration | 6,813 | 1,579 / 1,428 / 2,145 / 1,653 |
t3_code_tools (browser and device) | 2,906 | 2,906 |
t3_code_runtime | about 1,455 | about 1,455 |
Threads that are already running keep the old truncated t3_code_orchestration entry in their history and pick up the four new entries on their next turn, because Codex only emits entries whose value changed and has no way to retract a key.
Scope and approval#
This is a small, focused fix for an obvious bug. The bug and the proposed section split with a size regression test were confirmed in #18411. It changes how existing instructions are delivered, not what they say, and it restores a check this repository already had. There is no product-behaviour change and no new wording.
Verification#
- The defect, observed. On desktop nightly
0.0.46-nightly.20261011.2994with Codex CLI0.162.1, a fresh Codex thread's rollout records thet3_code_orchestrationdeveloper message with…704 tokens truncated…in it, while the provider log shows T3 Code submitting all 6,813 bytes. - The new test fails on the old code. Run against the modules from
main, every size case fails witht3_code_orchestration: 6813 UTF-8 bytes exceeds Codex's 4000-byte per-entry cap by 2813 bytes. - It passes with the fix.
vp test run apps/server/src/provider/CodexDeveloperInstructions.test.ts packages/provider-core/src/server/orchestrationInstructions.test.ts apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.test.tsgives 3 files, 190 tests passed. That includes the existing compaction test that restores additional context throughthread/inject_items. - Wording. I compared the new combined constant with the one on
main: identical apart from the one blank line. vp lintandvp fmt --checkon the four changed files pass, andtsc --noEmitis clean forapps/serverandpackages/provider-core.
Live Codex app-server verification passed on commit 273d7c3960ba1dbbc0f1f2bfaedad73c0b2b371b using Codex CLI 0.162.1. With browser and device tools enabled, the captured outgoing Responses payload contained all four orchestration entries (t3_code_orchestration_01 through _04), t3_code_runtime, and t3_code_tools byte for byte, including their wrappers, with no truncation marker anywhere in the captured payload. The check used a fresh isolated Codex home and a localhost mock Responses endpoint that completed one turn immediately; no model API request was made.
Claude Opus 5.5 in Claude Code wrote the fix; GPT-6 Astra in Codex wrote the tests.
🤖 Generated with Claude Code
Downstream port: lastobelus/lastCode#395. The port is independent of upstream acceptance.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
juliusmarminge added labelsmacroscope-review
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes
Approvability#
Verdict: Approved at
273d7c3Macroscope's review found this PR approvable — This is a focused server bug fix that splits existing orchestration guidance into size-safe Codex entries so the full text is delivered, while preserving behavior for other providers. The added tests verify entry limits, ordering, and adapter usage without introducing new product defaults or static-analysis overrides.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
-
-
-
-
⚙️ Run configuration
-
-
-
-
- Configuration used: Path: .coderabbit.config.ts
- Review profile: CHILL
- Plan: Advanced
- Run ID:
bfefb2e8-7d16-4b92-a278-8cdc990aab82
-
-
-
📥 Commits
-
-
-
-
Reviewing files that changed from the base of the PR and between 27839622efccb65982fd297847973fdedf6365aa and 273d7c3960ba1dbbc0f1f2bfaedad73c0b2b371b.
-
-
-
📒 Files selected for processing (4)
-
-
-
-
apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.test.tsapps/server/src/provider/CodexDeveloperInstructions.test.tsapps/server/src/provider/CodexDeveloperInstructions.tspackages/provider-core/src/server/orchestrationInstructions.ts
-
-
-
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
-
-
-
-
📝 Walkthrough
-
📝 Walkthrough
-
📝 Walkthrough
-
-
📝 Walkthrough
-
-
-
Walkthrough#
Orchestration instructions are now authored as separate sections and emitted as numbered Codex additional-context entries. Tests check each entry’s byte limit, section ordering, combined instruction text, and adapter expectations.
Changes#
Codex orchestration context
Layer / File(s) Summary Define orchestration instruction sections
packages/provider-core/src/server/orchestrationInstructions.tsOrchestration guidance is stored in separate sections and joined with blank lines to derive T3_CODE_ORCHESTRATION_INSTRUCTIONS. The guidance includes new details on MCP tool names, lazy discovery, bounded polling, and stable retry IDs.Emit and validate numbered context entries
apps/server/src/provider/CodexDeveloperInstructions.ts,apps/server/src/provider/CodexDeveloperInstructions.test.ts,apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.test.tsbuildCodexAdditionalContextemits each section under a sequential, zero-padded key. Tests check the 4,000-byte limit, section order, combined instructions, and updated adapter expectations.Priority: ⬇️ Low
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix
Suggested reviewers:
juliusmarminge
-
-
-
-
-
-
Merge Risk: ⚪ Minimal · up to
273d7No actionable merge-blocking issue is identified; the change is mergeable after normal checks.
Security Architecture Review
Security architecture risk: 🔵 Low · up to
273d7The change restores complete orchestration guidance without adding permissions or new user-controlled inputs. Remaining uncertainty concerns end-to-end delivery order and size handling, rather than an identified security regression.
Retained concerns No architecture-level concerns identified.
-
Security review details
-
-
-
Security Blast Radius
- inferred — The changed exposure is delivery of application-authored guidance to Codex turns with an attached T3 MCP session. The exported helpers do not themselves establish a new externally callable endpoint or grant additional tool authority.
Trust Boundaries and Controls
- observed — Production app-context keys use the mcp_app_ namespace and remain untrusted, preventing collision with the newly numbered application entries on that path. The generic adapter accepts arbitrary keys, but that pre-existing flexibility is not introduced by this PR.
-
-
-
Pre-merge checks |
4-
✅ Passed checks (4 passed)
-
Check name Status Explanation Linked Issues check Check skipped because no linked issues were found for this pull request. Out of Scope Changes check Check skipped because no linked issues were found for this pull request. Title check The title clearly identifies the main fix: ensuring Codex threads receive the complete T3 orchestration instructions. Description check The description includes complete Problem, Change, Scope and approval, and Verification sections. It explains the defect, implementation, approval basis, focused tests, manual verification, and agent …
-
✨ Finishing Touches
-
-
-
-
🧪 Generate unit tests (beta)
-
-
-
-
- Create a new PR
-
-
-
-
-
-
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Comment `@coderabbitai help` to get the list of available commands.-
coderabbitai[bot](GitHub profile, opens in a new tab) approved these changes
juliusmarminge merged this91adab7
juliusmarminge closed this
Sign in to join this conversation.
Codex Review Summary#
This comment shows the latest Codex review activity on this pull request.
273d7c3ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.