Skip to content

Conversation

@rabi
Copy link
Contributor

@rabi rabi commented Dec 24, 2025

Summary

The code execution extension's result wrapping logic only looked at the last line of code, not the complete multi-line statement. When code ended with continuation characters like });, the wrapping produced invalid JavaScript syntax like __result__ = })), causing parse errors and infinite retry loops.

  • Extract wrap_code_for_result() to handle multiline expressions ending with });
  • Detect continuation lines (closing brackets, method chaining)
  • Find expression start for proper wrapping instead of wrapping interior lines
  • Serialize results using to_json() instead of display() to show actual array/object contents
  • Update LLM instructions for clearer code formatting guidance

Type of Change

  • Feature
  • Bug fix
  • Refactor / Code quality
  • Performance improvement
  • Documentation
  • Tests
  • Security fix
  • Build / Release
  • Other (specify below)

AI Assistance

  • This PR was created or reviewed with AI assistance

Testing

Unit tests and manual testing.

Related Issues

Closes: #6266

@rabi rabi force-pushed the multiline_fix branch 8 times, most recently from 84e9a27 to ae1ce5f Compare December 28, 2025 11:52
@rabi rabi changed the title fix(code-execution): handle multi-line expressions in JS result wrapping fix(code-execution): auto-wrap multi-line function calls, serialize results as JSON Dec 28, 2025
…esults as JSON

- Extract wrap_code_for_result() to handle multiline expressions ending with });
- Detect continuation lines (closing brackets, method chaining)
- Find expression start for proper wrapping instead of wrapping interior lines
- Serialize results using to_json() instead of display() to show actual array/object contents
- Update LLM instructions for clearer code formatting guidance

Signed-off-by: rabi <[email protected]>
Copy link
Collaborator

@alexhancock alexhancock left a comment

Choose a reason for hiding this comment

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

thanks for looking at this

the result wrapping/capture was always one of my least favorite parts of what I originally merged. let me take a look at a more comprehensive fix that would avoid the need for something like this. if I don't come up with anything in a day or two we can proceed with this

@alexhancock
Copy link
Collaborator

#6343

@rabi
Copy link
Contributor Author

rabi commented Jan 6, 2026

Closing in favor of #6343

@rabi rabi closed this Jan 6, 2026
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.

Code execution extension produces syntax errors for multi-line JavaScript expressions

2 participants