-
Notifications
You must be signed in to change notification settings - Fork 1.8k
fix: prevent Playwright MCP error flood from crashing OpenCode #975
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Conversation
When Playwright MCP outputs non-JSON-RPC data to stdout (npm download progress, browser console logs), the MCP SDK's JSON parser throws repeatedly in a while(true) loop, flooding the system with errors and causing OpenCode to become unresponsive. Changes: - Add --yes --quiet flags to npx in playwright skill config to suppress npm output - Implement error rate limiting in SkillMcpManager: if >50 errors occur within 1 second, the MCP client is automatically killed - Add descriptive error message when a killed client is detected - Add unit tests for error rate limiting behavior - Add issue documentation with full root cause analysis Fixes the infinite JSON parse error loop that made OpenCode unrecoverable when using the /playwright skill.
|
Thank you for your contribution! Before we can merge this PR, we need you to sign our Contributor License Agreement (CLA). To sign the CLA, please comment on this PR with: This is a one-time requirement. Once signed, all your future contributions will be automatically accepted. I have read the CLA Document and I hereby sign the CLA DC seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. |
There was a problem hiding this 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: d05e11ad27
ℹ️ 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".
| const originalOnerror = transport.onerror | ||
| transport.onerror = (error: Error) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Install rate limiter before client.connect
The error‑rate wrapper is installed only after client.connect(transport) completes; any non‑JSON stdout that appears during the initial handshake (e.g., npx download progress or early Playwright logs) will still hit the SDK’s unbounded onerror loop before this handler is attached. That means the original freeze can still happen during startup, which is the most likely time for npm noise. Consider wiring the transport.onerror wrapper before calling client.connect so startup errors are also rate‑limited.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No issues found across 4 files
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Summary
Fixes the infinite JSON parse error loop that makes OpenCode unrecoverable when using the
/playwrightskill.Problem
When Playwright MCP outputs non-JSON-RPC data to stdout (npm download progress, browser console logs, debug output), the MCP SDK's JSON parser throws repeatedly in a
while(true)loop, flooding the system with thousands of errors per second and causing OpenCode to freeze.Root Cause
The MCP SDK's stdio transport (
@modelcontextprotocol/sdk) has aprocessReadBuffer()method with this pattern:When garbage hits stdout, each line throws, the error is reported, and the loop continues - creating a denial-of-service on the error handler.
Solution
1. Suppress npm output (quick fix)
Added
--yes --quietflags to npx in the playwright skill config to prevent npm from outputting download progress.2. Error rate limiting (defensive fix)
Added error rate limiting to
SkillMcpManager:Changes
src/features/builtin-skills/skills.ts--yes --quietto npx argssrc/features/skill-mcp-manager/manager.tsErrorRateTracker, error rate limiting logicsrc/features/skill-mcp-manager/manager.test.tsdocs/issues/playwright-mcp-infinite-loop.mdTest Results
Notes
The pre-existing type errors in
session-manager/tools.test.ts,skill-mcp/tools.test.ts, andskill/tools.test.tsare unrelated to this change (missingmetadataandaskproperties inToolContext).Summary by cubic
Prevents the Playwright MCP from flooding errors and freezing OpenCode by suppressing noisy stdout and terminating runaway clients when error rates spike.
Written for commit d05e11a. Summary will update on new commits.