Skip to content

fix(skills): run sherpa-onnx-tts bin under ESM#31965

Merged
steipete merged 1 commit intoopenclaw:mainfrom
bmendonca3:bm/sherpa-onnx-tts-esm
Mar 2, 2026
Merged

fix(skills): run sherpa-onnx-tts bin under ESM#31965
steipete merged 1 commit intoopenclaw:mainfrom
bmendonca3:bm/sherpa-onnx-tts-esm

Conversation

@bmendonca3
Copy link

Summary

Describe the problem and fix in 2–5 bullets:

  • Problem: skills/sherpa-onnx-tts/bin/sherpa-onnx-tts used CommonJS require(...) in a type: module repo, so direct node execution fails before argument parsing.
  • Why it matters: the built-in sherpa local-TTS skill cannot run at all for Node 22+ users invoking the bin script.
  • What changed: converted the bin entrypoint imports to ESM (import fs/path/spawnSync ...) and added a regression test that executes the bin script as a real Node entrypoint.
  • What did NOT change (scope boundary): no behavior changes to arg parsing, env resolution, model/runtime selection, or sherpa invocation flags.

Change Type (select all)

  • Bug fix
  • Feature
  • Refactor
  • Docs
  • Security hardening
  • Chore/infra

Scope (select all touched areas)

  • Gateway / orchestration
  • Skills / tool execution
  • Auth / tokens
  • Memory / storage
  • Integrations
  • API / contracts
  • UI / DX
  • CI/CD / infra

Linked Issue/PR

User-visible / Behavior Changes

  • node skills/sherpa-onnx-tts/bin/sherpa-onnx-tts ... now loads correctly in ESM mode and reaches normal usage/runtime validation instead of crashing at module load.

Security Impact (required)

  • New permissions/capabilities? (No)
  • Secrets/tokens handling changed? (No)
  • New/changed network calls? (No)
  • Command/tool execution surface changed? (No)
  • Data access scope changed? (No)
  • If any Yes, explain risk + mitigation:

Repro + Verification

Environment

  • OS: macOS 15
  • Runtime/container: Node v22.22.0
  • Model/provider: N/A
  • Integration/channel (if any): sherpa-onnx-tts bundled skill bin
  • Relevant config (redacted): none required to reproduce module-load failure

Steps

  1. On upstream/main, run: node skills/sherpa-onnx-tts/bin/sherpa-onnx-tts --help
  2. Observe startup crash: ReferenceError: require is not defined in ES module scope.
  3. Apply this branch and rerun the same command.

Expected

  • Bin script should run under ESM and proceed to usage/runtime validation.

Actual

  • Before fix: hard crash at line 3 on require(...).
  • After fix: script prints usage/missing env guidance (expected path when runtime/model env is not set).

Evidence

Attach at least one:

  • Failing test/log before + passing after
  • Trace/log snippets
  • Screenshot/recording
  • Perf numbers (if relevant)

Human Verification (required)

What you personally verified (not just CI), and how:

  • Verified scenarios:
    • Reproduced failure before patch with: node skills/sherpa-onnx-tts/bin/sherpa-onnx-tts --help (module-load require crash).
    • Verified post-fix behavior with: node skills/sherpa-onnx-tts/bin/sherpa-onnx-tts (usage output path).
    • Ran regression test: pnpm test src/agents/skills.sherpa-onnx-tts-bin.test.ts.
    • Ran static/type checks for touched code path: pnpm tsgo, pnpm lint.
  • Edge cases checked:
    • Entry script executed with no env still exits with usage (status 1), not module-load exception.
  • What you did not verify:
    • Full live sherpa runtime execution with downloaded models/binaries.

Compatibility / Migration

  • Backward compatible? (Yes)
  • Config/env changes? (No)
  • Migration needed? (No)
  • If yes, exact upgrade steps:

Failure Recovery (if this breaks)

  • How to disable/revert this change quickly:
    • Revert this PR commit.
  • Files/config to restore:
    • skills/sherpa-onnx-tts/bin/sherpa-onnx-tts
    • src/agents/skills.sherpa-onnx-tts-bin.test.ts
  • Known bad symptoms reviewers should watch for:
    • Unexpected import/loader errors in the sherpa skill bin entrypoint.

Risks and Mitigations

List only real risks for this PR. Add/remove entries as needed. If none, write None.

  • Risk: none observed; import syntax migration only.
    • Mitigation: regression test executes the exact bin script path with Node entrypoint semantics.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2243df47c8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +14 to +16
const result = spawnSync(process.execPath, [scriptPath], {
encoding: "utf8",
});

Choose a reason for hiding this comment

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

P2 Badge Isolate bin regression test from inherited SHERPA env

This test assumes the child process has no SHERPA_ONNX_RUNTIME_DIR/SHERPA_ONNX_MODEL_DIR, but spawnSync inherits the parent environment by default. If either variable is set in a developer shell or CI job, the script takes a different validation path and expect(result.stderr).toContain("Missing runtime/model directory.") fails even though ESM loading is fine, making the regression test non-deterministic across environments.

Useful? React with 👍 / 👎.

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Mar 2, 2026

Greptile Summary

This PR converts the sherpa-onnx-tts bin script from CommonJS to ESM, fixing a critical module loading bug in Node.js 22+. The change is minimal and surgical - only three import statements were converted from require() to ESM import syntax. A regression test was added that spawns the bin script directly and verifies it loads without throwing the CommonJS error. The test follows project conventions and provides good coverage of the fix.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk - it's a straightforward syntax conversion with a regression test.
  • The change is extremely narrow in scope (3 lines of import syntax), addresses a real blocking bug, includes a regression test that verifies the fix, and makes no behavioral changes. The ESM import syntax is correct and matches the project's type: module configuration.
  • No files require special attention

Last reviewed commit: 2243df4

@steipete steipete merged commit 738f5d4 into openclaw:main Mar 2, 2026
24 of 25 checks passed
@steipete
Copy link
Contributor

steipete commented Mar 2, 2026

Landed via temp rebase onto main.

  • Gate: pnpm test src/agents/skills.sherpa-onnx-tts-bin.test.ts
  • Land commit: ff66280
  • Merge commit: 738f5d4

Thanks @bmendonca3!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: The sherpa-onnx-tts script in the bin/ folder of the skill uses CommonJS syntax (fails to run)

2 participants