Skip to content

improvement(mothership): treat error as terminal event in traces#4290

Merged
icecrasher321 merged 1 commit intostagingfrom
improvement/error-term
Apr 24, 2026
Merged

improvement(mothership): treat error as terminal event in traces#4290
icecrasher321 merged 1 commit intostagingfrom
improvement/error-term

Conversation

@icecrasher321
Copy link
Copy Markdown
Collaborator

Summary

Treat errors as terminal events in traces

Type of Change

  • Bug fix

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 24, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Apr 24, 2026 9:42pm

Request Review

@icecrasher321 icecrasher321 changed the title improvement(mothership): treat error as terminal event improvement(mothership): treat error as terminal event in traces Apr 24, 2026
@cursor
Copy link
Copy Markdown

cursor Bot commented Apr 24, 2026

PR Summary

Low Risk
Low risk: a small tracing/observability tweak that only changes how terminal SSE completion is detected (counts error as terminal) and doesn’t affect request/stream control flow.

Overview
Updates stampSseReadLoopSpan to treat SSE error events as terminal alongside complete, so copilot.sse.terminal_event_seen/copilot.sse.terminal_event_missing (and related dashboard signals) no longer flag streams that ended with an error event as “missing terminal”.

Adjusts the inline documentation to reflect the new terminal event definition (complete or error).

Reviewed by Cursor Bugbot for commit 4824ea3. Configure here.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 24, 2026

Greptile Summary

This PR fixes a false-positive in the terminal_event_missing OTel span attribute by recognising SSE error events as terminal events alongside complete events. Previously, a stream that ended with an error event would still set terminalEventMissing = true (because only complete counted), even though handleErrorEvent correctly sets context.streamComplete = true and increments counters.eventsByType.error.

Confidence Score: 5/5

This PR is safe to merge — the one-line change is logically correct and matches the existing handler contract.

The fix is minimal and provably correct: handleErrorEvent already sets context.streamComplete = true and counters.eventsByType.error is already tracked in the counters initialiser, so extending the terminalEventSeen guard to include error events eliminates a guaranteed false-positive in the dashboard alert without any side effects on span status or close-reason logic. No P0/P1 issues found.

No files require special attention.

Important Files Changed

Filename Overview
apps/sim/lib/copilot/request/go/stream.ts Single-line fix: adds `

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[SSE Read Loop ends] --> B{context.streamComplete?}
    B -- No --> C[Log error: no terminal event\nendedOn = ClosedNoTerminal\nthrow CopilotBackendError]
    B -- Yes --> D[stampSseReadLoopSpan called]
    D --> E{counters.eventsByType.complete > 0\nOR counters.eventsByType.error > 0}
    E -- Yes --> F[terminalEventSeen = true]
    E -- No --> G[terminalEventSeen = false]
    F --> H{opts.expectedTerminal?}
    G --> H
    H -- Yes + terminalEventSeen=false --> I[terminalEventMissing = true\nSpan status → ERROR]
    H -- No or terminalEventSeen=true --> J[terminalEventMissing = false\nSpan status → UNSET]
    style I fill:#f88,stroke:#d00
    style J fill:#8f8,stroke:#080
Loading

Reviews (1): Last reviewed commit: "improvement(mothership): treat error as ..." | Re-trigger Greptile

@icecrasher321 icecrasher321 merged commit af4be77 into staging Apr 24, 2026
14 checks passed
@waleedlatif1 waleedlatif1 deleted the improvement/error-term branch April 24, 2026 23:14
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