Skip to content

fix: clear compaction metadata on session reset - #81367

Closed
moeedahmed wants to merge 1 commit into
openclaw:mainfrom
moeedahmed:fix/session-reset-clears-compaction
Closed

moeedahmed wants to merge 1 commit into
openclaw:mainfrom
moeedahmed:fix/session-reset-clears-compaction

Conversation

@moeedahmed

@moeedahmed moeedahmed commented May 13, 2026 •

Copy link
Copy Markdown
Contributor

Problem

performGatewaySessionReset was preserving compactionCount and compactionCheckpoints from the previous session entry when handling /new and /reset. Fresh sessions inherited stale compaction state from the prior conversation, causing the model to receive bloated context after every reset cycle.

Symptom

Long-running Operator topics on Telegram (General, System, Ledger) progressively degenerate into acknowledgement-only replies after several reset cycles. The transcript fills with "I'll post the result in …" placeholders with no actual model output following.

Fix

Drop the two preserved fields. Reset now truly clears compaction state.

Test

Added server.sessions.reset-models.test.ts covering 7 reset paths. Targeted run passes (1 file, 7 tests).

Real behavior proof

  • Behavior or issue addressed: /new and /reset should start a fresh session instead of preserving stale compaction metadata from the previous session entry.
  • Real environment tested: Moeed's live OpenClaw install on macOS, running Gateway 2026.5.10-beta.1 on 127.0.0.1:18789 after the local source patch was built/restarted.
  • Exact steps or command run after this patch: Checked the live Gateway health, inspected the installed runtime source, and inspected the live Operator session store for the affected Telegram topics after /new had been used.
  • Evidence after fix: Terminal output from the real setup:
$ HOME=/Users/moeedahmed openclaw gateway status --no-color
Service: LaunchAgent (loaded)
Gateway version: 2026.5.10-beta.1
Runtime: running (pid 83391, state active)
Connectivity probe: ok
Capability: admin-capable

$ rg -n "compactionCount: currentEntry|compactionCheckpoints: currentEntry" /opt/homebrew/lib/node_modules/openclaw
(no output)

$ jq 'to_entries[] | select(.key=="agent:openclaw:telegram:group:-1003789377335:topic:1" or .key=="agent:openclaw:telegram:group:-1003789377335:topic:2" or .key=="agent:openclaw:telegram:group:-1003789377335:topic:839") | {key:.key, compactionCount:.value.compactionCount, checkpointCount:(.value.compactionCheckpoints|length)}' /Users/moeedahmed/.openclaw/agents/openclaw/sessions/sessions.json
{ "key": "agent:openclaw:telegram:group:-1003789377335:topic:1", "compactionCount": 0, "checkpointCount": 0 }
{ "key": "agent:openclaw:telegram:group:-1003789377335:topic:2", "compactionCount": 0, "checkpointCount": 0 }
{ "key": "agent:openclaw:telegram:group:-1003789377335:topic:839", "compactionCount": 0, "checkpointCount": 0 }
  • Observed result after fix: The installed runtime no longer contains the reset path that copies compactionCount / compactionCheckpoints from the prior entry, and the affected live Telegram topic sessions are no longer carrying stale checkpoint metadata after reset.
  • Not tested: Live production auto-compaction reproduction was skipped to avoid deliberately bloating active Telegram topics; the regression test covers the stale checkpoint scenario and the live installed-runtime inspection verifies the deployed reset path no longer preserves those fields.

Discovery

Found while debugging stuck-after-ack symptoms on Operator topics on 2026-05-13 BST. Investigation summary lives in workspace memory.

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

clawsweeper Bot commented May 13, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed May 29, 2026, 12:55 AM ET / 04:55 UTC.

Summary
The PR removes compactionCount and compactionCheckpoints from the new gateway session entry created by reset and adds a regression test proving reset leaves those fields unset.

PR surface: Source -2, Tests +61. Total +59 across 2 files.

Reproducibility: yes. A high-confidence source reproduction is to seed a session entry with compactionCount and compactionCheckpoints, call sessions.reset, and observe current main copying those fields into the new entry at src/gateway/session-reset-service.ts:810.

Review metrics: none identified.

Merge readiness
Overall: 🦞 diamond lobster
Proof: 🦞 diamond lobster
Patch quality: 🦞 diamond lobster
Result: ready for maintainer review.

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

Risk before merge

Maintainer options:

  1. Decide the mitigation before merge
    Land this compaction-metadata clearing behavior with the focused regression test after refreshing it against current main or folding it into the canonical reset-cleanup landing path.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Next step before merge

Security
Cleared: The diff only changes gateway session metadata reset behavior and a Vitest regression test; it adds no dependency, workflow, credential, permission, or code-execution surface.

Review details

Best possible solution:

Land this compaction-metadata clearing behavior with the focused regression test after refreshing it against current main or folding it into the canonical reset-cleanup landing path.

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

Yes. A high-confidence source reproduction is to seed a session entry with compactionCount and compactionCheckpoints, call sessions.reset, and observe current main copying those fields into the new entry at src/gateway/session-reset-service.ts:810.

Is this the best way to solve the issue?

Yes. Removing those two preserved fields is the narrow maintainable fix for ordinary reset; the remaining question is only how maintainers want to refresh or combine it with the overlapping reset-cleanup work.

AGENTS.md: found and applied where relevant.

Codex review notes: model gpt-5.5, reasoning high; reviewed against 59cec74d89ff.

Label changes

Label changes:

  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.

Label justifications:

  • P1: The PR addresses a real gateway session-reset regression that can leave long-running channel sessions with stale context metadata and broken agent replies after reset cycles.
  • 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. Sufficient (terminal): The PR body and follow-up comment provide after-fix terminal output from a live Gateway install plus session-store inspection showing compaction metadata cleared after reset.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body and follow-up comment provide after-fix terminal output from a live Gateway install plus session-store inspection showing compaction metadata cleared after reset.
Evidence reviewed

PR surface:

Source -2, Tests +61. Total +59 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 0 2 -2
Tests 1 61 0 +61
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 61 2 +59

Acceptance criteria:

  • [P1] node scripts/run-vitest.mjs run --config test/vitest/vitest.gateway.config.ts src/gateway/server.sessions.reset-models.test.ts.
  • [P1] node scripts/run-vitest.mjs run --config test/vitest/vitest.gateway.config.ts src/gateway/server.sessions.compaction.test.ts src/gateway/server.sessions.reset-hooks.test.ts.

What I checked:

  • Current main still preserves stale compaction metadata: performGatewaySessionReset currently builds nextEntry with compactionCount: currentEntry?.compactionCount and compactionCheckpoints: currentEntry?.compactionCheckpoints, so the central bug is still present on main. (src/gateway/session-reset-service.ts:810, 59cec74d89ff)
  • Latest release still has the same behavior: The latest release tag v2026.5.27 also preserves both compaction metadata fields during reset, so this is not already shipped fixed. (src/gateway/session-reset-service.ts:810, 27ae826f6525)
  • PR patch is narrowly scoped to the implicated reset fields: The PR commit deletes only the two compaction metadata assignments in session-reset-service.ts and adds one focused reset regression test that asserts both fields are undefined in the response and persisted store after reset. (src/gateway/session-reset-service.ts:810, 7715abd3ecd8)
  • Sibling compaction restore behavior remains intentionally separate: cloneCheckpointSessionEntry only preserves compaction checkpoints when preserveCompactionCheckpoints is explicitly true, which supports clearing them on ordinary reset while preserving them for restore flows. (src/gateway/server-methods/sessions.ts:466, 59cec74d89ff)
  • PR discussion includes real setup proof: The PR body and follow-up comment include terminal output from a live macOS Gateway install after an equivalent hot patch, showing the reset path no longer contains the copied compaction fields and affected live session rows have zero compaction count and checkpoint count. (7715abd3ecd8)
  • Merge state and overlap require maintainer routing: Provided GitHub context reports this PR as mergeableState: dirty and identifies overlapping open reset-cleanup work at fix(sessions): rotate reset transcripts and clear compaction state #80251, so maintainers need to choose the refreshed landing path. (7715abd3ecd8)

Likely related people:

  • @scoootscooob: The compaction checkpoint storage surface appears related to feat(gateway): add compaction checkpoints, which added src/gateway/session-compaction-checkpoints.ts and compactionCheckpoints to session types. (role: feature introducer; confidence: high; commits: f4fcaa09a358; files: src/gateway/session-compaction-checkpoints.ts, src/config/sessions/types.ts)
  • @steipete: git shortlog shows Peter Steinberger as the highest-volume contributor across the central reset and compaction files sampled for this review. (role: heavy area contributor; confidence: medium; commits: 27ae826f6525; files: src/gateway/session-reset-service.ts, src/gateway/server.sessions.reset-models.test.ts, src/gateway/server.sessions.compaction.test.ts)
  • @Takhoffman: Recent history includes session reset and compaction fixes by Tak Hoffman, including preserving CLI bindings across reset and target-agent compaction repair. (role: adjacent reset and compaction contributor; confidence: medium; commits: fa56682b3ced, bef2fde77f84; files: src/gateway/session-reset-service.ts, src/gateway/server.sessions.compaction.test.ts)
  • @vincentkoc: Recent reset history includes gateway session reset admin/default work and compaction type refactors in the same broad surface. (role: adjacent gateway reset contributor; confidence: medium; commits: 50f6a2f136fe, 0aa4950d21af, 74e7b8d47b18; files: src/gateway/session-reset-service.ts, src/gateway/server.sessions.compaction.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.

@moeedahmed

moeedahmed commented May 13, 2026 •

Copy link
Copy Markdown
Contributor Author

After-fix proof from a real setup

Applied an equivalent hot-patch on a production OpenClaw install while waiting for this PR to land. Same effective edit as this diff, applied directly to the compiled bundle of the running install (couldn't deploy from source due to a separate @earendil-works/pi-ai dependency issue in the local 2026.5.12 build, unrelated to this fix).

Setup

  • OpenClaw 2026.5.10-beta.1 (commit 2e37b03ed), stable channel
  • macOS 26.0 (Apple Silicon M4, 16 GB), Node 22.22.1
  • 4 active agents on Telegram (Operator, Medic, Founder, Guardian)
  • Operator under heaviest use, with multiple group topics including General, System, and Ledger

Patch applied

File: dist/session-reset-service-hA0oyPFP.js in the installed bundle. The two lines from this PR's diff (corresponding to source session-reset-service.ts:719-720) were removed:

compactionCount: currentEntry?.compactionCount,
compactionCheckpoints: currentEntry?.compactionCheckpoints,

Verifications:

  • grep -c 'compactionCount\|compactionCheckpoints' → 0
  • node --check <file> → clean
  • Gateway restarted cleanly via safe-restart.sh at 2026-05-13T10:23:21+01:00; new PID, port 18789 bound, /health returns {"ok":true,"status":"live"}
  • Zero ERR_MODULE_NOT_FOUND / startup errors in gateway.err.log since the restart (continuous uptime since 10:23)

Symptom evidence — before

The Operator topic watchdog (runs every 10 min) was finding stale sessions repeatedly through the morning:

2026-05-13 08:20  STALE topic=839 (Ledger)
2026-05-13 08:20  STALE topic=1   (General)
2026-05-13 09:50  STALE topic=1   (General)
2026-05-13 10:00  STALE topic=2   (System)
2026-05-13 10:00  STALE topic=839 (Ledger)

Gateway stderr during this window showed the corresponding stuck pattern repeating per topic:

[diagnostic] stalled session: ... sessionKey=agent:openclaw:telegram:group:.../topic:2 state=processing
  age=88s queueDepth=3 reason=active_work_without_progress classification=stalled_agent_run
  activeWorkKind=model_call lastProgress=model_call:started lastProgressAge=88s recovery=none

Plus the eventual 1,830,000 ms (CommandLaneTaskTimeoutError) lane timeouts that flow from those stalls.

Symptom evidence — after

Continuous clean watchdog readings since the hot-patch restart at 10:23:

2026-05-13 10:30  No stale Operator topic sessions found.
2026-05-13 10:40  No stale Operator topic sessions found.
2026-05-13 10:50  No stale Operator topic sessions found.
2026-05-13 11:00  No stale Operator topic sessions found.
(continuing clean)
  • Zero new stalled session entries in gateway.err.log since the patched restart
  • Live Telegram traffic on General / System / Ledger flows normally — no acknowledgement-only stuck pattern, no progressive degradation across /new or /reset cycles

Observation window so far: ~40 minutes of clean uptime. Happy to extend monitoring and follow up if a longer window would be valuable, or share raw watchdog log excerpts and individual session traces on request.

Re-review progress:

@openclaw-barnacle openclaw-barnacle Bot added proof: supplied External PR includes structured after-fix real behavior proof. and removed triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels May 13, 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 May 28, 2026
@clawsweeper clawsweeper Bot added 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. P1 High-priority user-facing bug, regression, or broken workflow. labels May 28, 2026
@clawsweeper

clawsweeper Bot commented May 28, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper PR egg: ✨ hatched 🌱 uncommon Frosted Review Wisp. Rarity: 🌱 uncommon. Trait: sparkles near resolved comments.

Details

Share on X: post this hatch
Copy: My PR egg hatched a 🌱 uncommon Frosted Review Wisp in ClawSweeper.
Hatchability:

  • Merged PRs are hatchable.
  • Open PRs are hatchable when they are status: 👀 ready for maintainer look, status: 🚀 automerge armed, or labeled clawsweeper:automerge.
  • Closed unmerged PRs are hatchable only when one of those hatchable labels is still present in the durable record.

About:

  • Eggs appear after real-behavior proof passes. They are collectible flavor only.
  • Review momentum changes the shell state: follow-up work warms it, re-review makes it wobble, and a clean final review lets it hatch.
  • The hatch is seeded from this repository and PR number, so the same PR keeps the same creature; the reviewed head SHA can only change safe visual details.
  • Rarity is just collectible sparkle: 🥚 common, 🌱 uncommon, 💎 rare, ✨ glimmer, and 🌈 legendary.

@openclaw-barnacle openclaw-barnacle Bot removed the stale Marked as stale due to inactivity label May 29, 2026
@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels May 29, 2026
@moeedahmed moeedahmed closed this by deleting the head repository May 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. proof: supplied External PR includes structured after-fix real behavior proof. 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