Skip to content

fix: first turn after /new stays below transcript fuse - #124126

Merged
fuller-stack-dev merged 1 commit into
openclaw:mainfrom
fuller-stack-dev:fix/reset-window-byte-stats
Aug 15, 2026
Merged

fuller-stack-dev merged 1 commit into
openclaw:mainfrom
fuller-stack-dev:fix/reset-window-byte-stats

Conversation

@fuller-stack-dev

Copy link
Copy Markdown
Member

Closes #119984
Closes #123334

What Problem This Solves

Fixes an issue where the first turn after /new could immediately fail with “Context is too large and auto-compaction could not recover this turn” when discarded SQLite transcript rows from the previous reset generation exceeded maxActiveTranscriptBytes.

This also resolves the remaining current-main cause behind #123334. Keeping the OpenClaw channel session ID and durable rows across /new is intentional; current binding lifecycle tests prove that the retired in-place Codex generation can be reclaimed and rebound to a fresh native thread.

Why This Change Was Made

The authoritative transcript statistics reader now uses the same reset-window owner as model context. It counts the exact retained reset prelude—including valid paired tool results—plus post-reset events, while excluding discarded history and orphaned retained results. Cached retained-tail facts are reused across ordinary post-reset appends and invalidated when the reset boundary, branch, compaction, or projection generation changes.

This is a fresh-current-main successor to #120059, whose root-cause direction was correct. Current main added paired tool-result retention after that contributor head, so merging it unchanged would undercount model-visible reset context. Credit to @ayaangazali for identifying the canonical reset-window owner and supplying the original focused repair.

The change does not rotate session IDs, change Codex/OpenClaw runtime selection, modify config/default surfaces, alter SQLite schema, or change explicit Codex context-window/native auto-compaction settings.

Production LOC: +76/-32 (net +44), justified by making reset-window projection the shared owner of logical statistics and adding bounded cache invalidation. Tests: +179/-4.

User Impact

After /new, discarded pre-reset bytes can no longer keep a Codex-backed session stuck above the transcript fuse. A genuinely oversized new generation is still protected, and both fresh and persisted/upgraded OpenAI selections remain on the Codex runtime.

Evidence

  • Base red at 26ff3c96071726e582a05e720e64829e1749c9f4: logical history was three messages, but the fuse still measured 32,929 bytes from discarded rows. Blacksmith run
  • Focused head proof: discarded pre-reset bytes, paired-result accounting, oversized post-reset negative control, cache reuse, branch-change invalidation, and persisted 1M Codex budget all pass. Blacksmith run
  • Source-blind behavior validation: 16/16 reset-window cases and the persisted-Codex fuse contract pass. Run 1, verbose run
  • Current-main lifecycle proof: same-ID /new preservation, persisted Codex migration, 1.05M native rollout window, in-place binding reclaim, and cleared-binding fresh-thread start pass. Blacksmith run
  • Fresh OpenAI selection policy: 19/19 pass. Blacksmith run
  • Changed-file gate: formatting, core/core-test typecheck, lint, dependency/boundary guards, database-first guard, and import-cycle checks pass. Blacksmith run
  • Required Codex autoreview: clean, no actionable findings; paired tool-result context ownership and cache invalidation were explicitly reviewed.
  • Direct Codex contract inspection at openai/codex@85fc4def358b: unavailable thread IDs return thread not found; thread/start owns a new native thread; thread/compact/start loads the binding then submits Op::Compact; native model_context_window and model_auto_compact_token_limit remain independent configuration fields.

Real gateway proof is not claimed: the Testbox API-key attempt failed before a model turn because the active runtime snapshot had no resolved OpenAI API key. The staged Codex-auth rerun was stopped without a behavior verdict after the live lane was declared externally blocked. No private Rosita data was used.

@clawsweeper

clawsweeper Bot commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added size: M maintainer Maintainer-authored PR labels Aug 15, 2026
@fuller-stack-dev
fuller-stack-dev force-pushed the fix/reset-window-byte-stats branch from 0e42ad7 to e61c1c3 Compare August 15, 2026 09:11
@clawsweeper clawsweeper Bot added merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. 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. labels Aug 15, 2026
@clawsweeper

clawsweeper Bot commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 15, 2026, 5:16 AM ET / 09:16 UTC.

ClawSweeper review

What this changes

The PR makes the transcript byte fuse after /new count the retained reset prelude and post-reset events instead of discarded durable history.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep open. Current main still counts all active SQLite transcript rows through a reset; this PR moves byte statistics to the reset-window owner that matches model-context retention. No concrete patch defect was found; normal maintainer landing review remains appropriate.

Priority: P1
Reviewed head: e61c1c327389a2edc81e48808afa51baca0c298c

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch is a coherent owner-boundary repair with focused regression coverage and no supported correctness finding.
Proof confidence 🌊 off-meta tidepool Not applicable: The author is a repository MEMBER, so the external-contributor proof gate does not apply; the body supplies focused reader and memory-path evidence but does not claim a live gateway run.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The author is a repository MEMBER, so the external-contributor proof gate does not apply; the body supplies focused reader and memory-path evidence but does not claim a live gateway run.
Evidence reviewed 6 items Current-main defect path: The current implementation aggregates every active event's serialized bytes, while the memory guard uses that value to force compaction when it reaches the configured fuse. The scoped diff from the PR base to supplied current main has no changes in these paths.
Owner-boundary repair: The branch delegates active statistics to a reset-window reader, which sums post-boundary active rows and selector-approved retained prelude rows.
Model-context contract: The directly imported agent-core selector retains user and assistant messages plus paired tool results, matching the model-context reset path rather than the former display-only message filter.
Findings None None.
Security None None.

How this fits together

SQLite stores conversation events across resets, while the reset-window projection decides what the next model thread actually receives. The memory guard consumes transcript byte statistics before deciding whether to compact, so this change aligns that guard with model-visible context.

flowchart LR
  A[Incoming chat turn] --> B[SQLite transcript events]
  B --> C[Reset-window projection]
  C --> D[Logical byte statistics]
  D --> E[Memory compaction guard]
  E --> F[Model turn]
  C --> F
Loading

Before merge

  • Resolve merge risk (P1) - The supplied check snapshot still has exact-head validation in progress, so landing should wait for those checks to complete.
  • Resolve merge risk (P1) - Production grows by 44 net lines to cache retained-tail facts; the calculation should remain solely in the reset-window owner to avoid divergent byte accounting.
  • Complete next step (P2) - This member-authored PR carries the protected maintainer label and has no concrete automated repair to perform; finish ordinary landing review after exact-head checks.
Agent review details

Security

None.

PR surface

Source +44, Tests +175. Total +219 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 2 76 32 +44
Tests 2 179 4 +175
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 255 36 +219

Review metrics

Metric Value Why it matters
Production versus test delta production +76/-32 (net +44); tests +179/-4 (net +175) The added production code caches retained reset-tail accounting while focused tests cover the reset, paired-result, and preflight cases.

Stored data model

Persistent data-model change detected: serialized state: src/config/sessions/session-accessor.sqlite-active-events.test.ts, serialized state: src/config/sessions/session-accessor.sqlite-active-events.ts, serialized state: src/config/sessions/session-accessor.sqlite-reset-window.ts, unknown-data-model-change: src/config/sessions/session-accessor.sqlite-active-events.test.ts, unknown-data-model-change: src/config/sessions/session-accessor.sqlite-reset-window.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Complete exact-head validation (recommended)
    Wait for the in-progress exact-head checks to finish before merging the persisted-transcript accounting change.

Technical review

Best possible solution:

Keep one canonical reset-window statistics reader backed by the shared retained-entry selector, then land after exact-head validation completes; no net-neutral alternative can derive the previously unavailable retained paired-result byte facts.

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

Yes—source-reproducible. Current main sums the full active projection after a reset, and the linked oversized-history/reset/small-turn scenario directly reaches the byte-fuse decision.

Is this the best way to solve the issue?

Yes. Moving the calculation to the reset-window owner makes it follow the same retained-entry contract as model context; a consumer-side bypass or session-ID rotation would leave other accounting paths divergent or alter lifecycle semantics.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against fe5fa802fa27.

Labels

Label changes:

  • add P1: The existing /new recovery action can leave an affected session unable to make another model turn.
  • add merge-risk: 🚨 session-state: The PR changes which persisted transcript events contribute to compaction decisions after a reset.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The author is a repository MEMBER, so the external-contributor proof gate does not apply; the body supplies focused reader and memory-path evidence but does not claim a live gateway run.

Label justifications:

  • P1: The existing /new recovery action can leave an affected session unable to make another model turn.
  • merge-risk: 🚨 session-state: The PR changes which persisted transcript events contribute to compaction decisions after a reset.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The author is a repository MEMBER, so the external-contributor proof gate does not apply; the body supplies focused reader and memory-path evidence but does not claim a live gateway run.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: The available history attributes the active-statistics reader and retained-reset selector to the same projection commit. (role: introduced current session-projection and reset-selector behavior; confidence: high; commits: 2adbdd75c6f8; files: src/config/sessions/session-accessor.sqlite-active-events.ts, src/config/sessions/session-accessor.sqlite-reset-window.ts, packages/agent-core/src/harness/session/tool-result-pairing.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Allow exact-head checks to complete before landing.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@fuller-stack-dev

Copy link
Copy Markdown
Member Author

Maintainer landing review complete for exact head e61c1c327389a2edc81e48808afa51baca0c298c:

  • Exact-head CI completed successfully: all 80 jobs passed, including check-sqlite-session-lifecycle, Windows, lint/typecheck, and the compact test shards.
  • The +44 production-line calculation remains solely in session-accessor.sqlite-reset-window.ts; there is no second byte-accounting policy or caller-side workaround.
  • Repository-native prepare-run passed with hosted exact-head gates and zero review findings.
  • ClawSweeper reported no concrete patch defect; its sole rank-up move (complete exact-head checks) is satisfied.

Current main movement since the reviewed base is unrelated to the reset-window owner/caller/fixtures. No review thread remains unanswered.

@fuller-stack-dev
fuller-stack-dev merged commit 30216f5 into openclaw:main Aug 15, 2026
137 checks passed
@fuller-stack-dev

Copy link
Copy Markdown
Member Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

1 participant