Repository navigation
fix(sessions): reject oversized native context forks - #169792
Conversation
Resolve the child fork budget from the selected runtime catalog and authored model caps. Do not borrow API capacity when native limits are absent. Co-authored-by: Dallin Romney <[email protected]>
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. What this changesThis PR prevents native session forks from borrowing API catalog or cached context capacity. Example: Fork a 150,000-token parent with Codex when only the API catalog advertises 1,000,000 tokens.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this PR open: it fixes a current-main fork-admission defect through the existing capacity owner, with sufficient live proof and no actionable introduced findings. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherGateway session creation resolves the child's model and runtime, calculates its capacity, and passes the limit to the storage owner before parent history is copied. flowchart TD
A[Session creation request] --> B[Child model and runtime]
B --> C[Runtime catalog selection]
C --> D[Authored caps and selected window]
D --> E[Parent transcript admission]
E --> F[Reject or copy history]
Technical reviewBest possible solution: Land the focused fork-admission repair through the normal merge gates while keeping broader runtime-selection work separate. Do we have a high-confidence way to reproduce the issue? Current-main source exposes both capacity-donation paths, and the supplied live comparison records acceptance before the repair and rejection afterward; this read-only review ran no target code. Is this the best way to solve the issue? The patch fixes the existing admission owner directly using established selector and resolver controls while preserving authored caps, selected windows, and storage fallback. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against e6d42a6a73a0. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
PR surfaceSource 0, Tests +54, Docs +1. Total +55 across 3 files. Added test files: 0. View PR surface stats
Review metrics
LabelsLabel changes: No label changes. Label justifications:
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReviewed October 12, 2026, 6:03 AM ET / 10:03 UTC (Revision 3). |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Merged via explicitly authorized admin squash with attributed pre-existing CI failures.
|
Resolve the child fork budget from the selected runtime catalog and authored model caps. Do not borrow API capacity when native limits are absent. Co-authored-by: Dallin Romney <[email protected]>
What Problem This Solves
Native session forks can borrow an API route's context limit when the selected runtime has not declared that capacity.
User Impact
Fork creation uses the selected runtime's catalog and authored model caps. If that runtime has no known capacity, the existing 100,000-token fork limit applies. API-model limits and explicit context-window choices remain supported. No configuration or migration is required.
Why This Change Was Made
The creation owner now uses the runtime selector's existing no-API-fallback mode and resolves capacity without the shared cache. This is a focused maintainer replacement for the demonstrated fork-admission portion of #168809; thanks @RomneyDa for identifying and developing the runtime-selection repair. The source branch does not allow maintainer edits. Human credit is preserved in the commit.
Production: +2/-2 lines. Tests: +59/-5 lines. Documentation: +1 line.
Evidence
src/gateway/server.sessions.create.forks.test.tspass vianode scripts/run-vitest.mjs src/gateway/server.sessions.create.forks.test.ts --maxWorkers=1(396.98s wall, 351.28s Vitest; the three added cases total 13.817s locally and 3.136s in CI; all 24 cases also pass in CI). The existing Gateway-handler/storage fixture verifies actual admission and history copying; an isolated capacity helper would not cover that contract. No additional Gateway boots or timers were added.INVALID_REQUEST: parent session is too large to fork (198331/100000 tokens). The baseline response retainsagentRuntimeOverride: codex, the requested model, andforkedFromParent: true. A larger-parent probe confirms the baseline was borrowing the 272,000-token API limit. Baseline executable head759c4da4c48a26e50a4a7e174b164560a5d83e78contains only the parallel secrets repair; the fork-selection, parent-fork, context and model-catalog owners are byte-identical to main5e78ec6881c277fae9d4279e9315b5a1cc4b2925.NATIVE_FORK_OKwith Codex GPT-5.6 Sol, runtime-reported capacity 475,000 (2.809s); an Ollama Qwen3 4B fork answersLOCAL_FORK_OKwith its authored 16,384-token cap (7.745s). The local model also answered on main and completed real manual compaction (10.689s and 21.132s).42a5e461bc7a5f1f44efcd7f52e9ed2840f49dbe: ready for maintainer review, no findings or before-merge items; live proof is sufficient. No merge requested.Exact-head CI finished with 35 successful jobs, 24 skipped jobs, and one inherited test failure plus its aggregate gate failure.
checks-node-changed-compact-large-10failslocal-request-context.session-tools.test.ts/settles self-archive with live source authority after caller closure (closed request)at line 847: expected source authorityfalse, receivedtrue. The full unchanged file reproduces the identical failure (24 pass, 1 fail; 135.53s Vitest) on the CI merge's exact main parent93e87378063af62b07ca309d8fb48ceb7cb93073. The fork regression file passes in that same CI job. Security-fast, dependency review, and security-sensitive review pass. No job was cancelled, no CI rerun or synthetic push was used, and the aggregate CI gate remains red.The native check uses the already-installed Codex runtime and existing login; no new credentials were obtained. This is not live Claude CLI or Copilot-service proof.
Live reproduction
Both Gateways use the same isolated state and a fresh parent created through
sessions.create, with four 98,900-character synthetic messages appended throughchat.injectand no prior model turn. After refreshingmodels.list, which reports the native model available, call:pnpm openclaw --profile contrib-prs2-context gateway call sessions.create --json --params '{"key":"agent:main:native-proof-child","model":"openai/gpt-5.6-sol","agentRuntime":"codex","parentSessionKey":"agent:main:fork-input-medium","fork":true}'The before and after runs use distinct child keys. The parent is unchanged between them. Small native and local-model turns are separate positive controls; the rejected oversized fork does not start inference.