Skip to content

fix(pyodide): align bootstrap dispatcher with protocol envelope#197

Merged
bbopen merged 2 commits intomainfrom
codex/fix-pyodide-bootstrap-protocol
Mar 10, 2026
Merged

fix(pyodide): align bootstrap dispatcher with protocol envelope#197
bbopen merged 2 commits intomainfrom
codex/fix-pyodide-bootstrap-protocol

Conversation

@bbopen
Copy link
Owner

@bbopen bbopen commented Feb 28, 2026

Summary\n- rewrite Pyodide bootstrap dispatcher to consume protocol + method + params\n- return protocol-aligned envelopes with numeric ids and protocol echo\n- update runtime protocol examples/comments still using obsolete type shape\n- add transport-level regressions for legacy shape rejection and unknown-method errors\n\n## Validation\n- npx vitest --run test/transport.test.ts test/runtime_pyodide.test.ts

@coderabbitai
Copy link

coderabbitai bot commented Feb 28, 2026

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

The pull request replaces an old Python dispatch protocol with a new structured protocol-driven system using the 'tywrap/1' identifier. Messages now follow a standardized format with numeric id, protocol, method, and params fields. Support is added for four dispatch methods (call, instantiate, call_method, dispose_instance), and error handling is standardized with proper validation on both Python and TypeScript sides.

Changes

Cohort / File(s) Summary
Protocol Implementation
src/runtime/pyodide-io.ts
Replaces dispatch logic with protocol-driven flow. Adds message validation (numeric id, protocol='tywrap/1', params as dict). Implements four methods: call, instantiate, call_method, dispose_instance. Standardizes response format and error handling with traceback inclusion.
Documentation Updates
src/runtime/transport.ts
Updates example usage in Transport interface docstring to reflect new message shape with numeric id, protocol field, method, and params structure.
Test Coverage
test/transport.test.ts
Adds tests for legacy envelope rejection and unknown-method error handling. Updates existing tests to use numeric message IDs instead of strings. Aligns mock dispatch implementations and test expectations with new protocol format.

Sequence Diagram

sequenceDiagram
    participant Client as TypeScript Client
    participant Dispatcher as Python Dispatcher
    participant Module as Python Module/Class
    participant Store as Instance Store

    Client->>Dispatcher: {id: 1, protocol: 'tywrap/1', method: 'call', params: {...}}
    activate Dispatcher
    Dispatcher->>Dispatcher: Validate message format
    Dispatcher->>Dispatcher: Route by method
    
    alt method = 'call'
        Dispatcher->>Module: Dynamic import & call function
        Module-->>Dispatcher: result
    else method = 'instantiate'
        Dispatcher->>Module: Dynamic import & instantiate class
        Module-->>Dispatcher: instance
        Dispatcher->>Store: Store instance by handle
    else method = 'call_method'
        Dispatcher->>Store: Fetch instance by handle
        Store-->>Dispatcher: instance
        Dispatcher->>Module: Invoke bound method
        Module-->>Dispatcher: result
    else method = 'dispose_instance'
        Dispatcher->>Store: Remove instance by handle
        Store-->>Dispatcher: disposal result
    end
    
    Dispatcher-->>Client: {id: 1, protocol: 'tywrap/1', result: {...}} | {id: 1, protocol: 'tywrap/1', error: {...}}
    deactivate Dispatcher
    Client->>Client: Validate response.id & protocol
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

  • bbopen/tywrap#127: Modifies the same JSONL bridge protocol structure (id/protocol/method/params) and RPC method implementations.
  • bbopen/tywrap#153: Updates the same protocol/message shapes and Pyodide IO/transport code with numeric id and __tywrap_dispatch changes.
  • bbopen/tywrap#195: Implements strict top-level JSON parsing and numeric message IDs for IO response correlation alignment.

Suggested labels

bug, area:runtime-node, priority:p2

Poem

🐰 A protocol refined, so structured and clean,
With messages validated like none you have seen,
From call to dispose, each method takes flight,
The tywrap bridge now handles it right! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: aligning the Pyodide bootstrap dispatcher with the protocol envelope structure.
Description check ✅ Passed The description is directly related to the changeset, covering the rewrite of the dispatcher, protocol-aligned responses, and the addition of regression tests.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch codex/fix-pyodide-bootstrap-protocol

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.

@bbopen
Copy link
Owner Author

bbopen commented Mar 10, 2026

@coderabbitai review

@coderabbitai
Copy link

coderabbitai bot commented Mar 10, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai bot added bug Something isn't working area:runtime-node Area: Node runtime bridge priority:p2 Priority P2 (medium) labels Mar 10, 2026
@bbopen bbopen merged commit 79e6a95 into main Mar 10, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:runtime-node Area: Node runtime bridge bug Something isn't working priority:p2 Priority P2 (medium)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant