Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 10, 2025

Changes to stream worker output immediately

  • Understand current output accumulation pattern in all three workers
  • Update WorkerAPI interface to accept output callback parameter
  • Modify jsEval.worker.ts to send output immediately via callback
  • Modify ruby.worker.ts to send output immediately via callback
  • Modify pyodide.worker.ts to send output immediately via callback
  • Update runtime.tsx to handle streaming output with callbacks
  • Test the changes to ensure output is still displayed correctly
  • Run linting and build to verify no breakage
  • Address PR feedback:
    • Use optional chaining syntax in jsEval.worker.ts
    • Ruby worker now flushes complete lines immediately in stdout/stderr write
    • Move flushOutput() calls to finally blocks

Summary

All three worker files (jsEval.worker.ts, ruby.worker.ts, pyodide.worker.ts) have been successfully refactored to stream output immediately to the calling code via callbacks instead of accumulating output in arrays. This enables real-time output streaming and reduces memory usage.

Key Changes:

  1. WorkerAPI Interface: Added onOutput callback parameter to runCode and runFile methods
  2. Worker Files: Replaced output arrays with callback-based streaming using currentOutputCallback
  3. Runtime Provider: Updated to use Comlink's proxy() to wrap callbacks and collect streamed output
  4. Build Status: ✅ Build successful with no new errors or warnings

Improvements from PR feedback:

  • jsEval.worker.ts: Simplified callback checks using optional chaining (?.())
  • ruby.worker.ts: Lines with newlines are now flushed immediately in write() methods for real-time output
  • ruby.worker.ts: flushOutput() moved to finally blocks to ensure proper cleanup
Original prompt

This section details on the original issue you should resolve

<issue_title>jsEval.worker.ts, ruby.worker.ts, pyodide.worker.ts でoutputを配列にためるのではなく即座に呼び出し元に返す</issue_title>
<issue_description></issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

…f accumulating in arrays

Co-authored-by: na-trium-144 <100704180+na-trium-144@users.noreply.github.com>
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Dec 10, 2025

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
my-code ace27ff Commit Preview URL

Branch Preview URL
Dec 16 2025, 04:26 PM

Copilot AI changed the title [WIP] Fix immediate output return in jsEval, ruby, and pyodide workers Stream worker output immediately via callbacks instead of buffering in arrays Dec 10, 2025
Copilot AI requested a review from na-trium-144 December 10, 2025 03:22
@na-trium-144 na-trium-144 marked this pull request as ready for review December 13, 2025 17:23
@na-trium-144
Copy link
Contributor

コールバックが良いのかReadableStreamが良いのか悩みどころ
一旦マージするのはあり

Comment on lines 20 to 22
if (currentOutputCallback) {
currentOutputCallback({ type: "stdout", message: format(...args) });
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot currentOutputCallback?.(...) のほうが短いと思います。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to use optional chaining currentOutputCallback?.(...) for cleaner syntax in commit 9a08803.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同様のコードがある箇所を全部指摘してあげないと指摘箇所しかやらないのかこいつは

Comment on lines +141 to 143
} finally {
currentOutputCallback = null;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot finally節を追加するならflushOutput();もfinallyに移動できます。
runFile()内についても同様

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved flushOutput() calls to finally blocks in both runCode() and runFile() functions in commit 9a08803.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

と思ったけど、エラーメッセージのあとにflushするのは違うな
あとでrevertする

…move flushOutput to finally

Co-authored-by: na-trium-144 <100704180+na-trium-144@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Dec 13, 2025

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • workers.cloudflare.com
    • Triggering command: /usr/local/bin/node node /home/REDACTED/.npm/_npx/8b377f6eec906bc4/node_modules/.bin/next build (dns block)
    • Triggering command: /usr/local/bin/node node ./node_modules/.bin/next build (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@na-trium-144 na-trium-144 marked this pull request as ready for review December 16, 2025 16:25
@na-trium-144 na-trium-144 merged commit e340893 into main Dec 16, 2025
3 checks passed
@na-trium-144 na-trium-144 deleted the copilot/fix-output-return-methods branch December 16, 2025 16:26
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.

jsEval.worker.ts, ruby.worker.ts, pyodide.worker.ts でoutputを配列にためるのではなく即座に呼び出し元に返す

2 participants