Skip to content

Conversation

@ammar-agent
Copy link
Collaborator

@ammar-agent ammar-agent commented Oct 24, 2025

Problem

After #228 merged, encountered two issues:

  1. Init-output crash: StreamingMessageAggregator.ts:516 throws Cannot read properties of undefined (reading 'trimEnd') when processing init-output events with missing line field
  2. Inconsistent message appearance: User messages sometimes don't appear immediately in chat view

Solution

1. Init-output defensive check

Added null check for data.line before calling trimEnd():

if (!data.line) return; // Defensive: skip events with missing line data

Follows the defensive pattern from #228 - gracefully handle edge cases during replay.

2. Message processing condition tightened

Added 'role' in data check to the caught-up branch:

} else if (isCaughtUp && "role" in data) {

Makes the condition symmetric with the buffering branch and ensures only valid CmuxMessages are processed.

Testing

  • make typecheck passes
  • ✅ All 763 unit tests pass

Generated with cmux

Fixes two issues found after PR #228:

1. **Init-output undefined line crash**: Added null check for data.line
   before calling trimEnd(). Prevents crash when init-output events
   arrive with missing line data during replay or out-of-order scenarios.

2. **Message processing condition tightened**: Added 'role' field check
   to ensure only CmuxMessages are processed in the caught-up branch.
   This makes the condition symmetric with the buffering branch and
   ensures we don't accidentally process malformed messages.

Both changes follow the defensive programming pattern established in
PR #228 - gracefully handle edge cases during replay rather than crash.

_Generated with `cmux`_
Log errors when:
- init-output arrives without init-start
- init-output has missing line field
- init-end arrives without init-start
- message in WorkspaceStore doesn't match any processing condition

This helps debug edge cases and prevents silent failures.
Add typeof check after line assignment to handle any edge case where
data.line might become undefined after the initial null check.

This provides defense-in-depth against malformed events from any source
(disk corruption, IPC errors, etc.).
@ammario ammario merged commit 110962b into main Oct 24, 2025
13 checks passed
@ammario ammario deleted the fix/init-output-defensive-check branch October 24, 2025 17:43
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.

2 participants