Skip to content

fix(chat): ignore malformed stream payloads - #29

Merged
chryzxc merged 3 commits into
mainfrom
fix/issue-23-malformed-stream-events
Aug 6, 2026
Merged

fix(chat): ignore malformed stream payloads#29
chryzxc merged 3 commits into
mainfrom
fix/issue-23-malformed-stream-events

Conversation

@chryzxc

@chryzxc chryzxc commented Aug 6, 2026

Copy link
Copy Markdown
Owner

Summary

  • ignore null or missing stream-event payloads before chat-state processing
  • add a regression test for malformed events

Verification

  • TAP version 13

Subtest: malformed stream events are ignored before state processing

ok 1 - malformed stream events are ignored before state processing

duration_ms: 1.227042
...
1..1

tests 1

suites 0

pass 1

fail 0

cancelled 0

skipped 0

todo 0

duration_ms 63.790167

opencode-vscode-chryzxc@0.3.8 typecheck
tsc --noEmit

opencode-vscode-chryzxc@0.3.8 guard:streaming
node scripts/streaming-contract-check.mjs

Closes #23

Summary by CodeRabbit

  • Bug Fixes

    • Improved chat stream handling by safely ignoring null or invalid event payloads.
    • Prevented malformed streaming events from disrupting message processing.
  • Tests

    • Added regression coverage to verify robust handling of missing or invalid event data.

@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

handleStreamEvent now ignores null or non-object payloads before processing. A regression test verifies the guard exists in the handler source.

Changes

Stream event validation

Layer / File(s) Summary
Payload guard and regression test
webview/shared/src/chat/lib/messageHandler.ts, tests/regression/malformed-stream-event-regression.test.mjs
handleStreamEvent returns early for null or non-object payloads. The regression test checks for this behavior.
Estimated code review effort: 2 (Simple) ~10 minutes
🚥 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 clearly describes the main change: ignoring malformed chat stream payloads.
Linked Issues check ✅ Passed The handler ignores null and non-object stream payloads, preventing the reported error and allowing chat processing to continue [#23].
Out of Scope Changes check ✅ Passed The changes are limited to stream payload validation and its regression test, which directly support the linked issue [#23].
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/issue-23-malformed-stream-events

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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 97f607d030

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

knownReasoningPartIDs?: Set<string>,
pendingRenderableTextPart?: { partID?: string; messageID?: string },
): void {
if (!payload || typeof payload !== "object") return;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Reject malformed events before substituting the envelope

When the host sends { type: "streamEvent", event: null, processing: true }, the stream case sets payload to the outer data object via asRecord(data.event) ?? data, so this guard never returns; moreover, the shared pre-switch logic has already dispatched SET_PROCESSING, which can leave a phantom loading state. Reject a missing/non-record data.event at the message boundary before processing bootstrap, and exercise that path through the handler rather than matching source text.

AGENTS.md reference: AGENTS.md:L9-L14

Useful? React with 👍 / 👎.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

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 `@tests/regression/malformed-stream-event-regression.test.mjs`:
- Around line 11-17: Extend the regression test around handleStreamEvent to
invoke the handler through the existing test seam with null, undefined, and
primitive payloads, then assert state processing is not triggered. Retain the
current source-regex assertion as a supplementary implementation check, but make
the behavioral assertions the primary coverage.
🪄 Autofix

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: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: c8fef596-3c36-4a79-9466-91dbec3a8743

📥 Commits

Reviewing files that changed from the base of the PR and between 1a947d7 and 97f607d.

📒 Files selected for processing (2)
  • tests/regression/malformed-stream-event-regression.test.mjs
  • webview/shared/src/chat/lib/messageHandler.ts

Comment on lines +11 to +17
test("malformed stream events are ignored before state processing", () => {
assert.match(
source,
/function handleStreamEvent\([\s\S]*?\): void \{\s*if \(!payload \|\| typeof payload !== "object"\) return;/s,
"the stream handler must ignore null or missing event payloads",
);
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Exercise handleStreamEvent in the regression test.

This test only matches the guard text in messageHandler.ts. It does not call handleStreamEvent with null, undefined, or a primitive, and it does not verify that state processing is skipped. Add a behavior-level test through the handler test seam. Keep this source assertion only as a supplementary implementation check.

🤖 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 `@tests/regression/malformed-stream-event-regression.test.mjs` around lines 11
- 17, Extend the regression test around handleStreamEvent to invoke the handler
through the existing test seam with null, undefined, and primitive payloads,
then assert state processing is not triggered. Retain the current source-regex
assertion as a supplementary implementation check, but make the behavioral
assertions the primary coverage.

@chryzxc

chryzxc commented Aug 6, 2026

Copy link
Copy Markdown
Owner Author

Follow-up review addressed: malformed stream envelopes are rejected at the webview boundary before state processing, including arrays. The regression now invokes the handler and verifies state remains unchanged; the source-regex-only test was removed. Validation: focused handler regression, guard:prepush, guard:streaming, typecheck, webview build, and extension build.

@chryzxc
chryzxc merged commit b6165de into main Aug 6, 2026
1 check passed
@chryzxc
chryzxc deleted the fix/issue-23-malformed-stream-events branch August 6, 2026 14:26
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.

Bug: Chat message processing fails when a stream event has missing data

1 participant