Skip to content

Add support for Ballerina Interpreter v0.5.0 - #18

Merged
snelusha merged 4 commits into
mainfrom
chore/v0.5.0
May 31, 2026
Merged

Add support for Ballerina Interpreter v0.5.0#18
snelusha merged 4 commits into
mainfrom
chore/v0.5.0

Conversation

@snelusha

@snelusha snelusha commented May 31, 2026

Copy link
Copy Markdown
Owner

Introduce PAL including proper stdout, stderr handling and HTTP support with fetch API.
Resolves #15

Summary by CodeRabbit

  • New Features

    • Added browser-compatible HTTP client for WASM execution
    • Enhanced diagnostic messages with improved location and source formatting
  • Bug Fixes

    • Fixed Node.js process hanging due to uncleared WASM timers
  • Chores

    • Updated dependencies
    • Improved project loading mechanism

@coderabbitai

coderabbitai Bot commented May 31, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@snelusha, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 41 minutes and 41 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 39d7bed4-f289-4bd6-913d-68f857f39ee5

📥 Commits

Reviewing files that changed from the base of the PR and between 5266da1 and 4fc2805.

📒 Files selected for processing (1)
  • packages/ballerina-wasm/pal_wasm.go
📝 Walkthrough

Walkthrough

This PR refactors the Ballerina WASM runtime to load projects via projects.Load, introduces diagnostic environment awareness for better error reporting, adds a browser-based HTTP client using JavaScript fetch, and improves the Node.js WASM bridge to prevent process hangs from lingering Go timers.

Changes

Ballerina WASM Runtime and Platform Refactoring

Layer / File(s) Summary
Diagnostic Environment and Location Handling
packages/ballerina-wasm/diagnostic_printer.go
printDiagnostics now accepts and passes *diagnostics.DiagnosticEnv to each diagnostic; printDiagnostic replaces nil-location checks with empty-location semantics and uses environment-derived getters for file name and line/column coordinates.
Project Loading and Diagnostics Integration
packages/ballerina-wasm/ballerina-lang-go, packages/ballerina-wasm/main_wasm.go, packages/ballerina-wasm/go.mod
Main entrypoint switches from directory.LoadProject to projects.Load, creates and wires diagnostics.NewDiagnosticEnv() into diagnostic printing; imports updated for runtime and diagnostics tools; subproject updated to new commit; go.mod adds github.com/cockroachdb/apd/v3 indirect dependency.
Browser HTTP Client with Fetch
packages/ballerina-wasm/pal_wasm.go
New fetchHTTPClient implementation using JavaScript fetch API, constructs fetch options with method/headers/redirect/body/timeout, extracts response status/headers/body via JS callbacks, and newPal wires the client into pal.Platform with stdout/stderr writers.
Runtime Initialization with PAL and Type Environment
packages/ballerina-wasm/main_wasm.go
Runtime now created with newPal(stdout, stderr) and project's type environment instead of no-arg constructor; stdout defaults to os.Stdout when not provided; capturePrintlnOutput helper removed.

Node.js WASM Bridge Timeout Management

Layer / File(s) Summary
Go Runtime Lifetime Management and Timeout Cleanup
packages/balrun/src/wasm-bridge.ts, packages/balrun/package.json
WasmBridge stores Go runtime instance during load and clears scheduled timeouts in a finally block after each run via new clearScheduledTimeouts method, preventing internal _scheduledTimeouts from keeping Node alive; unrun added to devDependencies.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

  • snelusha/balrun#16: Establishes the initial WASM bridge implementation that this PR extends with Go runtime cleanup logic.

Poem

🐰 The runtime hops with fetch so swift,
Diagnostics dance with env's gift,
No timers linger, no ghosts remain—
The bridge now breathes, released from chain!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main objective of the pull request: upgrading support to Ballerina Interpreter v0.5.0. It directly corresponds to the source branch (chore/v0.5.0) and the substantial changes across multiple files for this upgrade.
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.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/v0.5.0

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.

@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.

🧹 Nitpick comments (1)
packages/ballerina-wasm/pal_wasm.go (1)

52-72: 💤 Low value

Silent fallback when AbortController is unavailable.

If setupTimeout fails (e.g., AbortController not available in the environment), the error is silently ignored and the request proceeds without timeout protection. Consider logging or returning an error to make this behavior explicit.

🤖 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 `@packages/ballerina-wasm/pal_wasm.go` around lines 52 - 72, The
buildFetchOptions function currently swallows setupTimeout errors (e.g., missing
AbortController) which results in silent no-timeout requests; change
buildFetchOptions to surface that failure by returning (map[string]any, error)
instead of just map[string]any, call setupTimeout and if it errors return the
partially built options with the error (or nil options with the error) so
callers can decide, or alternatively log the error explicitly (using the
client's logger on fetchHTTPClient) before proceeding; update all callers of
buildFetchOptions (e.g., the HTTP request entrypoint that invokes
buildFetchOptions) to handle the new error return and either abort or proceed
with explicit warning so the lack of timeout is not silent.
🤖 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.

Nitpick comments:
In `@packages/ballerina-wasm/pal_wasm.go`:
- Around line 52-72: The buildFetchOptions function currently swallows
setupTimeout errors (e.g., missing AbortController) which results in silent
no-timeout requests; change buildFetchOptions to surface that failure by
returning (map[string]any, error) instead of just map[string]any, call
setupTimeout and if it errors return the partially built options with the error
(or nil options with the error) so callers can decide, or alternatively log the
error explicitly (using the client's logger on fetchHTTPClient) before
proceeding; update all callers of buildFetchOptions (e.g., the HTTP request
entrypoint that invokes buildFetchOptions) to handle the new error return and
either abort or proceed with explicit warning so the lack of timeout is not
silent.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f99a1b66-e267-4945-b3ec-3d20696bd2e2

📥 Commits

Reviewing files that changed from the base of the PR and between 2d9bdc3 and 5266da1.

⛔ Files ignored due to path filters (2)
  • bun.lock is excluded by !**/*.lock
  • packages/ballerina-wasm/go.sum is excluded by !**/*.sum
📒 Files selected for processing (7)
  • packages/ballerina-wasm/ballerina-lang-go
  • packages/ballerina-wasm/diagnostic_printer.go
  • packages/ballerina-wasm/go.mod
  • packages/ballerina-wasm/main_wasm.go
  • packages/ballerina-wasm/pal_wasm.go
  • packages/balrun/package.json
  • packages/balrun/src/wasm-bridge.ts

@snelusha
snelusha merged commit 85042fd into main May 31, 2026
1 check passed
@snelusha
snelusha deleted the chore/v0.5.0 branch May 31, 2026 23:12
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.

Add support for Ballerina Interpreter v0.5.0

1 participant