Skip to content

fix: recover overlapping global chats through Doctor - #188577

Closed
shakkernerd wants to merge 10 commits into
mainfrom
global-chat-identity-continuation
Closed

shakkernerd wants to merge 10 commits into
mainfrom
global-chat-identity-continuation

Conversation

@shakkernerd

@shakkernerd shakkernerd commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Related: #188165

What Problem This Solves

Older stored state can contain both global and agent:<agentId>:global for one agent, with different session IDs and saved conversations. The normal qualified session reader cannot choose between those overlapping bindings, so continuing either conversation can fail even though its history and files still exist. Doctor previously left this pair in place.

This change repairs the stored binding once through Doctor. The original ongoing chat keeps global; the accidentally created second chat receives a distinct ordinary address derived from its existing session ID.

User Impact

With the Gateway stopped, run openclaw doctor --fix, restart, and reopen the recovered conversation from Sessions. Both conversations retain their original session IDs, stored titles, history windows, ownership, membership and workspace locations. Files stay where they were. After the repair, both addresses use normal session handling.

The old literal review URL requires explicit reopening. A retained view or a fresh visit resolves to the existing missing-session view, which offers navigation choices without silently moving work into the ongoing chat. Ordinary global aliases retain their meaning.

Attributable completed cron history follows the recovered conversation. Its stored run identity, timing and outcome remain unchanged, and scheduled-job definitions and enabled states are untouched. Doctor refuses an occupied destination, pending input, linked work or uncertain historical identity rather than overwriting or guessing. The moved review chat must have no repository workspace or persisted worker placement; those bindings remain untouched and their recovery is outside this operation. A binding owned only by the unchanged ongoing chat does not prevent repair.

Why This Change Was Made

The defect is an overlapping persisted binding. Doctor first completes ordinary key normalization. Its existing maintenance lock and session lifecycle writer own offline repair, history-window movement and preservation of session artifacts. They can give the second conversation an ordinary address while retaining its original identity and saved work.

The agent database move and the shared historical-reference update use their existing transaction owners. If execution stops between them, the retained run's session ID identifies the existing destination on the next Doctor run. Recovery checks for outstanding references before inspecting a destination, so a completed repair leaves subsequently active conversations alone. It selects the owner of the recorded history windows rather than scanning older recovered chats.

The UI change is limited to verifying the old explicit literal address, revalidating it after reconnect and keeping a retired view in place until the user chooses where to go. The canonical session and update documentation explains the repair and reopening step.

Evidence

The original Doctor regression failed on the base because the literal overlapping row remained after repair. The focused tests exercise the real Doctor entry, existing session writers and historical-run producer, including preserved history and ownership, refusal conditions, repeat execution and interruption between the two database commits. Two additional retry failures were reproduced before correcting selection: a completed repair rejected a conversation with restart work, and an interrupted repair inspected an older recovered conversation instead of the recorded session's destination.

The candidate in 3cc0cff passed formatting, focused lint and i18n checks, file-size/assertion/test-line guards, the SQLite worker and membership-writer guard, and seven selected type-check groups. Its Doctor-consumer run passed 357 cases in 32 files. Passing evidence for 743 cases in 30 other related files remains applicable on unchanged inputs, including the reconnect tests. These 62 related files cover initial preservation, retry and interruption, refusal conditions, healthy aliases, legacy normalization and explicit old-view handling.

A participant preservation case reproduced a doubled contribution count before correction. The lifecycle owner now transfers artifacts once, preserving counts and timestamps through repair and repeat execution. Repository-bound review inputs refuse before rehome while their Files access, identities, history, permissions and binding remain unchanged. Persisted worker placements receive the same protection. Separate controls verify that bindings owned only by the ongoing chat do not prevent recovery.

The original affected pair was repaired through the normal offline update/Doctor owner on this head. Independent native readback preserved both original session IDs, all 77 retained messages, ownership, membership, permissions, workspace roots and all three saved files. The disabled schedule stayed unchanged; the historical failed run retained its other facts while following the recovered conversation. Repeating Doctor made no further change.

Both original chats then completed one new natural UI turn at their own addresses. The ongoing chat used its saved work to recommend three pickups at capacity 18; the review retained its separate saved plan and kept seven parcels held pending inspection. Native send/acknowledgement/final receipts and rendered answers agree on each original identity. Independent post-turn readback preserved the existing history prefixes, files, authority and workspace roots. The retained and freshly opened old review URLs both stayed at the old address and required explicit reopening, with no sends.

A fresh healthy global conversation created by published OpenClaw 2026.10.9 was upgraded through OCM to the release-shaped package built from this head. Full-integrity Doctor completed, and the original address, session ID, six-message history prefix, owner fields, workspace and saved note were preserved. Existing Doctor behavior supplied a previously missing display title from the first message. One new ordinary agent turn then used the saved plan, retaining twelve eligible samples and three held for inspection. Independent readback preserved the original history prefix and note; no background service was introduced.

A confirmed blocker remains for an overlapping review conversation with managed attachments: after rehome, normal media cleanup can remove its old-key attachment record and original payload file. The unchanged ongoing-chat attachment control passes. This PR is not ready to land while that recovery contract is unresolved.

The current hosted ratchets pass. The published head's remaining Visitor Access and native plugin-spawn CI failures also reproduce on the relevant baseline; their attribution is recorded separately. Focused integration with the selected target, including its landed Visitor fixture repair, and final readiness checks remain pending. This PR remains open and unmerged.

Visual evidence

Open preview

View Before After
Old review address: baseline to repaired runtime Original review at its old address before repair Old address remains selected and requires explicit reopening after repair
Original ongoing chat: continuation on 3cc0cff New ordinary prompt prepared in the original ongoing chat Original ongoing chat uses its saved work to recommend pickups with capacity 18
Recovered review: continuation on 3cc0cff New ordinary prompt prepared in the recovered original review Recovered review keeps held parcels pending actual inspection

Original repair and continuation; reconnect wait labeled 8x

recovery-and-continuation.mp4

Visual verification

  • Baseline: 199d296 (old address); continuation pre-send states use the fixed head
  • Exact head: 3cc0cff304505ccdc524ea1487314740480d95cb
  • Scenario: Repair the original stored pair once, retire the old review address, and continue both original conversations through ordinary UI handling. The old-address comparison is 199d296 to 3cc0cff; continuation panels show before and after new turns on 3cc0cff.
  • Runtime/build: OpenClaw 2026.10.9-3cc0cff30450-2026-10-31T10-16-29.514Z
  • Retained and fresh old address: Both stay at the old address and show the missing-session view; zero sends
  • Original conversations: Two original session IDs; 77 existing messages preserved; two new prompts finish in their own chats
  • Saved work and references: Three named files unchanged; disabled schedule unchanged; failed-run facts retained at the recovered address
  • Repeat repair: No further history, ownership, authority, membership, workspace or file change
  • Exact fixed head and Gateway build observed in the real UI.
  • Independent native readback checks original history prefixes, files, ownership, authority, memberships and workspace roots.
  • Only the held-view update/reconnect wait is accelerated 8x; new-turn interactions remain at normal speed.
  • The review recording retains its brief scroll through the same saved history.
  • Source recordings received every-frame thumbnail inspection and full-resolution still/critical-frame inspection; no normal-speed playback claim.
  • The final 1,147-frame recording and decisive full-resolution frames were inspected; captioned waits and joins are measured, and the original recordings are retained.

@clawsweeper

clawsweeper Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review blocked

Automated review did not run, so no review verdict was produced.

Reason: The input-safety check rejected material in this revision. No detected value, path, or scanner output is reproduced here.

Automatic review is on hold, including after source changes. Request a fresh re-review after resolving the failure; maintainers can also release the hold through an intentional scanner-policy update.

Next step: If this is a genuine credential, remove and rotate it. If it is an intentional test fixture, a maintainer must review and qualify it.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation app: web-ui App: web-ui gateway Gateway runtime commands Command implementations agents Agent runtime and tooling plugin: file-transfer extensions: browser size: XL labels Oct 30, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 30, 2026
@shakkernerd
shakkernerd force-pushed the global-chat-identity-continuation branch from 0441bd0 to dc16bfd Compare October 30, 2026 23:59
@shakkernerd shakkernerd changed the title fix: resume existing chats with overlapping global keys fix: recover overlapping global chats through Doctor Oct 31, 2026
@shakkernerd

Copy link
Copy Markdown
Contributor Author

@clawsweeper review

@clawsweeper

clawsweeper Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot removed the clawsweeper:intake:bug Preliminary submission classification; full source review pending. label Oct 31, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 31, 2026
@clawsweeper

clawsweeper Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge.

What this changes

This PR recovers overlapping global conversations through offline Doctor repair and prevents retired literal URLs from opening another chat.

Example: An agent has separate saved conversations at global and agent:main:global.

  • Before: The overlapping bindings prevent reliable continuation of the two conversations.
  • After: Doctor keeps global and gives the second conversation a distinct global-review address while retaining its session ID.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The supplied live continuation evidence is useful, but the attachment data-loss path blocks merging.
Proof confidence 🐚 platinum hermit (4/6) ✨ media proof bonus Sufficient (screenshot): Inspected screenshots exercise the real Control UI: the retired address shows Session not found and both original chats complete separate turns; the body records native preservation readback and a latest-stable upgrade, while video inspection was limited by reviewer infrastructure.
Patch quality 🧂 unranked krab (1/6) 1 actionable review finding remain.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Users cannot reliably continue two saved conversations whose global bindings overlap.
Reason: The maintainer-authored direction restores existing conversations through Doctor, preserves normal runtime ownership, and explicitly bounds unsupported recovery cases.

Merge readiness

⛔ Blocked before merge - 2 items remain

Keep this PR open: recovery remains necessary, and the previous participant-count finding is fixed, but the repair can orphan managed attachments and cause their files to be deleted.

Priority: P2
Reviewed head: 3cc0cff304505ccdc524ea1487314740480d95cb

Before merge

  • [P1] Protect managed attachments before removing the source binding (P1) - If agent:main:global contains a generated image, audio file, or document backed by managed_outgoing_image_records, this removal leaves that record and its transcript URL bound to the old key. Neither the lifecycle transfer nor the cron-only shared-state update rehomes those records. Serving then cannot find the owning transcript, and cleanupManagedOutgoingMediaRecords resolves the same removed key, gets a missing transcript result, and calls deleteManagedImageRecordArtifacts to delete the original file. Refuse this input before mutation unless the existing media owner can preserve both access and cleanup ownership, and add a regression covering repair followed by media cleanup. This concern was already visible in the previously reviewed 1d4a2bf; discovering it in this cycle is a late review finding.
  • Add data-model compatibility proof - The review found that existing stored data may not work after upgrade. Show that existing data still loads and works with this change.

Findings

  • [P1] [P1] Protect managed attachments before removing the source binding — src/commands/doctor-session-global-key-repair.ts:300-306

Tests

  • Missing end-to-end proof: The supplied repair and continuation scenarios do not exercise a recovered conversation with managed attachments through subsequent media cleanup.
Agent review details

How this fits together

Doctor repairs persisted session bindings under exclusive offline custody, using the session lifecycle writer and cron history owner; the Control UI then resolves the recovered and retired addresses.

flowchart TD
A[Overlapping session bindings] --> B[Offline Doctor maintenance]
B --> C[Session lifecycle writer]
B --> D[Cron history owner]
C --> E[Recovered conversation]
E --> F[Control UI routing]
C --> G[Managed media ownership]
Loading

Technical review

Best possible solution:

Keep the existing repair owners, but refuse conversations with managed attachment records before removing their old binding until attachment preservation is supported.

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

The linked report establishes the original native failure, and source inspection shows both the remaining recovery gap on main and the introduced attachment-cleanup failure; no target code was run during this review.

Is this the best way to solve the issue?

Offline repair through the existing lifecycle and history owners is appropriate, and repair plus retired-URL handling forms one coherent change, but its preflight must protect managed attachments before the old node is removed.

Full review comments:

  • [P1] [P1] Protect managed attachments before removing the source binding — src/commands/doctor-session-global-key-repair.ts:300-306
    If agent:main:global contains a generated image, audio file, or document backed by managed_outgoing_image_records, this removal leaves that record and its transcript URL bound to the old key. Neither the lifecycle transfer nor the cron-only shared-state update rehomes those records. Serving then cannot find the owning transcript, and cleanupManagedOutgoingMediaRecords resolves the same removed key, gets a missing transcript result, and calls deleteManagedImageRecordArtifacts to delete the original file. Refuse this input before mutation unless the existing media owner can preserve both access and cleanup ownership, and add a regression covering repair followed by media cleanup. This concern was already visible in the previously reviewed 1d4a2bf; discovering it in this cycle is a late review finding.
    Confidence: 0.97
    Late finding: first raised on code an earlier review cycle already covered.

Overall correctness: patch is incorrect
Overall confidence: 0.95

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 1b777ab47da0.

Provenance checked

  • Doctor canonical repair keeps the original intent (cd8a964: Established Doctor as the durable repair owner while keeping runtime duplicate protection strict.)
  • Literal URL resolution and reconnect keeps the original intent (167c310: Missing established sessions must show a missing-session view after authoritative confirmation rather than becoming usable empty conversations.)
  • Early Gateway startup changes intended behavior with a stated reason (4420648: Overlap connection and history startup while retaining confirmation-required paths with their existing owners.)
  • Cron historical references keeps the original intent (6652f7e: Retain cron history under its existing owner after retiring the Tasks runtime.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

Acceptance criteria:

  • pnpm test src/commands/doctor-session-canonical-keys.global.test.ts --maxWorkers=1
  • pnpm test src/gateway/managed-image-attachments.branch-retention.test.ts --maxWorkers=1
  • Show the new attachment-preservation regression failing on the reviewed head and passing with the repair.
  • git diff --check

What I checked:

  • Recovery remains distinct from prevention: fix: keep scheduled global work in its existing conversation #188173 fixes the producer and explicitly excludes recovery of existing two-row state; fetched main still ends canonical repair without the new overlap-repair operation. (src/commands/doctor-session-canonical-keys.ts, 1b777ab47da0)
  • Managed-media ownership is left behind: The repair removes the source session node and moves its windows, while its shared-state update handles only cron references; managed_outgoing_image_records retain the removed session key. (src/commands/doctor-session-global-key-repair.ts:300, 3cc0cff30450)
  • Orphaned attachments reach destructive cleanup: Managed-media cleanup resolves the transcript using record.sessionKey, classifies an absent owner as missing, and calls deleteManagedImageRecordArtifacts, which removes the original file. (src/gateway/managed-image-attachments.ts:354, 3cc0cff30450)
  • Previous finding addressed; new finding is late: The latest commit removes the duplicate artifact copy and asserts preserved participant counts after repair and repetition; the source-removal path responsible for the attachment concern was already present at the previously reviewed head. (src/commands/doctor-session-canonical-keys.global.test.ts:91, 3cc0cff30450)
  • Inspected user-visible proof: The downloaded before/after images show the retired address becoming Session not found; additional GitHub attachment images show separate completed turns using capacity 18 and retaining the seven-parcel inspection hold. The PR also records native preservation readback and a v2026.10.9 upgrade. (3cc0cff30450)
  • Reviewer infrastructure limits: The prepared manifest contains four images and no video artifact. Further scratch downloads failed with curl error 23, ffmpeg/ffprobe were unavailable, and fallback video access returned Cache miss. The linked gist returned an integration 403 and its raw host was blocked; some out-of-scope historical blobs were also unavailable. These limits are not contributor defects. (3cc0cff30450)

Likely related people:

  • Peter Steinberger: Raw commit cd8a964 adds src/commands/doctor-session-canonical-keys.ts:534 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: cd8a96491e26; files: src/commands/doctor-session-canonical-keys.ts)

PR surface

Source +487, Tests +532, Docs +46, Other +2. Total +1067 across 19 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 7 492 5 +487
Tests 8 543 11 +532
Docs 3 46 0 +46
Config 0 0 0 0
Generated 0 0 0 0
Other 1 2 0 +2
Total 19 1083 16 +1067

Review metrics

Metric Value Why it matters
Production versus regression changes Production +492/-5; tests and test support +542/-11 Growth implements one offline repair and its retired-address handling; the regression additions cover preservation, refusal, interruption, and reconnect boundaries.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: Recovery addresses a confirmed but limited existing-state failure in an advanced global-session workflow.
  • merge-risk: 🚨 session-state: Removing the source binding can make retained managed attachments unreachable and eligible for deletion.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🐚 platinum hermit and patch quality is 🧂 unranked krab.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.
  • proof: sufficient: Contributor real behavior proof is sufficient.
  • proof: 📸 screenshot: Contributor real behavior proof includes screenshot evidence.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (1 earlier review cycle)
  • reviewed 2026-10-31T09:36:47.925Z sha 1d4a2bf :: blocked before merge. :: [P2] [P2] Let lifecycle removal copy session artifacts only once

Reviewed October 31, 2026, 8:11 AM ET / 12:11 UTC (Revision 2).

@openclaw-barnacle openclaw-barnacle Bot removed gateway Gateway runtime agents Agent runtime and tooling plugin: file-transfer extensions: browser labels Oct 31, 2026
@shakkernerd

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. proof: sufficient ClawSweeper judged the real behavior proof convincing. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 31, 2026
@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale after 7 days without qualifying human activity.
Without new human activity, Barnacle may close it as not planned 7 days after this message was posted. This is administrative inactivity cleanup, not a claim that the problem is fixed.
A human update restarts the inactivity clock; a new PR head also restarts it. A maintainer can add no-stale for a durable hold, or bad-barnacle to suppress Barnacle. Remove the hold when work can resume.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label Nov 15, 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

app: web-ui App: web-ui commands Command implementations docs Improvements or additions to documentation merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: XL stale Marked as stale due to inactivity status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant