Skip to content

fix(sessions): rotate reset transcripts and clear compaction state - #80251

Closed
fredrikmacmini wants to merge 1 commit into
openclaw:mainfrom
fredrikmacmini:goran/session-reset-sourcefix-20260510
Closed

fredrikmacmini wants to merge 1 commit into
openclaw:mainfrom
fredrikmacmini:goran/session-reset-sourcefix-20260510

Conversation

@fredrikmacmini

@fredrikmacmini fredrikmacmini commented May 10, 2026 •

Copy link
Copy Markdown

Summary

Fix sessions.reset so a reset creates a fresh generated transcript path for the new session id and clears stale compaction state.

This source patch makes permanent the behavior we previously had to protect with a local installed-dist hotfix: reset should not keep pointing at an old heavy transcript/checkpoint lineage after generating a new sessionId.

Problem

Before this change, sessions.reset generated a new sessionId but could preserve the old sessionFile, compactionCount, and compactionCheckpoints. In practice that can make a reset session continue to inherit old heavy transcript/checkpoint state, defeating the reset and risking immediate context/compaction failures on the next turn.

Changes

  • Add resolveRotatedGeneratedSessionFilePath(...) for safe generated transcript rotation.
  • Rotate generated UUID transcript names from <oldSessionId>.jsonl to <newSessionId>.jsonl.
  • Preserve generated topic suffixes, e.g. <oldSessionId>-topic-ops.jsonl → <newSessionId>-topic-ops.jsonl.
  • Preserve custom/non-generated session file behavior by falling back to the existing resolveSessionFilePath(...) path.
  • Clear reset compaction state with compactionCount: 0 and compactionCheckpoints left undefined (omitted when serialized).
  • Add regression coverage for helper behavior, topic transcript rotation, compaction cleanup, and custom transcript preservation.

Real behavior proof

  • Behavior or issue addressed: sessions.reset should not keep a reset session attached to an old heavy transcript file or stale compaction checkpoint lineage after generating a new sessionId.
  • Real environment tested: Mac mini, Darwin 25.4.0 arm64, live OpenClaw 2026.5.7 installation plus isolated source worktree goran/session-reset-sourcefix-20260510.
  • Exact steps or command run after fix: Live installed runtime was verified with OpenClaw system-test L2 and the session reset guard; the source patch was then verified in an isolated worktree with targeted reset/session tests. No live install from this PR branch was performed.
  • Evidence after fix: Copied terminal output from the real Mac mini setup:
$ python3 skills/system-test/scripts/system_test.py --level L2 --json
session_reset_guard: pass — guard markers present in 1 dist file(s)
active_session_model_route_divergence: pass — recent active sessions match configured primary models
memory_embedding_coverage: pass — missing embeddings 0
openclaw_docs_index_freshness: pass — docs index fresh
summary: 45 passed, 0 failed, 0 warnings

$ node scripts/run-vitest.mjs run --config test/vitest/vitest.runtime-config.config.ts src/config/sessions/sessions.test.ts
runtime-config src/config/sessions/sessions.test.ts: 29 tests passed

$ node scripts/run-vitest.mjs run --config test/vitest/vitest.gateway.config.ts src/gateway/server.sessions.reset-models.test.ts src/gateway/server.sessions.reset-hooks.test.ts src/gateway/server.sessions.compaction.test.ts src/gateway/session-utils.fs.test.ts
gateway targeted reset/compaction/session-utils suite: 4 files passed, 101 tests passed
  • Observed result after fix: The live OpenClaw setup is stable with the equivalent reset-rotation/checkpoint-clearing behavior guarded at L1/L2, and the source patch reproduces that behavior with regression coverage for generated UUID transcripts, topic transcript suffixes, drifted UUID basenames, custom transcript preservation, escape rejection, and compaction cleanup.
  • What was not tested: This PR branch was not installed into the live runtime; live runtime remains protected by the existing guarded installed-dist hotfix until a separate release/update integration gate.

Tests

  • corepack pnpm exec oxfmt --check --threads=1 src/config/sessions/paths.ts src/config/sessions/sessions.test.ts src/gateway/session-reset-service.ts src/gateway/server.sessions.reset-models.test.ts
  • corepack pnpm exec oxlint src/config/sessions/paths.ts src/config/sessions/sessions.test.ts src/gateway/session-reset-service.ts src/gateway/server.sessions.reset-models.test.ts
  • node scripts/run-vitest.mjs run --config test/vitest/vitest.runtime-config.config.ts src/config/sessions/sessions.test.ts
  • node scripts/run-vitest.mjs run --config test/vitest/vitest.gateway.config.ts src/gateway/server.sessions.reset-models.test.ts src/gateway/server.sessions.reset-hooks.test.ts src/gateway/server.sessions.compaction.test.ts src/gateway/session-utils.fs.test.ts

Review evidence

A local Claude Opus/Max read-only review first returned APPROVE_WITH_CHANGES because helper/topic/custom-path test coverage was incomplete. After adding those tests, the final Claude review returned APPROVE with no remaining blocker.

Notes

  • This is source-only; no live runtime install is included in this PR.
  • Existing custom session file behavior is intentionally preserved.
  • The helper treats UUID-shaped drifted basenames as generated, which is intentional for first reset after a previous stale session-file bug.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: M triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels May 10, 2026
@clawsweeper

clawsweeper Bot commented May 10, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 3, 2026, 11:48 PM ET / 03:48 UTC.

Summary
The branch adds reset transcript rotation logic, clears compaction metadata during gateway session reset, and adds session path/reset regression tests.

PR surface: Source +83, Tests +197. Total +280 across 4 files.

Reproducibility: yes. at source level: seed a session entry with compactionCount and compactionCheckpoints, call sessions.reset, and current main copies both fields into the new entry. I did not run a local repro because this review is read-only.

Review metrics: 2 noteworthy metrics.

  • Persisted reset state changes: 2 fields cleared. compactionCount and compactionCheckpoints are persisted session metadata, so the reset-state behavior change needs upgrade and real-runtime proof before merge.
  • Parallel transcript rotation helper: 1 added. Current main already has a reset transcript rotation helper, so adding a second filename grammar creates drift risk.

Stored data model
Persistent data-model change detected: serialized state: src/config/sessions/paths.ts, serialized state: src/config/sessions/sessions.test.ts, serialized state: src/gateway/server.sessions.reset-models.test.ts, serialized state: src/gateway/session-reset-service.ts, unknown-data-model-change: src/config/sessions/paths.ts, unknown-data-model-change: src/config/sessions/sessions.test.ts, and 1 more. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster
Relationship: canonical
Canonical: #80251
Summary: This PR remains the open canonical item for the remaining reset compaction-state cleanup; merged current-main work already covers the transcript-rotation overlap.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge readiness
Overall: 🦪 silver shellfish
Proof: 🦪 silver shellfish
Patch quality: 🦐 gold shrimp
Result: blocked until stronger real behavior proof is added.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • Refresh onto current main and remove the duplicate transcript rotation helper.
  • [P1] Add redacted branch-live terminal or gateway-state proof showing reset clears compaction metadata after running this PR branch.

Proof guidance:

  • [P1] Needs stronger real behavior proof before merge: The PR has related live-hotfix terminal output, but it says this branch was not installed or run; add redacted branch-live terminal, gateway-state, or log proof, update the PR body, and ask a maintainer for @clawsweeper re-review if it does not rerun automatically.

Risk before merge

  • [P1] The PR branch is currently dirty/conflicting against main and cannot land as submitted.
  • [P1] The transcript-rotation half duplicates current main's session-file-rotation path, so refreshing without narrowing could split generated, topic, fork, or stale-id filename handling.
  • [P1] The supplied real behavior proof is related terminal/live-hotfix proof, but it does not show this PR branch running in the real runtime.
  • [P1] The PR changes persisted reset session metadata, so maintainers need upgrade/session-store proof for the compaction cleanup before merge.

Maintainer options:

  1. Refresh and narrow the branch (recommended)
    Rebase onto current main, reuse the existing reset transcript rotation helper, keep only the compaction cleanup and regression test, and add branch-live proof before merge.
  2. Replace with a fresh narrow PR
    If this stale branch is too costly to repair, maintainers can open or select a current-main PR that only clears reset compaction state and then close this source PR.

Next step before merge

  • [P1] Contributor or maintainer action is needed to refresh and narrow the conflicted branch and supply branch-live proof; automation should not repair while the contributor proof gate is insufficient.

Security
Cleared: No concrete security or supply-chain concern was found; the diff is limited to TypeScript session reset/path logic and tests.

Review findings

  • [P1] Reuse the current reset transcript rotation helper — src/config/sessions/paths.ts:240-262
Review details

Best possible solution:

Refresh onto current main, drop the duplicate rotation helper, keep the compaction reset cleanup and focused regression coverage, then supply redacted branch-live gateway/session-store proof.

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

Yes at source level: seed a session entry with compactionCount and compactionCheckpoints, call sessions.reset, and current main copies both fields into the new entry. I did not run a local repro because this review is read-only.

Is this the best way to solve the issue?

No for the submitted branch; clearing reset compaction state is the right narrow behavior, but the branch should reuse current main's reset transcript rotation helper instead of adding a second grammar.

Full review comments:

  • [P1] Reuse the current reset transcript rotation helper — src/config/sessions/paths.ts:240-262
    Current main already routes reset transcript rotation through resolveResetSessionFile using extractGeneratedTranscriptSessionId and rewriteSessionFileForNewSessionId, including fork and stale embedded-id cases. This helper adds a second generated filename grammar, so refresh the PR to keep the compaction cleanup on top of the existing helper.
    Confidence: 0.88

Overall correctness: patch is incorrect
Overall confidence: 0.88

AGENTS.md: found and applied where relevant.

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

Label changes

Label justifications:

  • P1: The remaining reset compaction-state bug can keep real channel sessions under stale context and checkpoint pressure after a user-visible reset.
  • merge-risk: 🚨 session-state: The PR changes persisted reset session metadata and, as submitted, duplicates transcript filename rotation logic that current main already owns.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: The PR has related live-hotfix terminal output, but it says this branch was not installed or run; add redacted branch-live terminal, gateway-state, or log proof, update the PR body, and ask a maintainer for @clawsweeper re-review if it does not rerun automatically.
Evidence reviewed

PR surface:

Source +83, Tests +197. Total +280 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 2 94 11 +83
Tests 2 197 0 +197
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 291 11 +280

What I checked:

  • Repository policy read: Root AGENTS.md and scoped gateway AGENTS.md were read fully; their review guidance on session state, persisted data, and whole-path PR review affected this review. (AGENTS.md:1, 9d68f877ac3e)
  • Current main still preserves reset compaction metadata: The reset entry on current main still copies compactionCount and compactionCheckpoints from the prior session entry, so the remaining compaction-state problem is not implemented on main. (src/gateway/session-reset-service.ts:1030, 9d68f877ac3e)
  • Current main already owns reset transcript rotation: Current main routes reset transcript rotation through resolveResetSessionFile with extractGeneratedTranscriptSessionId and rewriteSessionFileForNewSessionId, including stale embedded-id handling. (src/gateway/session-reset-service.ts:76, 9d68f877ac3e)
  • Current main tests cover the transcript-rotation overlap: Current reset-model tests cover generated topic transcript rotation and already-stale generated transcript filename rotation, which supersedes the PR's added rotation helper portion. (src/gateway/server.sessions.reset-models.test.ts:329, 9d68f877ac3e)
  • Latest release has the same remaining compaction behavior: The v2026.6.11 tag has current reset transcript rotation but still copies compactionCount and compactionCheckpoints on reset, so this is not shipped-fixed either. (src/gateway/session-reset-service.ts:1030, e085fa1a3ffd)
  • PR head adds a parallel filename grammar: The PR adds resolveRotatedGeneratedSessionFilePath in paths.ts instead of reusing the reset transcript rotation helper now present on main. (src/config/sessions/paths.ts:240, 65cb593ca928)

Likely related people:

  • scoootscooob: The behavior appears to date to feat(gateway): add compaction checkpoints, which added persisted compaction checkpoint state and the reset path now carrying those fields forward. (role: feature introducer; confidence: high; commits: f4fcaa09a358; files: src/config/sessions/types.ts, src/gateway/session-compaction-checkpoints.ts, src/gateway/session-reset-service.ts)
  • joshavant: Merged work in the same reset path introduced the shared reset transcript rotation helper and topic transcript rotation tests that overlap this PR's transcript half. (role: recent reset-fix contributor; confidence: high; commits: 23f73b3ecfd9; files: src/config/sessions/session-file-rotation.ts, src/gateway/session-reset-service.ts, src/gateway/server.sessions.reset-models.test.ts)
  • harjothkhara: Merged work fixed already-stale generated transcript filename rotation on the same gateway reset path now present on current main. (role: recent reset-fix contributor; confidence: high; commits: d7cebdc215bf; files: src/gateway/session-reset-service.ts, src/gateway/session-transcript-files.fs.ts, src/gateway/server.sessions.reset-models.test.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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.

How this review workflow works
  • 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.

@tianxiaochannel-oss88

Copy link
Copy Markdown
Contributor

Adding live behavior evidence for the remaining compaction-state half of this PR.

This is not a live install of this PR branch. It is evidence from an installed OpenClaw gateway showing that the bug this PR fixes is real in a channel runtime, and that clearing reset compaction state is the right mitigation shape.

Environment:

  • OpenClaw CLI/Gateway: 2026.5.28 (e932160)
  • OS: macOS arm64
  • Node: v24.15.0
  • Channel: Slack, channel-scoped session
  • Provider/API path: openai / openai-responses
  • Model: gpt-5.5

Observed sequence:

  1. A Slack channel session hit context overflow during an embedded run.
  2. The same channel then entered repeated Responses replay retry / recovery pressure.
  3. Running sessions.reset alone rotated the channel to a fresh session id, but the reset entry still carried old overflow compaction state.

Sanitized state shape before the local mitigation:

{
  "status": "failed",
  "hasActiveRun": false,
  "compactionCheckpointCount": 18,
  "latestCompactionCheckpoint": {
    "reason": "overflow-retry"
  }
}

The important point is that this was a post-reset/fresh channel row still inheriting old overflow-retry checkpoint lineage. That makes reset less clean than users expect and can keep the next turn under stale compaction pressure.

Local installed-dist mitigation applied:

compactionCount: 0,
compactionCheckpoints: []

After applying that mitigation, restarting the gateway, and resetting the affected Slack channel again, the new session state came up clean:

{
  "systemSent": false,
  "inputTokens": 0,
  "outputTokens": 0,
  "totalTokens": 0,
  "compactionCheckpointCount": 0,
  "hasActiveRun": false
}

Post-mitigation validation:

  • node --check passed for the patched installed dist files.
  • Gateway restarted successfully.
  • openclaw channels status --probe: Slack running, connected, health:healthy, works.
  • In the verification window after restart/reset, no new overflow-retry compaction checkpoint was inherited by the fresh reset session.

Interpretation:
The transcript-rotation part may overlap newer main work, but the compaction-state cleanup remains independently useful. A reset should not carry compactionCount / compactionCheckpoints from the old overflow lineage into the new session row.

@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 Jun 14, 2026
@clawsweeper

clawsweeper Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

@fredrikmacmini thanks for the PR. ClawSweeper is still waiting on real behavior proof before this can move forward.

Useful proof can be a screenshot, short video, terminal output, copied live output, linked artifact, or redacted logs that show the changed behavior after the fix. Please redact private tokens, phone numbers, private endpoints, customer data, and anything else sensitive.

Once proof is added to the PR body or a comment, ClawSweeper or a maintainer can re-check it.

@steipete

steipete commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor

Thank you for tracking down both reset failure modes and providing focused regression cases. I checked this against current main: the underlying problems are already addressed by merged #113233 (4273ca9dbd9b3e3172f34a7231d41bcd8b5d200c) and #114936 (d894a235e88dd4fa9b262e09e2df7f0f9427ddba). Session transcripts and reset lifecycle are now SQLite-owned rather than generated .jsonl paths. src/gateway/session-reset-service.ts builds a fresh reset entry with compactionCount: 0 and without predecessor checkpoint/context-budget fields; src/config/sessions/session-accessor.sqlite-lifecycle.ts appends an authoritative reset boundary while retaining canonical transcript identity. Current regression coverage in src/gateway/server.sessions.reset-models.test.ts verifies that reset has no legacy sessionFile, clears stale context-budget state, and retains its canonical identity; src/config/sessions/session-accessor.sqlite-active-events.test.ts verifies the post-reset active transcript boundary. Consequently the proposed generated-file rotation would reintroduce retired JSONL runtime instead of implementing the current session contract. Closing as already resolved/superseded; thank you again for the detailed investigation.

@steipete steipete closed this Jul 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime 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. proof: supplied External PR includes structured after-fix real behavior proof. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: M 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.

3 participants