Skip to content

fix(chat): make task-notification parsing tolerant of field order and whitespace#862

Open
bourgois wants to merge 1 commit into
siteboon:mainfrom
bourgois:fix/task-notification-regex
Open

fix(chat): make task-notification parsing tolerant of field order and whitespace#862
bourgois wants to merge 1 commit into
siteboon:mainfrom
bourgois:fix/task-notification-regex

Conversation

@bourgois

@bourgois bourgois commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Small, self-contained fix extracted from #855 at the maintainer's request.

Issue

normalizedToChatMessages parses background <task-notification> messages with a regex that:

  • requires the exact field sequence task-idoutput-filestatussummary,
  • allows no leading/trailing content around the tag, and
  • runs with the /g flag against the raw (untrimmed) string.

When a notification's fields arrive in a different order, omit an optional field, or carry surrounding whitespace, the match fails and the message renders as raw XML in the chat instead of a formatted notification.

Reproduction

  1. Trigger a background task notification whose payload has any leading/trailing whitespace, or whose inner fields are not in the exact task-id, output-file, status, summary order.
  2. Observed: the chat shows the literal <task-notification>…</task-notification> markup.
  3. With this change: it renders as the formatted notification (status + summary).

Fix

Anchor the match to the trimmed content and use non-greedy [\s\S]*? between the status and summary captures, so field order and incidental whitespace no longer break parsing.

npm run typecheck and eslint pass. One-line change in useChatMessages.ts.

Summary by CodeRabbit

  • Bug Fixes
    • Improved task notification parsing so background task updates display more consistently: notifications now reliably extract and show the task status and summary, tolerate leading/trailing whitespace, and ignore extraneous formatting. Users should see clearer, more predictable status updates for background tasks.

@coderabbitai

coderabbitai Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The task-notification parsing logic in useChatMessages is updated to use a simplified regex pattern. The new pattern matches a reduced <task-notification>...</task-notification> XML structure capturing only status and summary fields, and execution is applied to content.trim() instead of the previous global-flag pattern.

Changes

Chat message task-notification parsing

Layer / File(s) Summary
Simplified task-notification parsing regex
src/components/chat/hooks/useChatMessages.ts
Task-notification regex for user text messages is updated to match a simplified start/end-anchored XML structure that captures only status and summary, and the match is executed against content.trim().

Suggested reviewers

  • blackmammoth
  • viper151

Poem

I nibble at tags in the midnight light,
Trim the edges, make matches tight,
Status and summary now hop in line,
No extra tags, the pattern's fine,
A rabbit's regex dance — concise and bright! 🐰✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: improving task-notification parsing to handle field order and whitespace variations.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

… whitespace

The task-notification regex required an exact field sequence
(task-id, output-file, status, summary) with no leading/trailing
content, and ran with the /g flag against the raw string. Notifications
whose fields arrive in a different order, omit optional fields, or carry
surrounding whitespace failed to match and rendered as raw XML in the
chat instead of a formatted notification.

Anchor the match to the trimmed content and use non-greedy [\s\S]*?
between the status and summary captures so field order and incidental
whitespace no longer break parsing.
@bourgois bourgois force-pushed the fix/task-notification-regex branch from cf4c1f6 to c98abb4 Compare June 11, 2026 18:45

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/components/chat/hooks/useChatMessages.ts`:
- Around line 58-59: The current single regex (taskNotifRegex) requires <status>
before <summary> and is order-dependent; change the logic to first extract the
whole <task-notification> block (e.g. via a regex matching
<task-notification>[\s\S]*?<\/task-notification>) then separately extract fields
from that inner content with two independent regexes for <status> and <summary>
so either order is accepted; update the code that uses
taskNotifRegex/taskNotifMatch in useChatMessages.ts to use the two-step
extraction and handle missing fields gracefully.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 03137d6a-112e-4806-8178-74e2161bc7fb

📥 Commits

Reviewing files that changed from the base of the PR and between cf4c1f6 and c98abb4.

📒 Files selected for processing (1)
  • src/components/chat/hooks/useChatMessages.ts

Comment on lines +58 to +59
const taskNotifRegex = /^<task-notification>[\s\S]*?<status>([^<]*)<\/status>[\s\S]*?<summary>([^<]*)<\/summary>[\s\S]*?<\/task-notification>$/;
const taskNotifMatch = taskNotifRegex.exec(content.trim());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Regex is still order-dependent for status vs summary

This pattern still requires <status> to appear before <summary>, so notifications with reversed order won’t parse and will fall back to raw XML rendering. That contradicts the PR’s field-order tolerance goal.

Suggested fix
-const taskNotifRegex = /^<task-notification>[\s\S]*?<status>([^<]*)<\/status>[\s\S]*?<summary>([^<]*)<\/summary>[\s\S]*?<\/task-notification>$/;
-const taskNotifMatch = taskNotifRegex.exec(content.trim());
+const trimmed = content.trim();
+const isTaskNotif = /^<task-notification>[\s\S]*<\/task-notification>$/.test(trimmed);
+const statusMatch = /<status>([^<]*)<\/status>/.exec(trimmed);
+const summaryMatch = /<summary>([^<]*)<\/summary>/.exec(trimmed);
+const taskNotifMatch = isTaskNotif && statusMatch && summaryMatch
+  ? [trimmed, statusMatch[1], summaryMatch[1]]
+  : null;
🧰 Tools
🪛 OpenGrep (1.22.0)

[ERROR] 59-59: Dynamic command passed to child_process.exec/execSync. Use child_process.execFile or spawn with an argument array instead.

(coderabbit.command-injection.exec-js)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/components/chat/hooks/useChatMessages.ts` around lines 58 - 59, The
current single regex (taskNotifRegex) requires <status> before <summary> and is
order-dependent; change the logic to first extract the whole <task-notification>
block (e.g. via a regex matching
<task-notification>[\s\S]*?<\/task-notification>) then separately extract fields
from that inner content with two independent regexes for <status> and <summary>
so either order is accepted; update the code that uses
taskNotifRegex/taskNotifMatch in useChatMessages.ts to use the two-step
extraction and handle missing fields gracefully.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant