Skip to content

fix(restart): deduplicate reason line in restart sentinel message#32083

Merged
steipete merged 2 commits intoopenclaw:mainfrom
velamints2:fix/restart-sentinel-dedup-message
Mar 3, 2026
Merged

fix(restart): deduplicate reason line in restart sentinel message#32083
steipete merged 2 commits intoopenclaw:mainfrom
velamints2:fix/restart-sentinel-dedup-message

Conversation

@velamints2
Copy link
Contributor

Summary

  • Problem: When gateway.restart is triggered with a reason but no separate note, formatRestartSentinelMessage() emits the reason text twice: once as the message line and again as Reason: <same text>. This produces noisy restart notifications and can confuse agents that parse system event text.
  • Root cause: gateway-tool.ts sets payload.message = note ?? reason ?? null and payload.stats.reason = reason. When note is undefined (common case), both fields contain the same string. formatRestartSentinelMessage() unconditionally appends Reason: ${reason} without checking for equality with the already-emitted message.
  • Fix: Skip the Reason: line when stats.reason matches the already-emitted message text. One-line change in restart-sentinel.ts.

What changed

  1. src/infra/restart-sentinel.ts — add reason !== message guard to skip duplicate Reason: line
  2. src/infra/restart-sentinel.test.ts — add regression tests for both duplicate (same reason/message) and distinct (different reason/message) scenarios

Before / After

Before (reason = message = "Applying config changes"):

Gateway restart restart ok (gateway.restart)
Applying config changes
Reason: Applying config changes
Run: openclaw doctor --non-interactive

After:

Gateway restart restart ok (gateway.restart)
Applying config changes
Run: openclaw doctor --non-interactive

Distinct reason/message still works:

Gateway restart restart ok (gateway.restart)
Restart requested by /restart
Reason: /restart
Run: openclaw doctor --non-interactive

What did NOT change

  • Sentinel payload structure unchanged
  • Delivery routing unchanged
  • Existing tests still pass

Copilot AI review requested due to automatic review settings March 2, 2026 19:22
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes duplicate Reason: lines in restart sentinel notifications when payload.message and payload.stats.reason are the same string, reducing noise and improving downstream parsing of system event text.

Changes:

  • Update formatRestartSentinelMessage() to only append Reason: when it differs from the emitted message
  • Add regression tests covering both the deduped and non-deduped cases

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/infra/restart-sentinel.ts Adds a reason !== message guard to prevent duplicate reason text in the formatted message output.
src/infra/restart-sentinel.test.ts Adds tests verifying the Reason: line is omitted when redundant and retained when distinct.

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Mar 2, 2026

Greptile Summary

This PR fixes a bug where restart sentinel messages displayed duplicate reason text when no separate note was provided. The fix adds a simple equality check (reason !== message) to skip the redundant "Reason:" line when it would duplicate the message content.

Key changes:

  • Added deduplication guard in formatRestartSentinelMessage() to prevent "Reason: X" when message already contains "X"
  • Added comprehensive regression tests covering both duplicate and distinct reason/message scenarios
  • Preserves backward compatibility - only affects message formatting, not payload structure or delivery

Impact: Cleaner restart notifications and less confusion for agents parsing system event text. The fix correctly handles edge cases (whitespace trimming, empty strings, undefined values) and maintains the existing behavior when reason differs from message.

Confidence Score: 5/5

  • This PR is safe to merge with no risk - it's a minimal, well-tested bug fix
  • Perfect score because this is a textbook example of a good bug fix: single-line change with clear intent, comprehensive test coverage for both the bug and the correct behavior, no breaking changes, and the logic is trivially correct (simple string equality check)
  • No files require special attention

Last reviewed commit: 7f84254

Jah-yee added a commit to Jah-yee/openclaw that referenced this pull request Mar 2, 2026
Issue openclaw#32083: Skip Reason: line when it duplicates the message
- Add reason !== message check to prevent duplicate reason lines

This PR has been tested locally.
velamints2 and others added 2 commits March 3, 2026 00:27
When gateway.restart is triggered with a reason but no separate note,
the payload sets both message and stats.reason to the same text.
formatRestartSentinelMessage() then emits both the message line and a
redundant 'Reason: <same text>' line, doubling the restart reason in
the notification delivered to the agent session.

Skip the 'Reason:' line when stats.reason matches the already-emitted
message text. Add regression tests for both duplicate and distinct
reason scenarios.
@steipete steipete force-pushed the fix/restart-sentinel-dedup-message branch from 7f84254 to 8e8991a Compare March 3, 2026 00:27
@steipete steipete merged commit f6233cf into openclaw:main Mar 3, 2026
19 of 21 checks passed
@steipete
Copy link
Contributor

steipete commented Mar 3, 2026

Landed via temp rebase onto main.

  • Gate: pnpm test -- src/infra/restart-sentinel.test.ts
  • CI note: required check and install-smoke failures on this PR run are unrelated baseline type errors currently on main (discord/media/security typed tests + Promise.withResolvers TS target mismatch).
  • Land commit: 8e8991a
  • Merge commit: f6233cf

Thanks @velamints2!

OWALabuy pushed a commit to kcinzgg/openclaw that referenced this pull request Mar 4, 2026
AytuncYildizli pushed a commit to AytuncYildizli/openclaw that referenced this pull request Mar 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants