Skip to content

Improve handler shape validation guidance#101

Merged
simongdavies merged 2 commits intomainfrom
handler-shape-validation-guidance
May 3, 2026
Merged

Improve handler shape validation guidance#101
simongdavies merged 2 commits intomainfrom
handler-shape-validation-guidance

Conversation

@simongdavies
Copy link
Copy Markdown
Member

No description provided.

Copilot AI review requested due to automatic review settings April 30, 2026 22:03
@simongdavies simongdavies added the bug Something isn't working label Apr 30, 2026
Signed-off-by: Simon Davies <simongdavies@users.noreply.github.com>
@simongdavies simongdavies force-pushed the handler-shape-validation-guidance branch from 0dc252c to ea24aef Compare April 30, 2026 22:06
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR improves the handler-shape validation and user guidance around register_handler by loosening parameter requirements (custom parameter names / no parameter) and providing clearer remediation messaging for common invalid handler forms (notably arrow handlers).

Changes:

  • Extend JS validation to (a) treat plain function handler(...) {} declarations as “module mode”, (b) allow handlers with custom/zero parameters, and (c) provide more targeted structure error guidance.
  • Add/expand test coverage for the updated validator behavior (TS-side analysis guest tests + sandbox tool execution tests).
  • Update agent-facing guidance (system message + tool/help text) to reflect the supported handler shapes and common invalid patterns.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tests/sandbox-tool.test.ts Adds execution tests for module handlers with custom parameter names and with no parameters.
tests/analysis-guest.test.ts Adds validator tests for module-mode detection, allowed signatures, and improved guidance for invalid handler shapes.
src/code-validator/guest/runtime/src/validator.rs Implements signature-issue detection, updates module-mode detection, and adjusts handler structure validation messaging.
src/agent/system-message.ts Updates the “mandatory handler format” guidance to mention async-only-with-await, flexible params, and arrow-handler rejection.
src/agent/index.ts Updates tool/help text for register_handler and handler guidance to align with the validator’s rules.

Comment thread src/code-validator/guest/runtime/src/validator.rs Outdated
Comment thread src/code-validator/guest/runtime/src/validator.rs
Comment thread src/agent/index.ts Outdated
Comment thread src/agent/system-message.ts
…sistency

- Gate return-check on has_handler_function && no signature issue to
  avoid misleading 'MUST return' errors on invalid handler shapes
- Expand check_handler_has_return skip logic to also skip arrow function
  bodies (=> { ... }) and generator declarations (function*)
- Fix conflicting guidance in register_handler tool description: use
  function handler(...) instead of function handler(event) in REQUIRED line
- Add zero-parameter form function handler() to system-message signature list

Signed-off-by: Simon Davies <simongdavies@users.noreply.github.com>
@simongdavies simongdavies merged commit a81d171 into main May 3, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants