Skip to content

[Bug]: WebChat session transcript overwritten on every turn (5.2 regression — SessionManager removal) #77012

Closed

Description

@dertbv

Bug type

Regression (worked before, now fails)

Beta release blocker

No

Summary

In OpenClaw v2026.5.2, the webchat session JSONL transcript is overwritten on every turn — only the latest message exchange survives. On page refresh, all previous messages are gone. This worked correctly on v2026.4.29.

Root cause

mirrorCodexAppServerTranscript (in run-attempt-*.js) receives the full conversation history via messagesSnapshot (built from readMirroredSessionHistoryMessages at line 3264) and rewrites ALL messages to the JSONL every turn. Each message is written via appendCodexAppServerTranscriptMessage, which calls migrateLinearTranscriptToParentLinked — a function that reads the entire file and rewrites it via fs.writeFile (not append).

The per-turn idempotencyScope (codex-app-server:${threadId}:${turnId}) changes every turn, so old messages get new keys and bypass the idempotency check. The rewrite creates new entries with different parentId chains, causing selectBoundedActiveTailRecords (the tree walk) to follow the newest branch and orphan previous entries.

In v4.29, SessionManager.open().appendMessage() truly appended to the file. The SessionManager was removed in 5.2 and replaced with this read-migrate-rewrite cycle.

Steps to reproduce

  1. Open webchat on v2026.5.2
  2. Send message 1, receive response
  3. Send message 2, receive response
  4. Check the session JSONL — message 1's assistant response is gone
  5. Refresh page — only message 2 and its response are visible

Evidence

Controlled test on macOS arm64, v2026.5.2 (8b2a6e5), stock dist (no patches except prewarm skip):

  • Took a JSONL snapshot between turns
  • Diffed after the next turn
  • The previous assistant response (id 44b4ec62, parentId d3471f25) was replaced by the new user message (id 9f4b19a1, parentId d3471f25) — same parent, sibling branch
  • The tree walk follows the new branch, orphaning the old assistant entry
  • 9 minutes between turns — no race condition, purely the mirror rewrite logic

Contributing factors

  1. migrateLinearTranscriptToParentLinked rewrites via writeFile — any concurrent access or stale read loses data
  2. Per-turn turnId in idempotency scope — old messages get new keys, bypassing dedup
  3. Write lock race (fix: session write lock race — async release can delete newly-acquired lock #57019) — releaseHeldLock deletes HELD_LOCKS before async cleanup, allowing concurrent acquirers on macOS
  4. appendCodexAppServerTranscriptMessage calls migration inside the lock but mirrorCodexAppServerTranscript takes a separate lock per batch — interleaving between the webchat write path and the mirror write path can race

Code references (v2026.5.2 dist)

  • run-attempt-CektiLYp.js:3264 — finalMessages = readMirroredSessionHistoryMessages(sessionFile) (full history)
  • run-attempt-CektiLYp.js:3598 — idempotencyScope: codex-app-server:${threadId}:${turnId} (per-turn keys)
  • run-attempt-CektiLYp.js:2082 — appendCodexAppServerTranscriptMessage triggers migration
  • transcript-C_uDP9Gl.js:121 — migrateLinearTranscriptToParentLinked rewrites file via writeFile
  • transcript-C_uDP9Gl.js:156 — fs.writeFile(transcriptPath, ...) — destructive overwrite
  • session-utils.fs-W0CAUUsv.js:564 — selectBoundedActiveTailRecords tree walk follows one branch

What changed (4.29 → 5.2)

4.29 5.2
Write method SessionManager.open().appendMessage() — true append appendCodexAppServerTranscriptMessage → migrateLinearTranscriptToParentLinked → writeFile — full rewrite
Session read readSessionMessages — sync, reads all readRecentSessionMessagesAsync — async, tail window + tree walk
Branch resolution SessionManager.open().getBranch() selectBoundedActiveTailRecords — drops orphaned branches
Mirror scope Current turn only Full messagesSnapshot (entire history)
Idempotency N/A (true append) Per-turn scope — changes every turn, old messages get new keys

Environment

  • OpenClaw: v2026.5.2 (8b2a6e5), npm global install
  • OS: macOS 26.4.0 arm64 (Mac Mini M4 Pro)
  • Node: 22
  • Channels affected: WebChat (Telegram and BlueBubbles unaffected — different write path)

Related issues

Activity

  1. clawsweeper commented on May 4, 2026

    @clawsweeper
    Contributor

    Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve. Reviewed June 28, 2026, 10:21 AM ET / 14:21 UTC.

    Summary
    Keep this issue open: current main contains the merged Codex app-server mirror idempotency repair from #77046, but that PR explicitly scoped itself as a partial fix and the remaining long-session, cross-channel, and compaction-related transcript-loss path has not been proven resolved on current main.

    Reproducibility: yes. for the already-fixed mirror-idempotency subpath from source and tests, but no high-confidence current-main live reproduction yet for the broader long-session and cross-channel transcript-loss path.

    Next step
    Maintainer review and live repro are needed before another fix PR because the known Codex mirror subpath is already fixed and the remaining writer path is not isolated.

    Review details

    Best possible solution:

    Keep this issue as the canonical tracker until maintainers have a current-main long-session or cross-channel reproduction with before/after JSONL snapshots, then fix the specific transcript writer that creates orphaned or sibling parent-linked records.

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

    Yes for the already-fixed mirror-idempotency subpath from source and tests, but no high-confidence current-main live reproduction yet for the broader long-session and cross-channel transcript-loss path.

    Is this the best way to solve the issue?

    No final fix is proven yet; #77046 is a good partial repair, but the best remaining path is targeted live repro plus source tracing of whichever writer still breaks the parent-linked transcript chain.

    AGENTS.md: found and applied where relevant.

    Remaining risk / open question:

    • No fresh current-main live reproduction has isolated the remaining long-session, cross-channel, or compaction-triggered writer path.
    • The merged fix(codex/app-server): stable mirror idempotency to prevent transcript loss #77046 repair proves one root-cause branch fixed, but its own scope note says the broader sibling-branch symptom likely has at least one additional path.
    • Local history appears shallow/grafted for some files, so ownership routing is based on merged PR provenance and recent area work rather than complete line-level blame.

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

    Label changes

    Label changes:

    • add maturity:stable: The affected Gateway chat.history and hosted WebChat/session surface maps to gateway-runtime, which is scored M4 Stable.

    Label justifications:

    • P1: The reported regression can make prior WebChat/session history disappear for real users, affecting an active agent workflow rather than only polish.
    • impact:data-loss: The issue is about durable session transcript records becoming missing or effectively unreachable from user-visible history.
    • impact:message-loss: The reported symptom is prior user and assistant messages disappearing from WebChat and related session replay views.
    • impact:session-state: The suspected root cause involves parent-linked transcript state, session history projection, cross-channel session continuity, and compaction.
    • maturity:stable: The affected Gateway chat.history and hosted WebChat/session surface maps to gateway-runtime, which is scored M4 Stable.
    Evidence reviewed

    Acceptance criteria:

    • Capture a current-main long-session WebChat reproduction with JSONL before and after the disappearance.
    • Repeat with the reported cross-channel path if available, including WebChat plus Feishu or another channel.
    • Trace all writes through SessionManager.appendMessage or wrapper calls and confirm the parentId chain stays single-branch across compaction/reload.

    What I checked:

    • Issue remains open with maintainer review gates: Live this issue is still open and carries needs-maintainer-review, needs-live-repro, and no-new-fix-pr routing, matching the current lack of a proven current-main long-session reproduction and an owned remaining fix path.
    • Merged partial fix for one Codex mirror failure mode: Current main has mirrorCodexAppServerTranscript using thread-scoped idempotency plus stable per-message identities, which fixes positional snapshot drift but does not by itself prove the broader orphan-branch transcript loss fixed. (extensions/codex/src/app-server/transcript-mirror.ts:101, 4d292caaa429)
    • Issue-specific identity tagging exists on main: The Codex event projector tags prompt, reasoning, plan, assistant, tool call, and tool result messages with stable turn-based identities, with comments tying the invariant to this issue. (extensions/codex/src/app-server/event-projector.ts:339, 4d292caaa429)
    • Regression tests cover the partial idempotency repair: Current tests cover positional-shift dedupe, repeated same-content turns, and prior-turn re-emission, proving the fix(codex/app-server): stable mirror idempotency to prevent transcript loss #77046 repair is present but only for that mirror-idempotency mechanism. (extensions/codex/src/app-server/transcript-mirror.test.ts:523, 4d292caaa429)
    • Active-branch history projection can still hide orphaned records: WebChat history still depends on the active parent-linked transcript tail, so any remaining path that writes sibling or orphaned records can still make older messages disappear from the rendered history. (src/gateway/session-utils.fs.ts:351, 4d292caaa429)
    • WebChat contract expects durable stored conversation history: The docs say Control UI remembers the Gateway sessionId for reconnects and refreshes, and distinguish durable transcript history from live delivery, so disappearing prior turns violates the documented current behavior. Public docs: docs/web/webchat.md. (docs/web/webchat.md:25, 4d292caaa429)

    Likely related people:

    • openperf: Authored and merged the fix(codex/app-server): stable mirror idempotency to prevent transcript loss #77046 Codex app-server transcript mirror identity/idempotency repair that directly references this issue. (role: partial-fix author and recent Codex mirror owner; confidence: high; commits: 14aa98827ab6, 46e4dd77a834; files: extensions/codex/src/app-server/transcript-mirror.ts, extensions/codex/src/app-server/event-projector.ts, extensions/codex/src/app-server/run-attempt.ts)
    • jalehman: Recent merged work in the session transcript runtime and SDK write-lock seam is directly adjacent to the canonical transcript append path involved in this issue. (role: recent session transcript runtime contributor; confidence: medium; files: src/plugin-sdk/session-transcript-runtime.ts, src/config/sessions/transcript-append.ts)
    • ZengWen-DT: Recent cross-channel session origin/reset work is relevant to the issue's reported WebChat plus Feishu and cross-client session-history symptoms. (role: recent cross-channel session-state contributor; confidence: medium; files: src/gateway, src/channels)
    • vincentkoc: Recent compaction/session runtime work is adjacent to the long-session and compaction-linked reproduction path still suspected in the issue discussion. (role: recent compaction and session-state contributor; confidence: medium; files: src/config/sessions, src/agents, src/gateway)
    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.
  2. mjamiv commented on May 4, 2026

    @mjamiv
    Contributor

    Opened a narrow regression-test PR for the active-branch case discussed here: #77051

    What it covers:

    • two consecutive Codex app-server mirror calls using different turn-scoped idempotency keys
    • raw JSONL remains a single parent-linked user/assistant/user/assistant chain
    • gateway readSessionMessages still sees both turns after the second mirror, matching the refresh-visible history path

    Validation: pnpm test extensions/codex/src/app-server/transcript-mirror.test.ts --run passed locally in a fresh upstream-main worktree.

    I did not claim this fully reproduces the live WebChat overwrite report; this PR pins the focused branch-preservation regression that ClawSweeper suggested.

  3. bijiashui commented on May 7, 2026

    @bijiashui

    我也是同样问题。

    环境:

    • OpenClaw:v2026.5.6(刚升级到最新)
    • 操作系统:macOS(Mac Mini)
    • 频道:WebChat

    具体表现:

    • 今天上午(北京时间)在北京时间约 11:00 左右在飞书有约 3.5 小时的报销单对话
    • OpenClaw session list 显示飞书会话活跃到 11:52
    • 但 jsonl transcript 文件记录的时间戳只到 11:15(北京时间)
    • WebChat 新会话从 12:01 开始,但 12:00 之前的报销单对话内容完全丢失
    • 两个渠道的会话历史都有同样问题——早期消息消失,只剩最新的几轮

    jsonl 证据:

    • 飞书 session jsonl 文件(0380464c)中,消息从北京时间 08:20 开始,到 11:15 结束
    • session list 显示最后活跃时间是 11:52,中间有约 37 分钟空白
    • 所有消息的 role 字段都是 N/A,说明消息内容没被正确解析

    影响:
    这不是刷新页面丢数据的问题,而是整个会话的历史在存储层就丢失了。报销单讨论的中间结果无法追溯,需要重新做一遍。

    重现步骤:

    1. 保持一个 session 持续对话超过一定长度
    2. 期间发生 context compaction 或其他内部状态变化
    3. 早期消息在 jsonl 中被孤立(orphaned),后续读取时丢失

    这个问题严重影响了会话的可用性,希望能尽快修复。谢谢。

  4. barnacle-openclaw commented on May 30, 2026

    @barnacle-openclaw

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

  5. added
    P1High-priority user-facing bug, regression, or broken workflow.
    impact:data-lossCan lose, corrupt, or silently drop user/session/config data.
    impact:message-lossChannel message delivery can be lost, duplicated, or misrouted.
    impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.
    issue-rating: 🦐 gold shrimpDecent issue quality, but reproduction details are still incomplete.
    clawsweeper:needs-infoClawSweeper needs more reporter information before it can verify this issue.
    clawsweeper:linked-pr-openClawSweeper found an open linked pull request for this issue.
    clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.
    on May 30, 2026
  6. dertbv commented on Jun 5, 2026

    @dertbv
    Author

    Still relevant on v2026.5.28 (openclaw --version → 2026.5.28 (e932160), npm-global, macOS Mac Mini M4 Pro arm64, LaunchAgent 24/7).

    Status check on this issue:

    • @bijiashui's repro from 2026-05-07 confirms the same data-loss pattern on macOS across WebChat + Feishu channels with the cross-channel + long-session pattern.
    • Regression-test PR test(codex): preserve mirrored transcript branch across turns #77051 was closed without merge 2026-05-14 — no in-flight fix that I can find.
    • The clawsweeper:linked-pr-open label is now stale (linked PR is closed).
    • No human maintainer response since 2026-05-04, and the stale-bot warning fired 2026-05-30.

    Spot-check on our v5.28 box (2026-06-05): today's 3-turn WebChat session (10:55→11:09 ET) preserved all user turns in the on-disk JSONL with proper parentId chains — no overwrite fingerprint under simple multi-turn usage. This suggests the bug requires the longer cross-channel + compaction pattern @bijiashui described, not the basic multi-turn case.

    Flagging so this doesn't auto-close — the P1 / impact:session-state / impact:data-loss / impact:message-loss labels still match the reported behavior, and WebChat transcript persistence is load-bearing for any install running Control UI alongside cron-backed channels.

    Happy to capture a fresh on-disk JSONL diff from our v5.28 box if a maintainer wants concrete bytes — let me know what reproducer shape would be most useful (longer session? cross-channel handoff? specific compaction trigger?).

  7. added
    issue-rating: 🐚 platinum hermitGood issue quality with a plausible reproduction path needing some confirmation.
    clawsweeper:needs-live-reproClawSweeper needs live local, crabbox, or manual validation to confirm this issue.
    clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.
    and removed
    clawsweeper:needs-infoClawSweeper needs more reporter information before it can verify this issue.
    issue-rating: 🦐 gold shrimpDecent issue quality, but reproduction details are still incomplete.
    clawsweeper:linked-pr-openClawSweeper found an open linked pull request for this issue.
    on Jun 14, 2026
  8. added
    maturity:stableBroken existing behavior primarily owned by an M4/M5 scorecard surface.
    on Jun 28, 2026
  9. openclaw-barnacle commented on Jul 13, 2026

    @openclaw-barnacle

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

  10. dertbv commented on Jul 14, 2026

    @dertbv
    Author

    No longer reproduces on v2026.7.1-beta.5 (b6387af) — same machine as the original report (macOS arm64, Mac Mini M4 Pro, npm-global, LaunchAgent 24/7), codex app-server runtime.

    Re-ran the original snapshot/diff method against a fresh gateway session (two turns via the gateway API, session JSONL snapshotted between turns):

    • After turn 1: session header + user + assistant (3 records).
    • After turn 2: the first 3 lines are byte-identical to the between-turns snapshot (diff clean) — the file was appended, not rewritten.
    • Parent chain is a single linear branch: user 17045e2e ← assistant 5e48b3eb ← user ed0a69ed ← assistant 3d3b8a0d. The 5.2 failure signature (new message written as a sibling of the old parent, orphaning the previous assistant entry) is absent.

    Caveat: this exercised the gateway session/transcript write path (codex app-server runtime) rather than the WebChat UI specifically, but that mirror path was the root cause identified above, and it now truly appends. Consistent with the transcript persistence having been reworked wholesale in the 7.x line.

    From my side this can close as fixed/superseded on the current beta line. (Original repro was v2026.5.2; last confirmed still-present v2026.5.28.)

  11. steipete commented on Jul 29, 2026

    @steipete
    Contributor

    Thank you for the exceptionally detailed reproduction and, especially, for retesting the original Codex app-server runtime on the same Mac and confirming that the existing transcript remains byte-identical across turns and that the parent chain stays linear: #77012 (comment).

    I independently checked the current implementation against Codex’s actual upstream thread/turn protocol. The underlying destructive file-era transcript persistence was subsequently replaced by the canonical SQLite, parent-linked, transaction-backed session transcript implementation in #113233 (commit 4273ca9). The earlier #77046 fixes the related Codex mirror identity/idempotency subpath; it is a partial contributing fix, not the sole resolution of this report.

    The complete current Codex transcript-mirror regression suite passes 28/28, including reordered snapshots, distinct repeated-message turns, and earlier-turn history re-emitted by later snapshots. In combination with the original reporter’s byte-for-byte, same-machine confirmation, this verifies the originally reported per-turn overwrite and orphaned-parent regression is fixed. Closing as completed; genuinely different cross-channel or compaction failures should remain tracked separately when supported by their own current reproduction.

  12. locked as resolved and limited conversation to collaborators on Oct 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1High-priority user-facing bug, regression, or broken workflow.clawsweeper:needs-live-reproClawSweeper needs live local, crabbox, or manual validation to confirm this issue.clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.impact:data-lossCan lose, corrupt, or silently drop user/session/config data.impact:message-lossChannel message delivery can be lost, duplicated, or misrouted.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.issue-rating: 🐚 platinum hermitGood issue quality with a plausible reproduction path needing some confirmation.maturity:stableBroken existing behavior primarily owned by an M4/M5 scorecard surface.

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions