Skip to content

fix: let long chats fork without losing searchable history - #205671

Merged
hannesrudolph merged 6 commits into
mainfrom
openclaw/briny-crab-5e1fed
Nov 26, 2026
Merged

hannesrudolph merged 6 commits into
mainfrom
openclaw/briny-crab-5e1fed

Conversation

@roboclaw-bot

@roboclaw-bot roboclaw-bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #174730 (incident evidence)

What Problem This Solves

Forking a long chat could fail before creating the child because the Gateway compared the selected history with the child model's input capacity. That prevented branching even though the full transcript need not be sent to the model. The incident showed the rejection; the later roster reading did not establish which estimator input produced it.

User Impact

User impact: an explicit chat fork on the built-in OpenClaw API runner keeps the selected, searchable history and can continue from the recent decision. The child writes to its own transcript. This does not raise a model cap, shorten the parent, or change automatic/subagent or native-runtime fork admission. Active parents still require a completed fork point; reset boundaries and access checks stay in place.

Why This Change Was Made

Copying a branch and fitting a model request are different operations. The runner now selects inherited turns against the space left after instructions, tools, current input and output reserve. Child-owned turns stay under normal compaction. Reply preflight no longer mistakes unmeasured copied history for a child request. Simply removing the creation check was insufficient: in the control run the first request summarized the old ledger and missed the recent decision.

Evidence

  • Before: at f57a179eb81fc48c3d3f64bf2489c1fec3537bf1, the real sessions.create WebSocket call returned INVALID_REQUEST (45912/32768 tokens). No child and no model call. The old ledger alone was 104,868 tokens under o200k_base, not an inflated usage counter.
  • After: clean build of PR head d3aad208067b5e4eb158666a554d4a6e0e15bac8, same saved synthetic parent. Child-scoped sessions.search found the old receipt in the child's own transcript. The neutral question did not repeat the answer. The first and only outbound request contained the recent decision, instructions and four tools, but none of the 2,800 old ledger rows. The built-in runner sent it to a real local Qwen2.5-0.5B-Instruct model via llama.cpp: 6,987 measured input + 2,048 reserved output = 9,035 / 32,768 tokens. The generated and delivered answer was “The QA canary code we chose is CobaltTrellis49.” All seven parent events and the active leaf were unchanged. This is not a Gemini or live-parent retest.
  • On that head, the committed first-request E2E and focused Gateway, automatic/subagent, active-run, reset and reply-preflight suites passed. The E2E uses a deterministic wire reader; the separate measurement above is actual model inference. The QA build passed. Local autoreview could not start its read-only reviewer sandbox; no local clean-review claim. Hosted review and CI are separate.

Reported, investigated and scoped by @hannesrudolph.

Work sessions

Linked for team reference; these sessions aren’t public.

Worked on by

roboclaw-bot and others added 3 commits November 26, 2026 01:09
Budget inherited context at the built-in API runner’s request boundary rather than rejecting the whole branch. Keep native and automatic fork admission unchanged.

Co-authored-by: hannesrudolph <[email protected]>
Worked on by:
- @hannesrudolph

Co-authored-by: hannesrudolph <[email protected]>
OpenClaw-Publication: 9532ef09-a309-4d7f-91df-985ad84b6a4b
@clawsweeper

clawsweeper Bot commented Nov 26, 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 agents Agent runtime and tooling size: XL labels Nov 26, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. impact:session-state Session, memory, transcript, context, or agent state can drift or corrupt. labels Nov 26, 2026
roboclaw-bot and others added 3 commits November 26, 2026 01:29
Worked on by:
- @hannesrudolph

Co-authored-by: hannesrudolph <[email protected]>
OpenClaw-Publication: 460097f2-eb9b-449b-a5b1-e48550923c80
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 26, 2026
@clawsweeper

clawsweeper Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR preserves searchable history when explicitly forking an API chat and fits inherited context at the model-request boundary.

Example: Fork a saved conversation whose estimated history exceeds a 32,768-token model window.

  • Before: sessions.create rejects the fork with INVALID_REQUEST (45912/32768 tokens), creating no child.
  • After: The child retains the searchable receipt VaultSlipRaven91 and answers the recent decision CobaltTrellis49 using a reported 9,035-token input-plus-output budget.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A worthwhile, focused behavioral repair with sufficient supplied end-to-end evidence and no identified blocking defect; exact-head CI is still completing.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The public exact-head account exercises sessions.create, child-scoped sessions.search and chat continuation through a built Gateway and real local model, with measured request usage, correct delivery and unchanged parent state; the committed wire-reader E2E separately supports request composition, and existing forkSource/inheritedThrough formats require no migration.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Forking a long API conversation fails before creating a child, leaving the user unable to branch the conversation.
Reason: The maintainer-authored direction supplies a useful recovery outcome: an independent, searchable child whose next request fits the selected model.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-authored PR addresses a current long-chat branching failure, and no blocking defect was identified in the introduced changes.

Reviewed head: d3aad208067b5e4eb158666a554d4a6e0e15bac8

Before merge

None.

Findings

None.

Agent review details

How this fits together

Gateway session creation copies the selected transcript into an independent child; the embedded runner prepares that child's model context while transcript search continues to read its saved history.

flowchart LR
  A[Explicit fork request] --> B[Gateway creation owner]
  B --> C[Independent child transcript]
  C --> D[Transcript search]
  C --> E[Embedded request preparation]
  E --> F[Budget inherited turns]
  F --> G[Model request]
Loading

Technical review

Best possible solution:

Preserve the complete copied transcript and fit only inherited model context through the existing request-budget and selection owners.

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

Current-main source still rejects oversized selected history before copying it, consistent with the linked incident and supplied base reproduction; this review executed no target code.

Is this the best way to solve the issue?

Separating transcript copying from request fitting addresses the blocked API-chat workflow without raising model limits or rewriting the parent, while reusing existing budget and tool-pairing selection logic.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

  • Pinned change and policy: Reviewed the introduced merge-base-to-head diff and applicable ancestor AGENTS.md files; no maintainer-notes directory was present. (AGENTS.md:1, d3aad208067b)
  • Current main still rejects oversized forks: Fetched main still resolves a child-model limit and passes it to token-enforced fork preparation, so the central behavior remains necessary. (src/gateway/session-create-fork.ts:26, b9d0210f31ba)
  • Scoped admission change: Only explicit forks using the built-in API runner bypass creation-time token admission; CLI providers and other runtimes retain capacity checks. (src/gateway/session-create-model-selection.ts:441, d3aad208067b)
  • Request fitting preserves child-owned work: The working-context selector reserves instructions, tools, pending input, output and protected messages, then removes only tagged inherited conversation rows using the existing tool-pairing-aware selector. (src/agents/embedded-agent-runner/run/fork-working-context.ts:48, d3aad208067b)
  • Search and transcript isolation: The Gateway regression checks child-scoped search, exact copied events, independent child appends, preserved Draft/workspace/native-binding metadata, and unchanged parent events. (src/gateway/server.sessions.create.fork-search.test.ts:130, d3aad208067b)
  • Supplied real-model proof: The exact-head PR body reports a real Gateway and llama.cpp inference: the first and only request retained the recent decision and required tools, omitted the old ledger, used 6,987 measured input tokens plus 2,048 reserved output tokens, and delivered the correct answer; parent events and leaf remained unchanged. (d3aad208067b)

Likely related people:

  • Peter Steinberger: Raw commit 245cbaf adds src/agents/sessions/session-manager.ts:572 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 245cbaf915c2; files: src/agents/sessions/session-manager.ts)
  • Dallin Romney: Raw commit fb83d65 adds src/config/sessions/session-bounded-context-selection.ts:60 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: fb83d658cf3b; files: src/config/sessions/session-bounded-context-selection.ts)
  • Josh Lehman: Raw commit c4a4c12 adds src/agents/sessions/session-manager.ts:57 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: c4a4c125b5bb; files: src/agents/sessions/session-manager.ts)

PR surface

Source +248, Tests +349, Docs 0. Total +597 across 23 files. Added test files: 3.

View PR surface stats
Area Files Added Removed Net
Source 16 337 89 +248
Tests 5 496 147 +349
Docs 2 2 2 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 23 835 238 +597

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.

Labels

Label changes:

No label changes.

Label justifications:

  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • 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.

Reviewed November 25, 2026, 8:50 PM ET / November 26, 2026, 01:50 UTC.

@hannesrudolph
hannesrudolph merged commit c2ac740 into main Nov 26, 2026
178 checks passed
@hannesrudolph
hannesrudolph deleted the openclaw/briny-crab-5e1fed branch November 26, 2026 07:43
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 27, 2026
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: qa-lab gateway Gateway runtime impact:session-state Session, memory, transcript, context, or agent state can drift or corrupt. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XL 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.

[Bug]: Control UI fork of long conversation fails with size-limit toast and no recovery action

2 participants