Skip to content

fix(gateway): skip heartbeat diagnostics in session preview#66656

Open
Tianworld wants to merge 2 commits intoopenclaw:mainfrom
Tianworld:fix/session-preview-skip-heartbeat
Open

fix(gateway): skip heartbeat diagnostics in session preview#66656
Tianworld wants to merge 2 commits intoopenclaw:mainfrom
Tianworld:fix/session-preview-skip-heartbeat

Conversation

@Tianworld
Copy link
Copy Markdown
Contributor

Summary

Session selectors (notably Control UI / WebChat) can become misleading over time because the backend derives lastMessagePreview from transcript tail lines, and heartbeat diagnostic entries may become the most recent content.

This change skips type: "diagnostic.heartbeat" entries when scanning for the last user/assistant preview.

Fixes #66533.

Test plan

  • pnpm exec vitest run src/gateway/session-utils.fs.test.ts

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: XS labels Apr 14, 2026
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 14, 2026

Greptile Summary

Adds a diagnostic.heartbeat skip in readLastMessagePreviewFromOpenTranscript so that heartbeat tail entries no longer overwrite the session preview shown in Control UI / WebChat selectors. The fix is correct and well-tested.

Confidence Score: 5/5

  • Safe to merge — the change is a one-line guard in a read-only transcript scan with a matching test.
  • Only P2 findings remain: a redundant typeof guard and an optional suggestion to broaden the filter to all diagnostic.* types. Neither affects correctness.
  • No files require special attention.
Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/gateway/session-utils.fs.ts
Line: 382-384

Comment:
**Redundant `typeof` check and narrow filter scope**

The `typeof parsed?.type === "string"` guard is redundant — strict equality against a string literal already handles the type check. More importantly, other diagnostic types (e.g. `diagnostic.ping`, `diagnostic.status`) would still leak into the preview if they appear at the transcript tail. Widening to a prefix match makes this more resilient.

```suggestion
      if (typeof parsed?.type === "string" && parsed.type.startsWith("diagnostic.")) {
```

How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "fix(gateway): ignore heartbeat diagnosti..." | Re-trigger Greptile

Comment thread src/gateway/session-utils.fs.ts Outdated
@prtags
Copy link
Copy Markdown

prtags Bot commented Apr 23, 2026

Related work from PRtags group smiling-wolf-gp52

Title: Open PR duplicate: [Bug]: WebChat session selector shows main session as “heartbeat” after a while, making /new fe…

Number Title
#66544 fix(gateway): exclude heartbeat sender ID from session display name
#66656* fix(gateway): skip heartbeat diagnostics in session preview

* This PR

@clawsweeper
Copy link
Copy Markdown
Contributor

clawsweeper Bot commented Apr 27, 2026

Codex review: needs maintainer review before merge.

What this changes:

The branch filters diagnostic.* transcript entries out of session preview derivation, adds regression tests, and adds a changelog fix entry.

Maintainer follow-up before merge:

This is already a focused implementation PR with tests and changelog; there is no narrow automated repair to queue, so the next action is maintainer review and landing if checks are acceptable.

Security review:

Security review cleared: The diff only changes read-only transcript parsing, colocated tests, and a changelog entry; it does not touch CI, dependencies, scripts, secrets, permissions, package metadata, or downloaded code.

Review details

Best possible solution:

Land this PR or an equivalent focused patch on main so the shared transcript-preview helper ignores the diagnostic namespace before deriving lastMessagePreview, while keeping #66544 separate for the display-name fallback path.

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

Yes. A transcript whose last JSONL row is { "type": "diagnostic.heartbeat", "message": { "role": "assistant", "content": "heartbeat: ok" } } will be selected as the preview on current main because the helper only checks message role; the PR adds a regression test for that shape.

Is this the best way to solve the issue?

Yes. Filtering diagnostic.* inside the shared preview helper is the narrowest maintainable fix because it protects all sessions.list consumers without changing normal user/assistant preview extraction.

Acceptance criteria:

  • pnpm test src/gateway/session-utils.fs.test.ts
  • pnpm check:changed in Testbox before landing

What I checked:

  • Current main accepts assistant-shaped diagnostic rows: readLastMessagePreviewFromOpenTranscript parses tail JSONL rows and reads parsed.message based only on role, without checking parsed.type, so a diagnostic row with an assistant-shaped message can become lastMessagePreview. (src/gateway/session-utils.fs.ts:712, a256745323ab)
  • Session rows propagate the preview: buildGatewaySessionRow reads transcript title fields when includeLastMessage is requested and copies fields.lastMessagePreview into the returned session row. (src/gateway/session-utils.ts:1546, a256745323ab)
  • Preview is displayed by current consumers: The TUI session selector requests includeLastMessage: true and displays session.lastMessagePreview; the MCP bridge also defaults conversation listing to includeLastMessage: true. (src/tui/tui-command-handlers.ts:192, a256745323ab)
  • Diagnostic namespace is real current behavior: Current source defines diagnostic event types such as diagnostic.heartbeat and diagnostic.liveness.warning, so a diagnostic. prefix filter matches the live namespace better than a heartbeat-only special case. (src/infra/diagnostic-events.ts:158, a256745323ab)
  • PR adds the narrow filter: The PR head adds isDiagnosticTranscriptEntry() and continues past entries whose type starts with diagnostic. before extracting a user/assistant preview. (src/gateway/session-utils.fs.ts:415, 48b6bdd43a81)
  • PR adds targeted regression coverage: The PR adds table-driven tests where a real user message is followed by diagnostic rows carrying assistant-shaped content, and expects the real user text to remain the preview. (src/gateway/session-utils.fs.test.ts:235, 48b6bdd43a81)

Likely related people:

  • steipete: Current-main blame for the transcript preview helper and session row propagation points to Peter Steinberger, and local history shows prior transcript-tail preview refactoring in the same area. (role: recent maintainer and transcript-preview owner; confidence: high; commits: 9300d48244ca, dc9808a67454; files: src/gateway/session-utils.fs.ts, src/gateway/session-utils.ts)
  • vincentkoc: PR history shows this handle force-pushed the narrow repair commit, removed the human-review/merge-ready labels afterward, and reported targeted validation, making them a practical follow-up route for this branch even though the original PR author is a contributor. (role: repair branch maintainer and likely follow-up owner; confidence: medium; commits: 48b6bdd43a81; files: src/gateway/session-utils.fs.ts, src/gateway/session-utils.fs.test.ts, CHANGELOG.md)

Remaining risk / open question:

  • No fresh tests were run in this read-only sweep; the PR discussion reports targeted Vitest and changed-gate validation.

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

Tianworld and others added 2 commits April 28, 2026 07:37
Skip diagnostic heartbeat transcript entries when deriving lastMessagePreview so session selectors don't get relabeled to 'heartbeat' over time.

Fixes openclaw#66533

Made-with: Cursor
@vincentkoc vincentkoc force-pushed the fix/session-preview-skip-heartbeat branch from 3b89b89 to 48b6bdd Compare April 28, 2026 07:41
@vincentkoc
Copy link
Copy Markdown
Member

ProjectClownfish pushed a narrow repair to this branch so the original contributor path can stay canonical.

Source PR: #66656
Validation: pnpm -s vitest run src/gateway/session-utils.fs.test.ts; pnpm check:changed
Contributor credit is preserved in the branch history and PR context.

@vincentkoc vincentkoc added clownfish:human-review clawsweeper Tracked by ClawSweeper automation and removed clownfish:human-review labels Apr 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clawsweeper Tracked by ClawSweeper automation gateway Gateway runtime size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: WebChat session selector shows main session as “heartbeat” after a while, making /new feel like sessions disappear

2 participants