Skip to content

fix #183856: stop writing retired top-level channel to session entry - #184079

Closed
wangjx-xydt wants to merge 3 commits into
openclaw:mainfrom
wangjx-xydt:feat/issue-183856
Closed

wangjx-xydt wants to merge 3 commits into
openclaw:mainfrom
wangjx-xydt:feat/issue-183856

Conversation

@wangjx-xydt

@wangjx-xydt wangjx-xydt commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Problem: When /status is the first message after a chat /new, the fast reply session initializer wrote a retired top-level channel field into the session entry. openclaw doctor then reported Found 1 durable session row(s) with legacy delivery fields and kept reporting it after every doctor --fix.
  • Solution: Stop emitting the retired top-level channel field from the fast session initializer. Channel identity is already owned by the canonical delivery block, so dropping the stray field loses no routing information.
  • What changed:
    • src/auto-reply/reply/get-reply-fast-path.ts: removed the channel variable and its ...(channel ? { channel } : {}) spread in initFastReplySessionState.
    • src/auto-reply/reply/get-reply.fast-path.test.ts: added a regression that seeds a post-/new session owning canonical external delivery, bootstraps a native /status over it, and asserts the resulting sessionEntry has no channel property, keeps the reused delivery block untouched, and is a no-op for Doctor's legacy-delivery normalizer.
  • What did NOT change: The delivery block, chatType, subject, groupChannel and all other canonical session fields are untouched. Doctor's legacy-delivery normalizer and its repair behavior are unchanged. No persisted schema or cache format changes.

Fixes #183856

Real behavior proof

  • Behavior or issue addressed: A native /status right after /new wrote the retired channel key next to the canonical delivery block, making doctor repeatedly ask for repair on healthy sessions. After the fix the fast initializer no longer emits the field, the reused canonical delivery survives, and the resulting entry is a no-op for Doctor's legacy-delivery normalizer (so a persisted row is not flagged).
  • Real environment tested: issue-183856 worktree on top of latest main (e850f7c5), running the real initFastReplySessionState fast bootstrap flow (native /status, Provider=telegram) through the existing fast-reply test harness, and the real Doctor delivery-state repair suite against SQLite session_nodes.entry_json rows.
  • Exact steps or command run after this patch:
    # Regression: native /status fast bootstrap must not persist a retired channel field,
    # must keep the reused canonical delivery, and must be a no-op for Doctor's normalizer
    OPENCLAW_VITEST_MAX_WORKERS=1 NODE_OPTIONS=--max-old-space-size=4096 \
      npx vitest run src/auto-reply/reply/get-reply.fast-path.test.ts -t "retired top-level channel"
    # Full fast-path suite
    npx vitest run src/auto-reply/reply/get-reply.fast-path.test.ts
    # Doctor's delivery-state repair over real SQLite rows (data-model compatibility:
    # a row carrying channel/route/lastAccountId is found, repaired to canonical delivery,
    # and stops being reported)
    npx vitest run src/commands/doctor-session-delivery-state.test.ts
  • Evidence after fix:
    ✓ getReplyFromConfig fast test bootstrap > does not persist a retired top-level channel field on a native /status fast bootstrap
    Test Files  1 passed (1)
         Tests  1 passed | 9 skipped (10)
    
    // get-reply.fast-path.test.ts: 10/10 passed
    // doctor-session-delivery-state.test.ts: 7/7 passed
    
  • Observed result after fix: On the base, the bootstrap's sessionEntry carried channel: "telegram" (assertion failed with Received: "telegram"). After the fix the same bootstrap produces a sessionEntry without a channel property, with the seeded canonical external delivery block intact, and normalizeLegacySessionEntryDelivery returns the entry unchanged (a persisted row is not reported by doctor). The Doctor suite proves the end-to-end data model: a durable row carrying channel/route/deliveryContext/lastAccountId is found by repairCanonicalSessionDeliveryStates, repaired to a canonical delivery block, has every LEGACY_SESSION_DELIVERY_KEYS key stripped, and is no longer reported on the next scan.
  • What was not tested: A live Telegram Gateway with an isolated agent DB and an actual openclaw doctor run against the persisted session_nodes.entry_json was not executed in this environment; the fix is verified at the exact producer (fast session initializer) with the native /status path, and the doctor normalizer that flags the field is covered by its own suite against real SQLite rows. The unrelated get-reply-native-slash-fast-path.test.ts file could not be run locally due to a pre-existing startup hang in this environment (it does not import the changed module); it runs in CI.

Regression Test Plan

  • Coverage level: Unit test
  • Target test file: src/auto-reply/reply/get-reply.fast-path.test.ts
  • Scenario locked in: a native /status fast bootstrap (Provider telegram) over a post-/new session that owns canonical external delivery must (1) not produce a top-level channel property, (2) keep the reused delivery block, and (3) be a no-op for normalizeLegacySessionEntryDelivery — the exact normalizer Doctor applies when deciding whether a durable row needs repair.
  • Why this is the smallest reliable guardrail: It exercises the exact producer (initFastReplySessionState) on the exact reported trigger (native /status after /new with a provider present), asserting the retired key is absent and that the persisted row would not be flagged by Doctor; the doctor-delivery suite independently asserts the normalizer's repair of already-affected rows.

Root Cause

  • Root cause: initFastReplySessionState in src/auto-reply/reply/get-reply-fast-path.ts computed const channel = normalizeOptionalString(ctx.Provider) and spread ...(channel ? { channel } : {}) into the SessionEntry. channel is a retired SessionEntry slot key (RETIRED_SESSION_SLOT_KEYS in src/plugins/session-entry-slot-keys.ts); the core SessionEntry type no longer carries it. The canonical delivery block already owns channel identity, so the field was pure legacy metadata that doctor flags.
  • Missing detection / guardrail: The fast initializer emitted a retired session field that the durable-row normalizer and doctor explicitly classify as legacy, with no consumer reading it back.

@clawsweeper

clawsweeper Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@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. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Oct 26, 2026
@clawsweeper

clawsweeper Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: stale review; fresh review needed.

Summary
The latest durable ClawSweeper review was for head 22068e5f88aa8803b332b5427ef674c841aef658, but the PR head is now 1b63955bc7175bf73560b2e8e073abd2b332e06a. Its old verdict and PR readiness labels are no longer current.

Next step
Comment @clawsweeper re-review when the current head is ready; pushes after the first review are not reviewed automatically.

Review history (2 earlier review cycles)
  • reviewed 2026-10-26T02:09:23.900Z sha 7f73559bbba4dfeda6554d0c4fda23af5b801fde :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-26T10:21:25.708Z sha 22068e5 :: needs real behavior proof before merge. :: none

The fast reply session initializer spread a top-level `channel` field
(retired SessionEntry slot key) into the session entry when a provider
was present. Doctor flags durable rows that carry it as legacy delivery
fields, so a native /status right after /new produced a recurring
maintenance warning. The canonical delivery block already owns channel
identity, so the field is simply no longer emitted.
…trap

The regression now seeds a post-`/new` session owning canonical external
delivery state, bootstraps `/status` over it, and asserts the retired
top-level `channel` key stays absent, the reused delivery block survives,
and the entry is a no-op for Doctor's legacy-delivery normalizer.
@wangjx-xydt

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 26, 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-environment Preliminary submission classification; full source review pending. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Oct 26, 2026
Move the normalizeLegacySessionEntryDelivery import below isPathInside to
match oxfmt's ordering; the previous placement failed the check-lint job.
@clawsweeper clawsweeper Bot removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 28, 2026
@roboclaw-bot

Copy link
Copy Markdown
Collaborator

Thanks @wangjx-xydt for finding and fixing this! Merged the credited replacement in #190213, with a regression that checks the persisted session and canonical delivery readers. Closing this superseded PR; your co-author credit is preserved in the landed commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal backlog priority with limited blast radius. size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: /status as the first message after /new writes a retired top-level channel session field (doctor: legacy delivery fields)

2 participants