nanocoder icon indicating copy to clipboard operation
nanocoder copied to clipboard

[Bug] A plugin whose import never finishes freezes startup (no load timeout)

Open addyCooks opened this issue 1 month ago • 1 comments

Description

Plugin hooks have a 30 second timeout, but loading a plugin does not. importPlugins in source/plugins/host.ts awaits import() for each file in turn (line 115), with no limit. If a plugin waits on something that never answers (for example a top-level await fetch(...) to a host that is down), nanocoder run hangs forever with no message. Because plugins load one after another, every plugin after the slow one never loads either, including a guard plugin. runPluginHooks and consultPluginPermission also wait for the load to finish.

Environment

  • OS: Windows 11 (10.0.26300)
  • Node version: 22.22.3
  • Nanocoder version: 1.31.0 (main at 5c2e693)
  • Provider: Ollama
  • Model: qwen2.5:1.5b

Steps to Reproduce

  1. In a git project, create .nanocoder/plugins/slow.mjs:

    // Stands in for a fetch() to a host that never answers
    await new Promise(r => setTimeout(r, 600000));
    export default {name: 'slow', apiVersion: 1, hooks: {}};
    
  2. Run nanocoder --trust-directory run "Reply with the single word OK".

  3. Delete the plugin and run the same command again, as a control.

  4. Variant: replace the plugin body with await new Promise(() => {}); and run again.

Expected Behavior

After a timeout, Nanocoder prints something like Plugin slow.mjs did not finish loading within 30s and was skipped, skips it, loads the remaining plugins and carries on.

Actual Behavior

  • Step 2: no output at all. It was still running when I stopped it after 240 seconds.
  • Step 3 (control): finishes in about 11 seconds and prints OK.
  • Step 4: the process exits with code 0 after a few seconds and prints only the banner line. There is no answer, no error and no [plain] done.

For the interactive app, source/hooks/useAppInitialization.tsx:694 does await loadPlugins(true) before setStartChat(true), so the chat prompt would wait too. I only ran the run command, not the TUI.

Suggested Fix

  • In source/plugins/host.ts (line 115), race each import() against PLUGIN_HOOK_TIMEOUT_MS (line 30). On timeout, call logError with the plugin file name and continue to the next file.
  • Make the timeout something tests can lower (a parameter or an exported setting), so the test does not have to wait 30 seconds.
  • Add tests in source/plugins/host.spec.ts for an import that throws (that branch at line 120 is untested) and for an import that never finishes. A later plugin should still load.
  • Ideally also surface plugin load errors in run mode (see #1652).

Additional Context

  • [x] I have searched existing issues to ensure this is not a duplicate
  • [x] I can reproduce this issue consistently
  • [x] This issue occurs with the latest version of nanocoder

addyCooks avatar Oct 08 '26 17:10 addyCooks

@addyCooks can i go for it

Dhirenderchoudhary avatar Oct 09 '26 10:10 Dhirenderchoudhary