fix(agent): tell users to clear a broken npx cache instead of "API Error" - #1200
Draft
posthog[bot] wants to merge 7 commits into
Draft
fix(agent): tell users to clear a broken npx cache instead of "API Error"#1200posthog[bot] wants to merge 7 commits into
posthog[bot] wants to merge 7 commits into
Conversation
…ror" A half-written ~/.npm/_npx extraction makes Node fail the pi-coding-agent dynamic import with ERR_MODULE_NOT_FOUND. Both pi catch blocks classified that as AgentErrorType.API_ERROR, so the user saw an "API Error" heading and a request to email support, for a problem they can fix in one command. Add AgentErrorType.MODULE_MISSING (PHW_AGENT_MODULE_MISSING), detect the Node error in the run and task catch blocks, and render a message that names the exact cached download to delete and the command to rerun. Generated-By: PostHog Desktop Task-Id: 9fe44d3a-6a47-4d1d-8950-c84b7281c08b
Contributor
Author
🦔 PostHog Review reviewed this pull requestFound 1 must fix, 2 should fix, 3 consider. Published 6 findings (view the review). Resolved comments: 2 fixed, 1 already settled |
🧙 Wizard CIRun the Wizard CI and test your changes against wizard-workbench example apps by replying with a GitHub comment using one of the following commands: Test all apps:
Test all apps in a directory:
Test an individual app:
Show more apps
Test against a Context Mill branch:
Add Results will be posted here when complete. |
Contributor
Author
|
PostHog Review alpha 🦔 If you find any issues helpful - please reply "valid", "invalid", etc., for evaluation purposes 🙏 |
The catalog doc's "Extending the catalog" procedure requires a table row for every new code. PHW_AGENT_MODULE_MISSING had the codes.ts constant and the ERROR_CATALOG entry but no documented row, so an integrator reading the markdown mirror would fall back to a default retry policy on a failure that never heals between runs. Generated-By: PostHog Desktop Task-Id: 4c97b145-3d33-4a0c-b890-f58cb5ef8189
… test The rate-limit branch matches "429" anywhere in the lowercased message. An npx cache directory is a 16-character hex hash, and Node's ERR_MODULE_NOT_FOUND message embeds that path twice, so a hash containing "429" made a broken npx download report as a rate limit — and from there as the same "API Error" text this change set out to replace. Module resolution is decided by the error object itself, so it now goes first in both pi catch blocks. A genuine rate-limit message never satisfies isModuleNotFoundError, so no other input changes classification. The loose "429" substring test is pre-existing and left as is; tightening it to a status token is a separate change to rate-limit handling. Generated-By: PostHog Desktop Task-Id: 4c97b145-3d33-4a0c-b890-f58cb5ef8189
Every non-orchestrator program renders this message through linear.ts, not just the default integration flow. The literal `npx @posthog/wizard@latest` line sat directly under a "run the wizard again" instruction, so a user who ran a read-only command such as `wizard audit events` would copy-paste their way into the base integration flow, which changes their project. The message now asks the user to run the same wizard command again, which is correct for every command and for an explicit --install-dir. Rebuilding the real invocation from argv was rejected: it would have to filter secret option values such as --api-key for no gain over prose. Generated-By: PostHog Desktop Task-Id: 4c97b145-3d33-4a0c-b890-f58cb5ef8189
… screen runPiTask classified a broken npx download, but nothing read the result: the executor's RunTask returns void and the drain call discarded it, while the seed path only logged. Orchestrator runs — the default integration flow and metrics — therefore still ended on the generic "report this to us" text, which is the population this change was written for. Both paths now record the failure, and a run that ended badly aborts with PHW_AGENT_MODULE_MISSING and the cache repair command before the queue verdict is read. The abort is gated on the run having actually failed, so a run that completed in spite of one bad task keeps its result. Reusing one AgentResult router across the linear and orchestrator sequences was rejected here: the two abort on different verdicts, and the shared abstraction is a larger design change than this fix needs. Generated-By: PostHog Desktop Task-Id: 4c97b145-3d33-4a0c-b890-f58cb5ef8189
The prefix before `_npx` excluded whitespace, so a home directory with a space in it started the match after the last space: `/Users/First Last/.npm/_npx/9f2` was captured as `Last/.npm/_npx/9f2`. The printed repair then targeted a relative path — on POSIX `rm -rf` matches nothing and exits 0, so the user believes the cache is clear, reruns, and hits the identical failure. Windows, where `C:\Users\John Smith` is ordinary, fails loudly instead. The prefix is now fenced by the quotes Node puts around a specifier rather than by whitespace, and has to start at a real root (`/`, a drive, or a UNC share). A fragment that cannot be rooted no longer matches at all, so it reaches the whole-cache fallback instead of being printed as if it were verified — half a path is worse than none here. The trailing segment stops at whitespace too, so prose after the hash is no longer swallowed. Covered by three tests: a POSIX path with a space, a Windows path with a space, and an unrooted fragment falling back. Generated-By: PostHog Desktop Task-Id: 398deef2-51b6-41a3-9b19-10e368612efe
`process.platform` names the OS, not the shell. `Remove-Item` is a PowerShell cmdlet, so a Windows user at a Command Prompt who pastes the printed line gets "'Remove-Item' is not recognized" — the recovery step fails even when the path is right, which is the one thing this message exists to prevent. Windows now prints both forms, labelled and aligned, and the user picks the one their prompt understands: PowerShell: Remove-Item -Recurse -Force "C:\...\_npx\abc" Command Prompt: rmdir /s /q "C:\...\_npx\abc" Detecting the shell was rejected: the repo carries no shell detection today (every other process.platform check picks a filesystem location, where the OS is the right axis), and inferring it from ComSpec or MSYSTEM is a new concern for no gain over letting the reader choose a labelled line. Non-Windows output is byte-identical. Covered by a test that stubs process.platform to win32, matching the pattern in the MCP client tests. Generated-By: PostHog Desktop Task-Id: 398deef2-51b6-41a3-9b19-10e368612efe
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
~/.npm/_npxextractions can truncate. Node then fails thepi-coding-agentdynamic import withERR_MODULE_NOT_FOUND, and both pi catch blocks fall through toAgentErrorType.API_ERROR.wizard: agent api errortelemetry from a second user on Windows.Changes
API_ERROR→PHW_AGENT_API_ERRORMODULE_MISSING→PHW_AGENT_MODULE_MISSINGagent module missingisModuleNotFoundErrorreads the Node error code and falls back to the message text, because a rethrow across a boundary keeps the text but drops the code.formatModuleMissingMessagetakes the.../_npx/<hash>/...path out of the failure text, so the user deletes one download and not the whole cache. It falls back to the platform npx cache root, and printsrm -rforRemove-Itemper platform.harness/pi/index.ts(default flow) andharness/pi/task.ts(orchestrator tasks).New message
Test plan
pnpm build && pnpm test && pnpm lint— 2606 tests pass, 0 lint errors.src/lib/errors/__tests__/module-missing.test.tscover: the Node error code, the message-only form, an ordinary API failure staying unclassified, the exact directory in the output, and the cache-root fallback.LLM context
Written by PostHog Desktop from the linked inbox report. Considered and skipped: the same classification in
agent-interface.ts(the Claude SDK harness). A module failure there rethrows and never reaches the "API Error" screen, so it is a different symptom.Created with PostHog Desktop from this inbox report.