Fix executeCode return values - #210
Conversation
|
All contributors have signed the CLA ✍️ ✅ |
|
I have read the CLA Document and I hereby sign the CLA |
There was a problem hiding this comment.
Pull request overview
This PR fixes a code-mode execution gap in the Workshop backend by preserving a code-mode module’s return value from the dynamic Worker harness, propagating it through executeCodeMode(), and appending it to the existing console-output-based result.
Changes:
- Update the code-mode harness to
returnthe user module’sagent(...)result. - Thread the harness return value through the
CodeModeEntrypoint.run()RPC typing andexecuteCodeMode()output formatting via a newappendCodeModeReturnValue()helper. - Add a unit test covering harness text and basic return-value formatting.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| packages/workshop-backend/src/overseer.ts | Return the code-mode module value from the harness and append it to formatted execution logs. |
| packages/workshop-backend/tests/code-mode-return.test.ts | Adds a unit test for the harness return and return-value rendering helper. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| it("preserves code mode return values", () => { | ||
| expect(CODE_MODE_HARNESS).toContain("return await agent"); | ||
| expect(appendCodeModeReturnValue("", 1n)).toBe("1"); | ||
| expect(appendCodeModeReturnValue("started", { ok: true })).toBe('started\n{"ok":true}'); | ||
| }); |
There was a problem hiding this comment.
Added a circular plain-object case that makes JSON.stringify() throw and asserts the explicit fallback. I also removed the source-text assertion so the test exercises return rendering behavior directly. The mutation check fails with "[object Object]" when the fallback is broken.
What does this change?
Part of #209.
During a live Cloudflare OS session, several
executeCodesteps completed with no visible output.That symptom can have more than one cause. This PR addresses one independently reproducible case:
a code-mode module returns a value without calling
console.log(), but the dynamic Worker harnessawaits and discards that value, so the completed invocation renders blank output.
The patch returns the module value from the harness, carries it through
executeCodeMode(), andappends it to existing console output. Plain objects and arrays use JSON; other RPC-supported values
use their string representation, with an explicit fallback if rendering throws.
undefinedkeepsthe existing console-only behavior.
This PR does not claim to explain every blank or timed-out code-mode step.
Why is this obviously correct and trivially verifiable?
The patch follows the existing call path directly: the harness returns
agent(...), the RPC typeaccepts that value,
executeCodeMode()captures it, and one small formatter appends it. The testchecks structured and non-JSON return rendering, plus a circular plain object that exercises the
explicit serialization fallback. No bindings, outbound access, authorization, or execution policy
changes.
Verification: Workshop unit tests (285/285), integration tests (2 passed, 4 existing skips),
Workshop build/typecheck, full repository tests and lint, and
git diff --checkall pass on Node 24.Checklist