Skip to content

fix(codex): attach a request over the turn cap instead of losing its middle - #200735

Merged
obviyus merged 4 commits into
mainfrom
fix-oversized-input-budget
Nov 17, 2026
Merged

obviyus merged 4 commits into
mainfrom
fix-oversized-input-budget

Conversation

@obviyus

@obviyus obviyus commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #200514, #200690

What Problem This Solves

The Codex app-server rejects any turn over 1,048,576 characters (MAX_USER_INPUT_TEXT_CHARS in codex-rs). Since #200690, a current request over that cap keeps its head and tail and loses its middle. Anything that appears only in the middle is gone, and the model answers from what remains.

Large requests come from hooks (up to 1 MiB since #200514), the OpenAI-compatible endpoint (20 MiB bodies), channel messages, pastes and cron messages.

Fix

  • New host capability, fitCurrentInput. It is a generic harness host capability, so there are no new Plugin SDK exports. The Codex attempt calls it right after its connection is ready, with the Codex turn cap and the connection's own prepareInputAttachments.
  • Over the cap, and the run may read files on this host: the full request is saved as an inbound attachment (current-request.txt). The model sees the request's head and tail, which keep the instruction and both untrusted-content markers. It also sees a marker saying the visible part is incomplete and that it should search the attachment before answering, plus the attachment path.
  • Placement is the connection's decision. It already refuses local paths for a sandbox, remote execution, non-stdio transport, a remote workspace root, restricted tools or a non-full permission mode, and prefers a registered remote attachment binding.
  • Otherwise: only the middle is cut, as in fix(codex): keep the instruction when an oversized request is fitted #200690.
  • Transcript: keeps the original (transcriptPrompt). There is no change to stored turns, schema or retention; the file follows the operator's existing inbound attachment retention.
  • Visible outcome: each case logs current input oversize: chars=… budget=… action=attached|cut.

Scope, after local review. Earlier revisions also estimated a token budget from the model window and fitted requests for the built-in runtime. A chars-per-token estimate cannot prove token overflow. Fitting below the hard cap could drop content that fit, and the built-in runtime has its own token-aware overflow handling. This version acts only past a runtime's hard per-turn text cap, so nothing that worked inline changes.

User Impact

On the Codex runtime, a request over 1 MiB stays usable: the agent can search the full text instead of guessing from its start and end. Requests within the cap and the built-in runtime behave as before.

Evidence

Real Gateways from source with real models on the Codex runtime, POST /v1/chat/completions.

1. 3 MB request. A 2,948,079-character meeting transcript. The instruction is at the top ("Kenji Sato states the budget codeword. Reply with ONLY that codeword"). The codeword HERON-5150 appears once, at the 49.9% offset.

model main 9aed362 this PR, final head
gpt-5.4 Fire, Fire, ClawRouter (0/3) HERON-5150 ×3 (3/3)
gpt-5.4-mini armed, Fire, Fire (0/3) HERON-5150 1/3 (armed, done) on an earlier head with the same staging path
  • The log shows current input oversize: chars=2948079 budget=1048576 action=attached.
  • The Codex rollout shows the agent opening …/media/inbound/current-request---….txt, parsing it, and printing the matching segment.

2. 2 MiB request whose instruction is only at the top ("reply exactly ZEBRA-4217"), gpt-5.4-mini, final head: ZEBRA-4217, action=attached.

Tests:

  • src/agents/harness/current-input-budget.test.ts covers three cases:
    • unchanged within the cap;
    • attached: the saved file holds the full original, and the instruction and both markers stay inline;
    • cut-only when staging returns nothing.
  • Passing: src/agents/harness/ and every extensions/codex/src/app-server/run-attempt*.test.ts (11 shards), tsgo:core, tsgo:extensions, check:test-types, plugin-sdk:surface:check, oxlint, oxfmt and git diff --check.

Not covered / accepted:

  • gpt-5.4-mini is unreliable at finding a middle-only fact through the attachment (1/3). The docs say so.
  • Requests over the 5 MB inbound media cap fall back to the cut.
  • Each retry of the same oversized turn saves its own copy.
  • The Codex-side head/tail cut from fix(codex): keep the instruction when an oversized request is fitted #200690 stays as the guard for prompt decoration that still exceeds the cap.
  • The built-in runtime's handling of an oversized single message stays a separate, token-aware follow-up.

A request larger than the runtime's turn cap or most of the model window
was cut (Codex) or overflowed the model (embedded runtime). Core now fits
it once per harness attempt: the full text becomes a readable inbound
attachment when the run may read files, and the model sees its head, tail
and the attachment path. Otherwise only the middle is cut. The transcript
keeps the original.

Co-authored-by: obviyus <[email protected]>
@clawsweeper

clawsweeper Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation agents Agent runtime and tooling extensions: codex size: S labels Nov 17, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 17, 2026
@clawsweeper

clawsweeper Bot commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

Fits oversized requests by attaching their complete text when readable and sending a bounded head-and-tail excerpt.

Example: A 2,948,079-character Codex request asks for a codeword appearing only in its middle.

  • Before: The middle is discarded, and the supplied gpt-5.4 trials return the wrong answer.
  • After: The full request becomes an attachment, and the supplied gpt-5.4 trials return HERON-5150 three times.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) Useful production proof supports the repair, but two source-established regressions block merge.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The supplied real Gateway comparisons exercise oversized Codex attachment retrieval and embedded truncation through POST /v1/chat/completions, with returned codewords and matching runtime observations.
Patch quality 🦪 silver shellfish (2/6) 2 actionable review findings remain.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Large accepted requests lose relevant content or fail with an internal context-overflow error.
Reason: The maintainer-authored direction addresses demonstrated failures using existing attachment infrastructure; the remaining blockers are implementation defects.

Merge readiness

⛔ Needs changes before merge - 4 items remain

This PR addresses a demonstrated input-loss bug, but native-model budgeting and remote attachment placement introduce two regressions that need correction.

Priority: P2
Reviewed head: 7b840fbc846ddad48aae2825e8f50d2f61e73ba9

Before merge

  • Preserve unknown capacity for native-owned models (P2) - Unconfigured native Codex models and supervised sessions use createNativeModelOwnedRuntimeModel, whose contextWindow is a structural 200,000-token fallback. resolveEmbeddedRuntimeModelPolicy intentionally leaves contextTokenBudget undefined for these runs. Falling back to model.contextWindow here therefore imposes a 540,000-character limit regardless of the native model’s actual window. An 800,000-character request that previously stayed inline now becomes an attachment or loses its middle, recreating the attachment-retrieval regression described in the PR. Use an authored or observed budget, retaining only the runtime hard cap when native capacity is unknown, and cover this through harness selection.
  • Stage attachments through the execution placement owner (P2) - Calling the host capability directly bypasses connection.prepareInputAttachments, which rejects local paths for remote execution, non-stdio transports, and remoteWorkspaceRoot. For a remote WebSocket App Server with an ordinary local workspace and no registered remote attachment binding, host-media can return a Gateway-local media path because it does not know the Codex transport. The remote model then receives an instruction to read a file unavailable on its host, while the run logs action=attached. Preserve the existing connection-owned reachability checks before choosing attachment mode; otherwise use the documented cut fallback.
  • Explain or restore the original intent of Native context budgeting - fix: configured Codex chats compact prematurely after durable completion #171495: Preserve configured assembly allowances while retaining unconfigured native-window observation and pinned native-session ownership.
  • Explain or restore the original intent of Execution-host attachment preparation - fix(codex): large document uploads are unavailable to local file tools #156758: Expose verified local attachment paths only after the Codex connection confirms local execution, preserving remote and tool-policy restrictions.

Findings

  • [P2] Preserve unknown capacity for native-owned models — src/agents/harness/current-input-budget.ts:27-29
  • [P2] Stage attachments through the execution placement owner — src/agents/harness/current-input-budget.ts:40-45

Provenance

Tests

  • Missing end-to-end proof: The PR does not report a red-on-base run of the added regression tests.
Agent review details

How this fits together

Harness selection receives the prepared request and model policy, bounds the model-facing text, and uses the existing media store and attachment capability while preserving the original transcript.

flowchart TD
  A[Prepared current request] --> B[Harness selection]
  B --> C[Input budget]
  C --> D[Inbound attachment store]
  D --> E[Execution host attachment paths]
  C --> F[Bounded request text]
  E --> F
  F --> G[Selected agent harness]
Loading

Technical review

Best possible solution:

Use only authored or observed context limits and stage complete requests through the execution host’s existing attachment owner.

Do we have a high-confidence way to reproduce the issue?

Current source exposes both introduced failure paths, and the supplied real Gateway comparisons establish the original oversized-request problem; review execution remained read-only.

Is this the best way to solve the issue?

Shared fitting and reuse of inbound attachments are appropriate, but capacity and attachment reachability must remain with their existing native-runtime and execution-host owners.

Full review comments:

  • [P2] Preserve unknown capacity for native-owned models — src/agents/harness/current-input-budget.ts:27-29
    Unconfigured native Codex models and supervised sessions use createNativeModelOwnedRuntimeModel, whose contextWindow is a structural 200,000-token fallback. resolveEmbeddedRuntimeModelPolicy intentionally leaves contextTokenBudget undefined for these runs. Falling back to model.contextWindow here therefore imposes a 540,000-character limit regardless of the native model’s actual window. An 800,000-character request that previously stayed inline now becomes an attachment or loses its middle, recreating the attachment-retrieval regression described in the PR. Use an authored or observed budget, retaining only the runtime hard cap when native capacity is unknown, and cover this through harness selection.
    Confidence: 0.99
  • [P2] Stage attachments through the execution placement owner — src/agents/harness/current-input-budget.ts:40-45
    Calling the host capability directly bypasses connection.prepareInputAttachments, which rejects local paths for remote execution, non-stdio transports, and remoteWorkspaceRoot. For a remote WebSocket App Server with an ordinary local workspace and no registered remote attachment binding, host-media can return a Gateway-local media path because it does not know the Codex transport. The remote model then receives an instruction to read a file unavailable on its host, while the run logs action=attached. Preserve the existing connection-owned reachability checks before choosing attachment mode; otherwise use the documented cut fallback.
    Confidence: 0.97

Overall correctness: patch is incorrect
Overall confidence: 0.98

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 7ba70332d8dd.

Provenance checked

Testing

Proof path: shipped entry point.

Security

None.

Evidence

Acceptance criteria:

  • pnpm test src/agents/harness/current-input-budget.test.ts src/agents/harness/selection.input-attachments.test.ts
  • pnpm test src/agents/embedded-agent-runner/run/setup.test.ts
  • pnpm test extensions/codex/src/app-server/run-attempt.protocol-validation.test.ts extensions/codex/harness.test.ts
  • pnpm tsgo:core
  • pnpm tsgo:extensions

What I checked:

PR surface

Source +136, Tests +61, Docs +7. Total +204 across 6 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 4 137 1 +136
Tests 1 61 0 +61
Docs 1 7 0 +7
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 205 1 +204

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Review metrics

Metric Value Why it matters
Harness API addition 1 optional capability maxInputTextChars extends the public harness contract and controls core request fitting.

Labels

Label changes:

  • add P2: Oversized requests have demonstrated failures, with the affected surface limited to unusually large inputs.
  • add merge-risk: 🚨 compatibility: The patch extends the public harness API and changes existing native-session input handling, including premature fitting from placeholder capacity.
  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🐚 platinum hermit and patch quality is 🦪 silver shellfish.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Label justifications:

  • P2: Oversized requests have demonstrated failures, with the affected surface limited to unusually large inputs.
  • merge-risk: 🚨 compatibility: The patch extends the public harness API and changes existing native-session input handling, including premature fitting from placeholder capacity.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🐚 platinum hermit and patch quality is 🦪 silver shellfish.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed November 17, 2026, 1:40 PM ET / 18:40 UTC.

…n placement

Review: calling the local-host preparer from core bypassed the Codex
connection's placement checks, and cutting at the attach budget regressed
built-in runs that would still fit. Core now offers fitCurrentInput as a host
capability; Codex calls it with its connection-level preparer. The built-in
runtime cuts only a request that cannot fit the model window.

Co-authored-by: obviyus <[email protected]>
obviyus and others added 2 commits November 18, 2026 00:25
The reply allowance shares the window, so a 400k-token model with a 128k
reply cap cut to 1.4M chars still overflowed. Both limits now use the input
share of the window.

Co-authored-by: obviyus <[email protected]>
Review: a chars-per-token estimate cannot prove token overflow, so cutting
or spilling below the Codex hard cap dropped content that fit, and the
built-in runtime has its own token-aware overflow handling. The fitter now
acts only past the runtime's hard per-turn text cap, which only Codex
declares, and leaves the built-in runtime unchanged.

Co-authored-by: obviyus <[email protected]>
@obviyus obviyus changed the title fix(agents): attach an oversized current request instead of losing it fix(codex): attach a request over the turn cap instead of losing its middle Nov 17, 2026
@obviyus
obviyus merged commit 52e8079 into main Nov 17, 2026
135 checks passed
@obviyus
obviyus deleted the fix-oversized-input-budget branch November 17, 2026 19:24
@obviyus

obviyus commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator Author

Landed as 52e8079. On the Codex runtime, a current request over the 1,048,576-character turn cap used to lose its middle. Now, when the run can read files where Codex runs, the full request is saved as an attachment, and the model keeps the instruction, both untrusted-content markers and the attachment path. The Codex connection's own preparer decides placement. Otherwise only the middle is cut, as before. Proof: a 3 MB request with the needed fact only at its midpoint, on a real Gateway with gpt-5.4. main got it wrong 3/3; this change got it right 3/3 by reading the attachment. Local review and CI on the exact head are green. Follow-up from #200514 and #200690.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 18, 2026
…middle (openclaw#200735)

Related: openclaw#200514, openclaw#200690

## What Problem This Solves

The Codex app-server rejects any turn over 1,048,576 characters (`MAX_USER_INPUT_TEXT_CHARS` in codex-rs). Since openclaw#200690, a current request over that cap keeps its head and tail and loses its middle. Anything that appears only in the middle is gone, and the model answers from what remains.

Large requests come from hooks (up to 1 MiB since openclaw#200514), the OpenAI-compatible endpoint (20 MiB bodies), channel messages, pastes and cron messages.

## Fix

- **New host capability, `fitCurrentInput`.** It is a generic harness host capability, so there are no new Plugin SDK exports. The Codex attempt calls it right after its connection is ready, with the Codex turn cap and the connection's own `prepareInputAttachments`.
- **Over the cap, and the run may read files on this host:** the full request is saved as an inbound attachment (`current-request.txt`). The model sees the request's head and tail, which keep the instruction and both untrusted-content markers. It also sees a marker saying the visible part is incomplete and that it should search the attachment before answering, plus the attachment path.
- **Placement is the connection's decision.** It already refuses local paths for a sandbox, remote execution, non-stdio transport, a remote workspace root, restricted tools or a non-full permission mode, and prefers a registered remote attachment binding.
- **Otherwise:** only the middle is cut, as in openclaw#200690.
- **Transcript:** keeps the original (`transcriptPrompt`). There is no change to stored turns, schema or retention; the file follows the operator's existing inbound attachment retention.
- **Visible outcome:** each case logs `current input oversize: chars=… budget=… action=attached|cut`.

**Scope, after local review.** Earlier revisions also estimated a token budget from the model window and fitted requests for the built-in runtime. A chars-per-token estimate cannot prove token overflow. Fitting below the hard cap could drop content that fit, and the built-in runtime has its own token-aware overflow handling. This version acts only past a runtime's hard per-turn text cap, so nothing that worked inline changes.

## User Impact

On the Codex runtime, a request over 1 MiB stays usable: the agent can search the full text instead of guessing from its start and end. Requests within the cap and the built-in runtime behave as before.

## Evidence

Real Gateways from source with real models on the Codex runtime, `POST /v1/chat/completions`.

**1. 3 MB request.** A 2,948,079-character meeting transcript. The instruction is at the top ("Kenji Sato states the budget codeword. Reply with ONLY that codeword"). The codeword `HERON-5150` appears once, at the 49.9% offset.

| model | `main` 709b566 | this PR, final head |
|---|---|---|
| gpt-5.4 | `Fire`, `Fire`, `ClawRouter` (0/3) | `HERON-5150` ×3 (3/3) |
| gpt-5.4-mini | `armed`, `Fire`, `Fire` (0/3) | `HERON-5150` 1/3 (`armed`, `done`) on an earlier head with the same staging path |

- The log shows `current input oversize: chars=2948079 budget=1048576 action=attached`.
- The Codex rollout shows the agent opening `…/media/inbound/current-request---….txt`, parsing it, and printing the matching segment.

**2. 2 MiB request whose instruction is only at the top** ("reply exactly ZEBRA-4217"), gpt-5.4-mini, final head: `ZEBRA-4217`, `action=attached`.

**Tests:**

- `src/agents/harness/current-input-budget.test.ts` covers three cases:
  - unchanged within the cap;
  - attached: the saved file holds the full original, and the instruction and both markers stay inline;
  - cut-only when staging returns nothing.
- Passing: `src/agents/harness/` and every `extensions/codex/src/app-server/run-attempt*.test.ts` (11 shards), `tsgo:core`, `tsgo:extensions`, `check:test-types`, `plugin-sdk:surface:check`, oxlint, oxfmt and `git diff --check`.

**Not covered / accepted:**

- gpt-5.4-mini is unreliable at finding a middle-only fact through the attachment (1/3). The docs say so.
- Requests over the 5 MB inbound media cap fall back to the cut.
- Each retry of the same oversized turn saves its own copy.
- The Codex-side head/tail cut from openclaw#200690 stays as the guard for prompt decoration that still exceeds the cap.
- The built-in runtime's handling of an oversized single message stays a separate, token-aware follow-up.

Co-authored-by: Ayaan Zaidi <[email protected]>
RomneyDa added a commit that referenced this pull request Nov 18, 2026
…middle (#200735)

Related: #200514, #200690

## What Problem This Solves

The Codex app-server rejects any turn over 1,048,576 characters (`MAX_USER_INPUT_TEXT_CHARS` in codex-rs). Since #200690, a current request over that cap keeps its head and tail and loses its middle. Anything that appears only in the middle is gone, and the model answers from what remains.

Large requests come from hooks (up to 1 MiB since #200514), the OpenAI-compatible endpoint (20 MiB bodies), channel messages, pastes and cron messages.

## Fix

- **New host capability, `fitCurrentInput`.** It is a generic harness host capability, so there are no new Plugin SDK exports. The Codex attempt calls it right after its connection is ready, with the Codex turn cap and the connection's own `prepareInputAttachments`.
- **Over the cap, and the run may read files on this host:** the full request is saved as an inbound attachment (`current-request.txt`). The model sees the request's head and tail, which keep the instruction and both untrusted-content markers. It also sees a marker saying the visible part is incomplete and that it should search the attachment before answering, plus the attachment path.
- **Placement is the connection's decision.** It already refuses local paths for a sandbox, remote execution, non-stdio transport, a remote workspace root, restricted tools or a non-full permission mode, and prefers a registered remote attachment binding.
- **Otherwise:** only the middle is cut, as in #200690.
- **Transcript:** keeps the original (`transcriptPrompt`). There is no change to stored turns, schema or retention; the file follows the operator's existing inbound attachment retention.
- **Visible outcome:** each case logs `current input oversize: chars=… budget=… action=attached|cut`.

**Scope, after local review.** Earlier revisions also estimated a token budget from the model window and fitted requests for the built-in runtime. A chars-per-token estimate cannot prove token overflow. Fitting below the hard cap could drop content that fit, and the built-in runtime has its own token-aware overflow handling. This version acts only past a runtime's hard per-turn text cap, so nothing that worked inline changes.

## User Impact

On the Codex runtime, a request over 1 MiB stays usable: the agent can search the full text instead of guessing from its start and end. Requests within the cap and the built-in runtime behave as before.

## Evidence

Real Gateways from source with real models on the Codex runtime, `POST /v1/chat/completions`.

**1. 3 MB request.** A 2,948,079-character meeting transcript. The instruction is at the top ("Kenji Sato states the budget codeword. Reply with ONLY that codeword"). The codeword `HERON-5150` appears once, at the 49.9% offset.

| model | `main` 9aed362 | this PR, final head |
|---|---|---|
| gpt-5.4 | `Fire`, `Fire`, `ClawRouter` (0/3) | `HERON-5150` ×3 (3/3) |
| gpt-5.4-mini | `armed`, `Fire`, `Fire` (0/3) | `HERON-5150` 1/3 (`armed`, `done`) on an earlier head with the same staging path |

- The log shows `current input oversize: chars=2948079 budget=1048576 action=attached`.
- The Codex rollout shows the agent opening `…/media/inbound/current-request---….txt`, parsing it, and printing the matching segment.

**2. 2 MiB request whose instruction is only at the top** ("reply exactly ZEBRA-4217"), gpt-5.4-mini, final head: `ZEBRA-4217`, `action=attached`.

**Tests:**

- `src/agents/harness/current-input-budget.test.ts` covers three cases:
  - unchanged within the cap;
  - attached: the saved file holds the full original, and the instruction and both markers stay inline;
  - cut-only when staging returns nothing.
- Passing: `src/agents/harness/` and every `extensions/codex/src/app-server/run-attempt*.test.ts` (11 shards), `tsgo:core`, `tsgo:extensions`, `check:test-types`, `plugin-sdk:surface:check`, oxlint, oxfmt and `git diff --check`.

**Not covered / accepted:**

- gpt-5.4-mini is unreliable at finding a middle-only fact through the attachment (1/3). The docs say so.
- Requests over the 5 MB inbound media cap fall back to the cut.
- Each retry of the same oversized turn saves its own copy.
- The Codex-side head/tail cut from #200690 stays as the guard for prompt decoration that still exceeds the cap.
- The built-in runtime's handling of an oversized single message stays a separate, token-aware follow-up.

Co-authored-by: Ayaan Zaidi <[email protected]>

(cherry picked from commit 52e8079)

Backport-proof: added a production-host Codex turn/start regression with registered workspace attachment owner; red on a8f3bfad459c because complete-request attachment guidance is absent. Existing placement and live binding owner retained.
Co-authored-by: vincentkoc <[email protected]>
Co-authored-by: RomneyDa <[email protected]>
RomneyDa added a commit that referenced this pull request Nov 19, 2026
…middle (#200735)

Related: #200514, #200690

## What Problem This Solves

The Codex app-server rejects any turn over 1,048,576 characters (`MAX_USER_INPUT_TEXT_CHARS` in codex-rs). Since #200690, a current request over that cap keeps its head and tail and loses its middle. Anything that appears only in the middle is gone, and the model answers from what remains.

Large requests come from hooks (up to 1 MiB since #200514), the OpenAI-compatible endpoint (20 MiB bodies), channel messages, pastes and cron messages.

## Fix

- **New host capability, `fitCurrentInput`.** It is a generic harness host capability, so there are no new Plugin SDK exports. The Codex attempt calls it right after its connection is ready, with the Codex turn cap and the connection's own `prepareInputAttachments`.
- **Over the cap, and the run may read files on this host:** the full request is saved as an inbound attachment (`current-request.txt`). The model sees the request's head and tail, which keep the instruction and both untrusted-content markers. It also sees a marker saying the visible part is incomplete and that it should search the attachment before answering, plus the attachment path.
- **Placement is the connection's decision.** It already refuses local paths for a sandbox, remote execution, non-stdio transport, a remote workspace root, restricted tools or a non-full permission mode, and prefers a registered remote attachment binding.
- **Otherwise:** only the middle is cut, as in #200690.
- **Transcript:** keeps the original (`transcriptPrompt`). There is no change to stored turns, schema or retention; the file follows the operator's existing inbound attachment retention.
- **Visible outcome:** each case logs `current input oversize: chars=… budget=… action=attached|cut`.

**Scope, after local review.** Earlier revisions also estimated a token budget from the model window and fitted requests for the built-in runtime. A chars-per-token estimate cannot prove token overflow. Fitting below the hard cap could drop content that fit, and the built-in runtime has its own token-aware overflow handling. This version acts only past a runtime's hard per-turn text cap, so nothing that worked inline changes.

## User Impact

On the Codex runtime, a request over 1 MiB stays usable: the agent can search the full text instead of guessing from its start and end. Requests within the cap and the built-in runtime behave as before.

## Evidence

Real Gateways from source with real models on the Codex runtime, `POST /v1/chat/completions`.

**1. 3 MB request.** A 2,948,079-character meeting transcript. The instruction is at the top ("Kenji Sato states the budget codeword. Reply with ONLY that codeword"). The codeword `HERON-5150` appears once, at the 49.9% offset.

| model | `main` 9aed362 | this PR, final head |
|---|---|---|
| gpt-5.4 | `Fire`, `Fire`, `ClawRouter` (0/3) | `HERON-5150` ×3 (3/3) |
| gpt-5.4-mini | `armed`, `Fire`, `Fire` (0/3) | `HERON-5150` 1/3 (`armed`, `done`) on an earlier head with the same staging path |

- The log shows `current input oversize: chars=2948079 budget=1048576 action=attached`.
- The Codex rollout shows the agent opening `…/media/inbound/current-request---….txt`, parsing it, and printing the matching segment.

**2. 2 MiB request whose instruction is only at the top** ("reply exactly ZEBRA-4217"), gpt-5.4-mini, final head: `ZEBRA-4217`, `action=attached`.

**Tests:**

- `src/agents/harness/current-input-budget.test.ts` covers three cases:
  - unchanged within the cap;
  - attached: the saved file holds the full original, and the instruction and both markers stay inline;
  - cut-only when staging returns nothing.
- Passing: `src/agents/harness/` and every `extensions/codex/src/app-server/run-attempt*.test.ts` (11 shards), `tsgo:core`, `tsgo:extensions`, `check:test-types`, `plugin-sdk:surface:check`, oxlint, oxfmt and `git diff --check`.

**Not covered / accepted:**

- gpt-5.4-mini is unreliable at finding a middle-only fact through the attachment (1/3). The docs say so.
- Requests over the 5 MB inbound media cap fall back to the cut.
- Each retry of the same oversized turn saves its own copy.
- The Codex-side head/tail cut from #200690 stays as the guard for prompt decoration that still exceeds the cap.
- The built-in runtime's handling of an oversized single message stays a separate, token-aware follow-up.

Co-authored-by: Ayaan Zaidi <[email protected]>
(cherry picked from commit 52e8079)
Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit 4f7dcc1980d999588febf5f02aa05c4d5a1e30eb)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation extensions: codex merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: S status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant