Skip to content

fix(ocx-child): bound WebSocket event retention - #820

Closed
luvs01 wants to merge 1 commit into
devfrom
fix/child-ws-frame-event-budget
Closed

luvs01 wants to merge 1 commit into
devfrom
fix/child-ws-frame-event-budget

Conversation

@luvs01

@luvs01 luvs01 commented Nov 16, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Handle each completed WebSocket frame event before parsing the next event from the same socket read. Completed fragmented messages no longer accumulate full-capacity payload buffers in an intermediate event vector.
  • Convert payload reservation failure into a connection-level 1009 fault. Preserve the existing message and fragment limits, masking, UTF-8 validation, close behavior, and wire ordering.
  • Keep link-ws-test-gate absent from ordinary builds. Add bounded parser coverage, a real feature-enabled relay regression, and the owning runtime contract.

This addresses the Daybreak finding. The branch is based on dev at 1d10758fa6ced80cdd780cb000bc5c4b83f84703; its reviewed tree is 01f85f6d7ef39df5e6ab5dc024d04489b10f2653.

Verification

Linux, Rust 1.90.0 and Bun 1.4.4:

  • cargo test --locked --manifest-path native/ocx-child/Cargo.toml --lib: 57 passed, 0 failed.
  • cargo test --locked --manifest-path native/ocx-child/Cargo.toml --features link-ws-test-gate --lib --test link_websocket: 56 library tests and 5 real-binary integration tests passed.
  • Standalone frame-reader regression run: 14 passed, 0 failed.
  • A bounded comparison using a 64 KiB message limit failed under the former batched-consumption model and passed with single-event consumption. Retained completed-message capacity fell from 44,695,552 bytes to a peak of 65,536 bytes in that synthetic case. No allocator-exhaustion or operating-system OOM test was run.
  • bun run typecheck (2,533 files), bun run structure:check, bun run privacy:scan, file-size ratchet, Rust formatting, and staged diff checks passed.
  • Read-only review traced both relay directions, payload ownership transfer through write_frame, control frames, and terminal error handling.

Unresolved validation: the attempted default full Cargo suite stopped after 121 passing tests and 1 failure, owner_link::a_relay_of_another_home_keeps_the_planted_binary_from_being_purged, with OS error 26 (Text file busy). The same isolated test passed on the unchanged base, so this failure is unclassified, not asserted to be a proven baseline failure. The full suite was not rerun to obtain a green result. Windows/macOS and an installed application were not tested.

Hosted follow-up: the existing Linux remote-helper CI job ran the default full ocx-child Cargo suite with Rust 1.100.0: 133 passed, 0 failed, including the locally failing owner-link test. Its merge-preview commit 43cbda04e7af30acb1664aad2730ed695372d144 has the exact reviewed tree 01f85f6d7ef39df5e6ab5dc024d04489b10f2653, equal to this PR head. The local OS-26 result above remains recorded and unclassified; the hosted result independently verifies the same patch content. This hosted job does not enable link-ws-test-gate; the feature-enabled coverage is the separate local run above.

This PR remains Draft for maintainer security review and full platform acceptance. No production feature gate is enabled.

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • Docs or release notes were updated when needed.
  • Security-sensitive changes were reviewed for secrets, auth, and unsafe defaults.

The last item records implementation and independent source review; it does not claim maintainer approval or full platform acceptance.

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of WebSocket messages that arrive together or in fragments, helping keep the relay responsive for other messages and clients.
    • Connections now close with code 1009 if memory cannot be reserved for a message payload.
  • Tests
    • Added coverage for bursts of fragmented messages, subsequent messages, and multiple clients.
  • Documentation
    • Updated the WebSocket documentation to describe sequential event handling and payload reservation behavior.

Upstream handoff

The complete four-file change is preserved in lidge-jun/opencodex#8801 at the same head bf259f16c346accb29f91121e3562b509860b2db. Its exact-head main CI and CodeRabbit review completed successfully, with no unresolved inline review threads at verification. Closing this duplicate fork PR; follow-up continues in lidge-jun#8801. The shared source branch is retained. This is not a merge or platform-acceptance claim.

Consume completed frame events before parsing later messages in the same read.
Handle payload reservation failure as a connection fault and preserve the
existing test-only feature gate, framing limits, and close behavior.
@coderabbitai

coderabbitai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The WebSocket frame reader now returns one completed event at a time. The relay handles each event before parsing more input. Payload reservations use fallible allocation, and new tests cover coalesced messages and reservation failure.

Changes: WebSocket relay event processing

Layer / File(s) Summary
Incremental frame parsing and allocation
native/ocx-child/src/link_ws_frame.rs, structure/remote-link.md
FrameReader::next_event consumes input through one event and leaves later input unread. Payload reservations use fallible allocation and return ProtocolFault::TooLarge on failure. Tests cover coalesced frames, faults, close frames, and reservation failure. The documentation describes the event flow and payload bound.
Sequential relay handling
native/ocx-child/src/link_ws.rs, native/ocx-child/tests/link_websocket.rs
The relay handles each parsed event before requesting another and handles parser faults immediately. The integration test checks coalesced fragmented messages, a subsequent message, and a second client.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant WebSocketPeer
  participant pump
  participant FrameReader
  WebSocketPeer->>pump: input chunk
  pump->>FrameReader: next_event
  FrameReader-->>pump: one event or fault
  pump->>WebSocketPeer: handle event or close
Loading

Suggested reviewers: lidge-jun

Merge Risk: Minimal · up to bf259

This change bounds memory retained while the relay parses coalesced WebSocket messages, and it closes the connection with 1009 if a payload reservation fails. No concrete merge-blocking risk was found in the supplied review context, though cross-platform acceptance remains for maintainers.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "fix(ocx-child): bound WebSocket event retention" names the main change. The PR makes FrameReader consume one completed event at a time, so completed fragmented payloads are released before …
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.
Full details: Title check

Explanation

The title "fix(ocx-child): bound WebSocket event retention" names the main change. The PR makes FrameReader consume one completed event at a time, so completed fragmented payloads are released before the next event is parsed, and payload reservation failure becomes a 1009 close. The title is concise, specific, and follows conventional commit form. It does not mention the fallible reservation or single-event parsing, but it captures the primary intent.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 1d10758 and bf259f1.

Files selected for processing: 4

  • native/ocx-child/src/link_ws.rs
  • native/ocx-child/src/link_ws_frame.rs
  • native/ocx-child/tests/link_websocket.rs
  • structure/remote-link.md

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@github-actions

Copy link
Copy Markdown

✅ Deterministic PR hygiene checks passed.

@github-actions github-actions Bot added the bug Something isn't working label Nov 16, 2026

@devin-ai-integration devin-ai-integration 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.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

@luvs01

luvs01 commented Nov 16, 2026 •

Copy link
Copy Markdown
Owner Author

No description provided.

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

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant