fix(cli-apps): lighten npm install + friendly timeout to avoid service restart#8
Merged
Merged
Conversation
…e restart Installing an npm-based CLI App on a small Render instance could 502 the whole service: the runtime `npm install -g` starves the 0.5-CPU box enough that it stops answering the health check, so Render restarts the container. Confirmed from metrics it is NOT an OOM (memory peaked ~300MB of 512MB, CPU 0.2 of 0.5) — it is health-check-triggered restart under install-time resource contention. - _npm_argv: add --no-audit --no-fund --maxsockets 4 to install/update to flatten the CPU/network burst (npm-only; pip/uv/brew unchanged). - _run_argv: convert subprocess.TimeoutExpired into a friendly CliAppError(503) advising an instance upgrade instead of leaking a raw traceback. - README: note that Starter runs the core experience fine but resource-intensive tasks (npm CLI Apps, image rendering) may need a Standard upgrade; fix typo. Blueprint plan/disk intentionally unchanged (lean default + documented upgrade). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Match the codebase convention — error strings elsewhere in nanobot/apps use plain ASCII, not em-dashes. Behavior unchanged. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Merge the instance-plan and persistent-disk upgrade guidance into a single Note, covering both the ~15s restart and the "No space left on device" cases. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Installing an npm-based CLI App (e.g.
GET /api/settings/cli-apps/install?name=hyperframes) on a Starter instance made the whole nanobot web service return 502 Bad Gateway for ~15s, then restart and recover with a fresh WebSocket token.Root cause (confirmed from Render metrics + logs — NOT OOM)
The earlier OOM hypothesis is disproven:
00:01:56npm install starts →00:02:27requests hang (responseTimeMS=45065, responseBytes=0= origin unreachable = the 502s) →00:02:40container fully restarts ([entrypoint] starting as uid=0(root)re-runs) →00:02:49healthy →00:03:45Render logsInstance restarted.Mechanism: the runtime
npm install -gstarves the single 0.5-CPU instance enough that it stops answering Render's health check (healthCheckPath: /, which serves the ~223 KB WebUI SPA), so Render restarts the container. The install already runs inasyncio.to_thread, so it's resource contention — not an event-loop deadlock and not a hard OOM.Changes
nanobot/apps/cli/service.py_npm_argv: add--no-audit --no-fund --maxsockets 4to install/update to flatten the CPU/network burst (npm-only; pip/uv/brew untouched)._run_argv: convertsubprocess.TimeoutExpiredinto a friendlyCliAppError(status=503)advising an instance upgrade, instead of leaking a raw Python traceback to the WebUI.README.md: note that Starter runs the core experience (chat, web search/fetch, memory) fine, but resource-intensive tasks (npm CLI Apps, image rendering) may briefly overwhelm the instance and can be run reliably by upgrading to a larger plan (Standard, 2 GB); cross-referenced from Cost expectations; fixed a pre-existing "dask" typo.tests/cli_apps/test_service.py: new tests for the npm flags and the timeout→503 mapping; updated the stale-install test's argv expectation.The blueprint
plan/diskare intentionally left unchanged — Starter is a fine lean default, and instance upgrades stay documented rather than forced.Verification
pytest tests/cli_apps/→ 37 passed;pytest tests/webui/→ 97 passed;ruff check nanobot/→ clean.Instance ... restarted).🤖 Generated with Claude Code