Skip to content

fix(sessions): preserve target rows during legacy migration - #117272

Merged
vincentkoc merged 4 commits into
openclaw:mainfrom
wangyan2026:fix/legacy-session-key-normalize-117263
Aug 1, 2026
Merged

vincentkoc merged 4 commits into
openclaw:mainfrom
wangyan2026:fix/legacy-session-key-normalize-117263

Conversation

@wangyan2026

@wangyan2026 wangyan2026 commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #117263

What Problem This Solves

Automatic startup migration could silently delete readable target-session rows whose sessionId equals their canonical agent session key. The normalizer needs the store key to recognize that legacy shape as initializationPending; without it, the row is rejected and omitted from the replacement store.

The original repair exposed a second destructive path: after moving legacy transcripts, migration re-normalized mutable raw rows and replaced the store again. A matching <pendingKey>.jsonl added retired sessionFile metadata to the pending row, made normalization reject it, and deleted it in the second write.

Root Cause

  • Legacy-session and ACP metadata normalization omitted the in-scope store key.
  • Store replacement did not protect rows already present in the readable target store from normalization rejection.
  • The post-move rewrite persisted sessionFile, a file-era field retired by refactor(sessions): remove file-era transcript runtime #113233 and removed from the canonical session-entry shape. That obsolete second replacement write violated the same target-row preservation invariant.

Canonical Repair

  • Pass the session key through every affected normalization path.
  • Track canonical target keys and refuse the migration before replacement if normalization rejects any protected target row.
  • Keep filtering invalid legacy-only rows, which are not authoritative target state.
  • Remove the obsolete post-move sessionFile rewrite entirely. Transcript files still move to the canonical agent directory; the canonical store is written once.
  • Cover initial preservation, fail-closed target rejection, legacy-only filtering, ACP extraction, matching <pendingKey>.jsonl, metadata preservation, and rerun idempotence.

Best-fix judgment: deleting the obsolete second write is better than carrying first-pass entries into it or adding another guard. Canonical entries no longer persist file paths, so preserving the rewrite would keep dead policy and another state-replacement boundary without a supported contract.

User Impact

Startup migration now preserves live pending-session metadata, including display name, category, provider/model overrides, delivery state, and group activation. A matching legacy transcript is moved without mutating or deleting the canonical row. A second startup is byte-stable.

Evidence

Validated head: f4aa51d96b2b5df7c8a6198fb1c0f63741419ac3

Sanitized direct AWS Crabbox: public networking, no Tailscale, no instance role, no hydration, only CI forwarded, trusted bootstrap, exact SHA verification.

  • Static and focused proof
    • pnpm format:check
    • full oxlint: 0 warnings, 0 errors
    • src/infra/state-migrations.test.ts: 79/79
    • src/config/sessions/sessions.test.ts: 21/21
    • src/acp/runtime/session-meta.test.ts: 12/12
    • SQLite sessions/transcripts flip E2E: 1/1
  • Built CLI startup proof
    • built the packaged CLI
    • ran real openclaw status --json startup migration twice against isolated state
    • preserved the key-shaped pending row and all checked metadata
    • moved the literal matching <pendingKey>.jsonl
    • migrated ACP metadata with a null runtime session id
    • proved byte-stable rerun state
    • output: ACP_PROOF_OK, LEGACY_PROOF_OK, RUNTIME_PROOF_OK
  • Exact-head autoreview: clean, no accepted/actionable findings, confidence 0.95.
  • GitHub openclaw/ci-gate: passed on the exact head.

Diff Shape

  • Production: +32/-44, net -12 lines.
  • Tests: +285/-9.
  • No config, protocol, schema-version, or public API change.

AI Assistance

  • AI-assisted: Yes
  • Original model: glm-5.1

@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. P0 Emergency: data loss, security bypass, crash loop, or unusable core runtime. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. labels Aug 1, 2026
@clawsweeper

clawsweeper Bot commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 1, 2026, 5:01 AM ET / 09:01 UTC.

ClawSweeper review

What this changes

Repairs automatic legacy-session migration so it supplies each store key to session normalization, preserves protected target rows on a rejected normalization, and avoids a second stale transcript-path replacement.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep this PR open for normal landing review. The latest head fixes the current-main destructive normalization path, resolves the prior P0 post-move rewrite finding by removing that obsolete second replacement, and adds focused coverage for the matching legacy-transcript case; remaining work is exact-head CI completion and a merge refresh.

Priority: P0
Reviewed head: f4aa51d96b2b5df7c8a6198fb1c0f63741419ac3

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The repaired branch now has direct runtime evidence, a focused destructive-path regression test, and no remaining discrete correctness finding.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The PR body includes a redacted built-runtime migration transcript showing the previously dropped key-shaped row is retained, alongside focused regression coverage; private paths and credentials remain redacted.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The PR body includes a redacted built-runtime migration transcript showing the previously dropped key-shaped row is retained, alongside focused regression coverage; private paths and credentials remain redacted.
Evidence reviewed 5 items Current-main defect: Current main normalizes merged session entries without the map key and then atomically replaces the target store, so key-shaped pending rows can be omitted before the save.
Repair owns the destructive boundary: The PR normalizes entries with their store keys and refuses the migration before replacement when normalization rejects an existing target key, leaving both source stores in place for Doctor repair.
Prior P0 finding covered: The latest regression test uses a protected key-shaped row with a matching legacy transcript, verifies that metadata survives, verifies no obsolete transcript rewrite occurs, and verifies a second run is idempotent.
Findings None None.
Security None None.

How this fits together

Startup state migration reads legacy JSONL/session-store artifacts, merges them into the canonical per-agent session store, and moves legacy transcript artifacts. The resulting session records feed later routing, provider selection, delivery state, and group activation behavior.

flowchart LR
  A[Legacy JSONL and session store] --> B[Startup state migration]
  C[Canonical target session store] --> B
  B --> D[Normalize rows with store keys]
  D --> E{Protected target row valid?}
  E -->|yes| F[Atomically save canonical store]
  E -->|no| G[Defer migration with warning]
  F --> H[Move legacy transcript artifacts]
Loading

Before merge

  • Resolve merge risk (P1) - This migration rewrites persisted session state, so merge should wait for the remaining exact-head checks and a refreshed clean merge against current main before landing.
  • Complete next step (P2) - No discrete mechanical repair remains after the prior P0 fix; the maintainer action is to wait for exact-head CI, refresh mergeability, and land if those gates remain green.
Agent review details

Security

None.

PR surface

Source -12, Tests +276. Total +264 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 2 32 44 -12
Tests 1 285 9 +276
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 317 53 +264

Review metrics

None.

Stored data model

Persistent data-model change detected: serialized state: src/infra/state-migrations.legacy-sessions.ts, serialized state: src/infra/state-migrations.test.ts, unknown-data-model-change: src/infra/state-migrations.legacy-sessions.ts, unknown-data-model-change: src/infra/state-migrations.test.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #117263
Summary: This PR is the active candidate repair for the canonical report of automatic legacy-session migration deleting key-shaped target rows.

Members:

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

Merge-risk options

Maintainer options:

  1. Confirm exact-head migration proof (recommended)
    Wait for the remaining exact-head checks and refresh the clean merge result before landing this persistent-session migration repair.
  2. Pause if the migration contract changes
    Pause this PR rather than broadening it if review uncovers a need to change the canonical session-store shape or migration policy.

Technical review

Best possible solution:

Land the guarded canonical normalization path after exact-head CI is green, preserving the one-save migration flow and retaining the focused regression coverage for key-shaped pending rows.

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

Yes—current main's merged-store loop omits the session key before strict replacement, and the PR body provides a matching built-runtime migration transcript; this review did not execute the reproduction locally.

Is this the best way to solve the issue?

Yes—the latest patch fixes the owner boundary by passing the canonical key into normalization, fails safely for rejected existing target rows, and removes the stale second rewrite instead of adding another compensating path.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR body includes a redacted built-runtime migration transcript showing the previously dropped key-shaped row is retained, alongside focused regression coverage; private paths and credentials remain redacted.
  • remove rating: 🧂 unranked krab: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P0: Current main can silently delete readable live session rows during automatic startup migration, including delivery and activation metadata.
  • merge-risk: 🚨 session-state: The PR changes the atomic rewrite path for persisted per-agent session stores, so an unproven edge case could affect existing session state during upgrade.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR body includes a redacted built-runtime migration transcript showing the previously dropped key-shaped row is retained, alongside focused regression coverage; private paths and credentials remain redacted.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes a redacted built-runtime migration transcript showing the previously dropped key-shaped row is retained, alongside focused regression coverage; private paths and credentials remain redacted.

Evidence

What I checked:

Likely related people:

  • steipete: Authored the merged state-migration split and the later merged session-runtime refactor that established the surrounding migration and normalization boundaries. (role: migration-module and session-runtime refactor author; confidence: high; commits: 8aab4ff94de8, 4273ca9dbd9b; files: src/infra/state-migrations.legacy-sessions.ts, src/infra/state-migrations.session-store.ts)
  • vincentkoc: Authored the current branch's follow-up guard, regression coverage, and removal of the obsolete second replacement that addressed the prior review blocker. (role: recent repair contributor; confidence: high; commits: 7c45021fa236, 8474f6151897, f4aa51d96b2b; files: src/infra/state-migrations.legacy-sessions.ts, src/infra/state-migrations.test.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Let the exact-head CI complete and refresh the merge result against current main before landing.

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 (5 earlier review cycles)
  • reviewed 2026-08-01T07:21:59.487Z sha 375eb4910c0f890b96ffcaee0467c7b1d77ead60 :: needs real behavior proof before merge. :: none
  • reviewed August 1, 2026, 3:48 AM ET / 07:48 UTC sha unknown :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-01T07:59:36.938Z sha 375eb4910c0f890b96ffcaee0467c7b1d77ead60 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-01T08:12:37.249Z sha ed4d2fc9c7554fb24a5d5470b18a268a74eeecd1 :: needs changes before merge. :: [P0] Protect key-shaped rows during the post-move rewrite
  • reviewed 2026-08-01T08:32:30.649Z sha 209ce493b970307972623fa0ee4339db6eb2806d :: needs changes before merge. :: [P0] Preserve protected rows during the post-move rewrite

@wangyan2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@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. and removed 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. labels Aug 1, 2026
@vincentkoc
vincentkoc force-pushed the fix/legacy-session-key-normalize-117263 branch from 375eb49 to 5c63519 Compare August 1, 2026 08:03
@vincentkoc
vincentkoc force-pushed the fix/legacy-session-key-normalize-117263 branch from 5c63519 to ed4d2fc Compare August 1, 2026 08:07
@clawsweeper clawsweeper Bot added 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 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. labels Aug 1, 2026
@vincentkoc
vincentkoc force-pushed the fix/legacy-session-key-normalize-117263 branch 2 times, most recently from 209ce49 to cbefb83 Compare August 1, 2026 08:43
wangyan2026 and others added 3 commits August 1, 2026 16:49
Legacy migration must pass each stored map key into the canonical session-entry normalizer so key-shaped pending rows survive both replacement writes and ACP metadata detection.\n\nFixes openclaw#117263
@vincentkoc
vincentkoc force-pushed the fix/legacy-session-key-normalize-117263 branch from cbefb83 to 7f5b559 Compare August 1, 2026 08:50
@vincentkoc
vincentkoc force-pushed the fix/legacy-session-key-normalize-117263 branch from 7f5b559 to f4aa51d Compare August 1, 2026 08:55
@clawsweeper clawsweeper Bot added 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. and removed 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. labels Aug 1, 2026
@vincentkoc vincentkoc changed the title fix(sessions): pass session key to normalizer in legacy session migration fix(sessions): preserve target rows during legacy migration Aug 1, 2026
@vincentkoc

Copy link
Copy Markdown
Member

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@openclaw-barnacle openclaw-barnacle Bot added triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. and removed triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Aug 1, 2026
@vincentkoc
vincentkoc merged commit 4aaea53 into openclaw:main Aug 1, 2026
140 of 151 checks passed
vincentkoc added a commit to Alix-007/openclaw that referenced this pull request Aug 1, 2026
* origin/main:
  fix(update): keep rolled-back Git installs runnable (openclaw#117294)
  refactor(ui): centralize chat outbox projections (openclaw#117284)
  fix(sessions): preserve target rows during legacy migration (openclaw#117272)
  fix(security): detect multiline skill prompt injection (openclaw#117254)
  fix(qa): lease credentials for Telegram startup proof (openclaw#116842)
  refactor(memory): unify session ingestion (openclaw#117293)
  fix(channels): strip internal tool text in Reef and Zalo Personal (openclaw#112621)
  fix(ui): keep newer Appearance choices after delayed theme imports [AI-assisted] (openclaw#117292)
  fix(inference): simplify lifecycle and preserve Codex tool identity (openclaw#117298)
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 2, 2026
…#117272)

* fix(sessions): pass session key to legacy normalizer

Legacy migration must pass each stored map key into the canonical session-entry normalizer so key-shaped pending rows survive both replacement writes and ACP metadata detection.\n\nFixes openclaw#117263

* fix(sessions): defer rejected target-row migrations

* test(sessions): cover pending legacy migration paths

* fix(sessions): remove obsolete transcript rewrite

---------

Co-authored-by: Vincent Koc <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 2, 2026
* origin/main:
  fix(update): keep rolled-back Git installs runnable (openclaw#117294)
  refactor(ui): centralize chat outbox projections (openclaw#117284)
  fix(sessions): preserve target rows during legacy migration (openclaw#117272)
  fix(security): detect multiline skill prompt injection (openclaw#117254)
  fix(qa): lease credentials for Telegram startup proof (openclaw#116842)
  refactor(memory): unify session ingestion (openclaw#117293)
  fix(channels): strip internal tool text in Reef and Zalo Personal (openclaw#112621)
  fix(ui): keep newer Appearance choices after delayed theme imports [AI-assisted] (openclaw#117292)
  fix(inference): simplify lifecycle and preserve Codex tool identity (openclaw#117298)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P0 Emergency: data loss, security bypass, crash loop, or unusable core runtime. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M 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.

[Bug]: startup legacy session migration silently deletes live session rows

2 participants