Skip to content

fix(compaction): recover reset Codex sessions - #119985

Closed
clark-wq wants to merge 1 commit into
openclaw:mainfrom
clark-wq:forge/115904-clark-context-compaction
Closed

clark-wq wants to merge 1 commit into
openclaw:mainfrom
clark-wq:forge/115904-clark-context-compaction

Conversation

@clark-wq

@clark-wq clark-wq commented Aug 6, 2026 •

Copy link
Copy Markdown

Related: #115904, #115912.

What Problem This Solves

Fixes an issue where users of long-lived SQLite-backed Codex sessions could receive a fatal preflight compaction error on the first ordinary message after /new. The reset created a small logical context but retained the physical transcript for history, so the byte guard could measure megabytes of pre-reset history and invoke a native compaction path that intentionally hands automatic compaction back to Codex.

Why This Change Was Made

The SQLite byte guard now measures the replay window defined by the latest reset or compaction boundary while preserving every durable transcript event. When a model-locked Codex runtime returns its automatic-compaction ownership result for a genuinely oversized current replay window, required byte preflight falls through to semantic compaction and then the guarded thread/compact/start native handoff.

This is a focused current-main integration of the replay-window accounting shape in #115912 with the locked-Codex preflight path that the earlier candidate does not cover.

User Impact

After /new, the next ordinary message can reach model dispatch even when the retained physical transcript exceeds maxActiveTranscriptBytes. Genuinely oversized current Codex windows still take the bounded semantic-plus-native compaction path instead of treating expected ownership as a fatal error. No transcript rows are deleted or rewritten by this fix.

Evidence

Validated at exact head 805c66e8732b24b5eae4e68eef63cb83e020478c:

  • corepack pnpm exec vitest run src/config/sessions/session-accessor.sqlite-active-events.test.ts src/auto-reply/reply/agent-runner-memory.test.ts src/agents/embedded-agent-runner/compact-reasons.test.ts src/agents/embedded-agent-runner/compact.hooks.test.ts — 344 passed.
  • Regression builds a 4.3 MB retained transcript, appends an in-place reset, proves replay-window bytes are below 4 KiB, preserves all six durable events, and proves Codex preflight does not run.
  • Model-locked Codex regression proves the ownership result continues through context-engine compaction and the guarded after_context_engine native handoff.
  • corepack pnpm exec oxlint --type-aware --deny-warnings <12 changed files> — passed.
  • corepack pnpm exec oxfmt --check <12 changed files> — passed.
  • node scripts/check-kysely-guardrails.mjs — passed.
  • corepack pnpm build — passed.
  • git diff --check — passed before commit.

AI-assisted: Forge implemented and validated this change from a deterministic production RCA. Independent live Discord verification remains intentionally separate.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: L labels Aug 6, 2026
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. labels Aug 6, 2026
@clawsweeper

clawsweeper Bot commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed August 25, 2026, 9:39 PM ET / August 26, 2026, 01:39 UTC.

ClawSweeper review

What this changes

The branch makes SQLite transcript byte preflight use the post-reset or post-compaction replay window and lets locked Codex sessions continue compaction after an automatic-compaction ownership response.

Merge readiness

⛔ Blocked until real behavior proof from a real setup is added - 9 items remain

Keep this draft PR open for now, but block merge: it uses a public harness-result string to escape a model-locked compaction path, while current main has later, safer implementations of both central behaviors. The branch also lacks required real behavior proof.

Priority: P1
Reviewed head: 805c66e8732b24b5eae4e68eef63cb83e020478c

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The patch has a blocking lock-boundary defect and no real after-fix behavior proof.
Proof confidence 🧂 unranked krab (1/6) Needs real behavior proof before merge: Authority-chain proof required: the body reports focused tests and builds, but the supplied evidence only mocks the ownership result and does not show a real SQLite/Codex run or rejection of the nearest generic locked harness before compaction I/O. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🧂 unranked krab (1/6) Security review found an item that needs attention.

Verification

Check Result Evidence
Real behavior Needs proof Needs real behavior proof before merge: Authority-chain proof required: the body reports focused tests and builds, but the supplied evidence only mocks the ownership result and does not show a real SQLite/Codex run or rejection of the nearest generic locked harness before compaction I/O. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed 6 items Public result bypasses model lock: The branch permits a successful, non-compacting result with the exported ownership reason to fall through a locked harness into context-engine compaction.
Current main has a safer owner boundary: Later main commit 16cde04 uses a private registered native-compaction capability before allowing required locked-harness fallback, rather than trusting public result fields.
Current main covers replay-window accounting: Later main commit 30216f5 scopes the transcript fuse to the reset window across the SQLite accessor and preflight caller.
Findings 1 actionable finding [P1] Keep public harness results from escaping a model lock
Security Needs attention Do not authorize fallback with a public result string: Any harness can return the matching ownership reason, allowing a locked run to enter context-engine compaction without the host-owned capability current main requires.

How this fits together

SQLite retains full agent transcripts for history, while the agent runner derives a replay window to decide whether compaction is needed before model dispatch. That preflight may invoke the native Codex harness or the context engine.

flowchart LR
  A[Durable SQLite transcript] --> B[Replay-window boundary]
  B --> C[Byte preflight]
  C --> D{Compaction needed}
  D -->|No| E[Model dispatch]
  D -->|Yes| F[Native harness]
  F --> G[Context engine]
  G --> E
Loading

Before merge

  • Add real behavior proof - Needs real behavior proof before merge: Authority-chain proof required: the body reports focused tests and builds, but the supplied evidence only mocks the ownership result and does not show a real SQLite/Codex run or rejection of the nearest generic locked harness before compaction I/O. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Keep public harness results from escaping a model lock (P1) - This treats a free-form public result reason as authority to escape modelSelectionLocked and invoke context-engine compaction. Use current main’s registered native-compaction capability instead; a generic harness can otherwise forge the same result. This concern is late relative to the unchanged prior-reviewed head, based on newer current-main owner-boundary evidence.
  • Resolve security concern: Do not authorize fallback with a public result string - Any harness can return the matching ownership reason, allowing a locked run to enter context-engine compaction without the host-owned capability current main requires.
  • Resolve merge risk (P1) - Merging the branch can let a free-form harness result override a persisted model lock and route compaction through a different owner.
  • Resolve merge risk (P1) - The draft is divergent from current main, which already has newer reset-window and required-preflight implementations; it needs a rebase before its remaining value can be assessed.
  • Resolve merge risk (P1) - Upstream Codex source could not be inspected because the required sibling source and network path were unavailable.
  • Improve patch quality - Rebase onto current main’s private registered-native capability design.
  • Improve patch quality - Add negative proof that a generic locked harness cannot reach context-engine compaction and positive proof for registered Codex capability.
  • Improve patch quality - Attach redacted after-fix SQLite/Codex runtime evidence showing reset recovery reaches dispatch.

Findings

  • [P1] Keep public harness results from escaping a model lock — src/agents/embedded-agent-runner/compact.queued.ts:568-577
  • [medium] Do not authorize fallback with a public result string — src/agents/embedded-agent-runner/compact.queued.ts:568
Agent review details

Security

Needs attention: The patch lets a public harness result cross a persisted model-selection lock before the provider-side compaction effect.

PR surface

Source +148, Tests +204. Total +352 across 12 files.

View PR surface stats
Area Files Added Removed Net
Source 8 255 107 +148
Tests 4 204 0 +204
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 12 459 107 +352

Review metrics

Metric Value Why it matters
Production versus test delta production +255/-107, tests +204/-0 The sizeable runtime change crosses persisted transcript accounting and locked-harness routing, so it needs the current owner-boundary design rather than branch-era fallback logic.

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-active-stats.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-active-events.ts, and 2 more. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Rebase onto the current owner-boundary design (recommended)
    Replace the public-string fallback with current main’s registered native-compaction capability and retain paired-tool-result replay accounting.
  2. Pause the obsolete draft
    Keep the branch out of merge consideration if its intended behavior is fully covered by the later main fixes after live GitHub provenance is confirmed.

Technical review

Best possible solution:

Rebase onto current main’s replay-window owner and private registered native-compaction capability, then prove that only registered Codex capability can cross the locked preflight boundary.

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

Yes, from source: a generic locked harness can return the matching public reason and reach context-engine compaction through the changed fallback branch.

Is this the best way to solve the issue?

No. Current main uses a private registered native capability for this escape hatch, which preserves the lock boundary without trusting a public result string.

Full review comments:

  • [P1] Keep public harness results from escaping a model lock — src/agents/embedded-agent-runner/compact.queued.ts:568-577
    This treats a free-form public result reason as authority to escape modelSelectionLocked and invoke context-engine compaction. Use current main’s registered native-compaction capability instead; a generic harness can otherwise forge the same result. This concern is late relative to the unchanged prior-reviewed head, based on newer current-main owner-boundary evidence.
    Confidence: 0.94
    Late finding: first raised on code an earlier review cycle already covered.

Overall correctness: patch is incorrect
Overall confidence: 0.94

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P1: A model-locked compaction path can be bypassed by a public harness result, affecting active agent runs.
  • merge-risk: 🚨 compatibility: The draft changes compaction behavior for existing SQLite-backed and model-locked sessions.
  • merge-risk: 🚨 session-state: It changes how reset and compaction boundaries determine replay-window state.
  • merge-risk: 🚨 security-boundary: A public harness result can authorize escape from a persisted model-selection lock.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🧂 unranked krab.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: Authority-chain proof required: the body reports focused tests and builds, but the supplied evidence only mocks the ownership result and does not show a real SQLite/Codex run or rejection of the nearest generic locked harness before compaction I/O. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Evidence

Security concerns:

  • [medium] Do not authorize fallback with a public result string — src/agents/embedded-agent-runner/compact.queued.ts:568
    Any harness can return the matching ownership reason, allowing a locked run to enter context-engine compaction without the host-owned capability current main requires.
    Confidence: 0.94

What I checked:

Likely related people:

  • fuller-stack-dev: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • SunnyShu: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

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.

History

Review history (2 earlier review cycles)
  • reviewed 2026-08-06T15:38:18.766Z sha 805c66e :: needs real behavior proof before merge. :: [P1] Preserve the locked-Codex preflight path under the default engine
  • reviewed 2026-08-06T23:33:50.181Z sha 805c66e :: needs real behavior proof before merge. :: [P2] Count replayed entries instead of all post-reset rows

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Aug 15, 2026
@clawsweeper clawsweeper Bot added the merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. label Aug 26, 2026
@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label Sep 16, 2026
@openclaw-barnacle

Copy link
Copy Markdown

Closing due to inactivity.
If you believe this PR should be revived, post in #clawtributors on Discord to talk to a maintainer.
That channel is the escape hatch for high-quality PRs that get auto-closed.

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

Labels

agents Agent runtime and tooling merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. 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: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: L stale Marked as stale due to inactivity status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant