Skip to content

fix(sessions): reject oversized native context forks - #169792

Merged
steipete merged 1 commit into
mainfrom
fix/native-session-fork-context
Oct 12, 2026
Merged

steipete merged 1 commit into
mainfrom
fix/native-session-fork-context

Conversation

@steipete

@steipete steipete commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

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

  • The two added native rejection cases fail on main by incorrectly accepting a 150,000-token parent; five controls pass (178.76s wall including cold setup).
  • All 24 cases in src/gateway/server.sessions.create.forks.test.ts pass via node 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.
  • Full build, core production types, Gateway-server test types, targeted lint, formatting, and the required max-lines, line-cap, assertion-safety, timeout-race, mock-export, configuration-doc and plugin-inventory checks pass.
  • Live Gateway comparison: an explicit Codex GPT-5.6 Sol fork of the same fresh parent is accepted by the unchanged main context owner and rejected by this patch with INVALID_REQUEST: parent session is too large to fork (198331/100000 tokens). The baseline response retains agentRuntimeOverride: codex, the requested model, and forkedFromParent: true. A larger-parent probe confirms the baseline was borrowing the 272,000-token API limit. Baseline executable head 759c4da4c48a26e50a4a7e174b164560a5d83e78 contains only the parallel secrets repair; the fork-selection, parent-fork, context and model-catalog owners are byte-identical to main 5e78ec6881c277fae9d4279e9315b5a1cc4b2925.
  • Positive controls through the real Gateway: a small explicit native fork answers NATIVE_FORK_OK with Codex GPT-5.6 Sol, runtime-reported capacity 475,000 (2.809s); an Ollama Qwen3 4B fork answers LOCAL_FORK_OK with 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).
  • Independent Codex review reports no actionable P0–P2 findings. ClawSweeper reviewed exact head 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-10 fails local-request-context.session-tools.test.ts / settles self-archive with live source authority after caller closure (closed request) at line 847: expected source authority false, received true. The full unchanged file reproduces the identical failure (24 pass, 1 fail; 135.53s Vitest) on the CI merge's exact main parent 93e87378063af62b07ca309d8fb48ceb7cb93073. 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 through chat.inject and no prior model turn. After refreshing models.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.

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]>
@clawsweeper

clawsweeper Bot commented Oct 12, 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 gateway Gateway runtime size: S labels Oct 12, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 12, 2026
@clawsweeper

clawsweeper Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This 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.

  • Before: The fork is accepted using the API capacity.
  • After: The fork is rejected against the existing 100,000-token fallback unless native or authored capacity permits it.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) Focused owner-level repair with shipped-entry-point before/after evidence, meaningful admission regressions, and no identified introduced defect.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The supplied isolated-Gateway sessions.create comparison exercises explicit native selection against the same oversized parent and records corrected rejection, with successful small native and authored-cap local-model controls; inspected picker screenshots are unrelated context.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Native forks can be accepted using context capacity advertised only by another runtime.
Reason: The focused repair restores the established runtime-isolation contract, and maintainer authorship settles the conservative fallback choice.

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
Reviewed head: 42a5e461bc7a5f1f44efcd7f52e9ed2840f49dbe

Before merge

None.

Findings

None.

Agent review details

How this fits together

Gateway 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]
Loading

Technical review

Best 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

  • Runtime-specific fork capacity keeps the original intent (8cd38b0: The installed-agent integration introduced the helper to resolve fork capacity from the selected runtime's catalog and configured model limits.)
  • Fork admission test table keeps the original intent (52b32be: Consolidate equivalent Gateway tests while preserving distinct storage, authority, and routing coverage.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

PR surface

Source 0, Tests +54, Docs +1. Total +55 across 3 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 2 2 0
Tests 1 59 5 +54
Docs 1 1 0 +1
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 62 7 +55

Review metrics

Metric Value Why it matters
Production versus test LOC Production +2/-2; tests +59/-5 Three distinct admission cases extend the existing fixture without adding production machinery or Gateway boots.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: Incorrect fork admission affects mixed native/API catalogs and oversized parents, with limited blast radius.
  • merge-risk: 🚨 compatibility: Previously accepted oversized native forks can now be rejected; this correction and the retained fallback are explicitly accepted in the maintainer-authored PR.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • 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.

History

Review history (2 earlier review cycles)
  • reviewed 2026-10-12T09:24:46.018Z sha 42a5e46 :: needs changes before merge. :: none
  • reviewed 2026-10-12T09:33:00.223Z sha 42a5e46 :: needs maintainer review before merge. :: none

Reviewed October 12, 2026, 6:03 AM ET / 10:03 UTC (Revision 3).

@steipete
steipete marked this pull request as ready for review October 12, 2026 09:28
@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 12, 2026
@steipete steipete self-assigned this Oct 12, 2026
@steipete
steipete merged commit 34627e9 into main Oct 12, 2026
216 of 222 checks passed
@steipete
steipete deleted the fix/native-session-fork-context branch October 12, 2026 17:28
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via explicitly authorized admin squash with attributed pre-existing CI failures.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 13, 2026
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation gateway Gateway runtime 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: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant