| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
|
The following comment was made by an LLM, it may be inaccurate: I found several related PRs that address similar issues with cleanup, signal handling, and preventing orphaned processes: Potential Related/Duplicate PRs:
You should verify the status of PR #12877 in particular, as it appears to be a very recent and directly related fix for the same orphaned process issue. |
Sorry, something went wrong.
Self-Review: What the tests prove (and don't)Tests that passed (10 new tests, all green)
What's NOT tested
Probability each fix helps with the reported issue (#12687)
Test results
|
Sorry, something went wrong.
Response to related PRs checkI reviewed all 4 flagged PRs. None have been merged into dev as of today. Here is the overlap analysis: PR #12877 — signal handlers to prevent orphaned processesDirect overlap with our index.ts changes. Both add SIGTERM/SIGINT/SIGHUP handlers calling Instance.disposeAll(). Key differences:
Assessment: #12877 has a cleaner modular design with the timeout safety net. Our approach is simpler but covers the finally block too. If #12877 is merged first, we should drop our index.ts signal handler changes and keep only the finally block addition. PR #11603 — prevent orphaned worker process when killedPartial overlap with our worker.ts changes. Both add signal handlers to the worker. Key differences:
Assessment: #11603 is more thorough — the parent-death polling catches the case where the main process is SIGKILL'd (which no signal handler can intercept). If #11603 is merged first, we should drop our worker.ts changes entirely. PR #9866 — signal handlers for graceful shutdown on WindowsPartial overlap with our serve.ts changes. Both address graceful shutdown of the serve command. Key differences:
Assessment: Our serve.ts fix is more complete since it also removes the dead code. #9866 just adds handlers above the existing broken pattern. These could coexist but ours makes #9866's changes redundant. PR #9145 — memory leaks in OAuth transport and process cleanupMinimal overlap. #9145 focuses on MCP OAuth transport lifecycle (closeTransport, setPendingOAuthTransport) which we do not touch. Its index.ts changes overlap with ours (signal handlers + main() wrapper with cleanup) but the MCP-specific fixes are orthogonal. Assessment: The MCP OAuth transport fixes in #9145 are valuable and complementary to our PR. If both merged, only the index.ts changes conflict. SummaryOur PR has unique value beyond what the other PRs offer:
The signal handler overlap (index.ts, worker.ts) is expected since multiple people independently identified the same root cause. Whichever PR is merged first, the others should rebase and drop the duplicate changes. |
Sorry, something went wrong.
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
Sorry, something went wrong.
…andlers - Add SIGTERM/SIGINT/SIGHUP signal handlers to index.ts, worker.ts, and serve.ts that call Instance.disposeAll() to clean up child processes (LSP servers, MCP servers, bash tool processes spawned with detached:true) - Replace O(n²) string concatenation (output += chunk.toString()) in bash.ts and prompt.ts shell execution with Buffer[] ring buffer + capped preview - Replace deep clone of entire message history in prompt.ts with shallow copy (only the parts that get mutated need copying) - Add dispose callbacks to PermissionNext, Question, and FileTime state to reject pending promises and clear session data on instance disposal Fixes anomalyco#12687
- Signal handler pattern test: verifies SIGTERM triggers graceful handler instead of default kill behavior (proves index.ts signal handler works) - Bash ring buffer memory test: verifies output metadata preview stays capped at 30KB and total memory growth is bounded for large output - Dispose callback tests: verifies PermissionNext and Question pending promises are rejected with RejectedError on Instance.dispose() - FileTime state cleanup test: verifies session data is cleared on disposal - Instance.disposeAll() idempotency test: verifies safe double-call
Replace preview += chunk.toString() with string[] array accumulation joined only on flush. Throttle Session.updatePart() / ctx.metadata() calls to at most every 100ms via setTimeout. In prompt.ts shell(), reduce preview cap from 1MB to 30KB (MAX_METADATA_LENGTH) to match bash.ts. These three changes together eliminate ~64GB of transient allocations that caused 100GB RAM consumption and macOS kernel panics when running verbose commands.
…uffer - processor.ts: accumulate text/reasoning deltas in arrays with throttled flush (50ms) instead of per-token part.text += and Session.updatePart() calls, eliminating O(n²) string concatenation and quadratic JSON.stringify/Storage.write/Bus.publish overhead - pty/index.ts: replace buffer string concatenation with chunks array and length tracking, drop oldest chunks on overflow instead of join+slice, send chunks individually on client connect
Addresses the remaining memory leaks identified in anomalyco#16697 by consolidating the best fixes from 23+ open community PRs into a single coherent changeset. Fixes consolidated from PRs: anomalyco#16695, anomalyco#16346, anomalyco#14650, anomalyco#15646, anomalyco#13186, anomalyco#10392, anomalyco#7914, anomalyco#9145, anomalyco#9146, anomalyco#7049, anomalyco#16616, anomalyco#16241 - Plugin subscriber stacking: unsub before re-subscribing in init() - Subagent deallocation: Session.remove() after task completion - SSE stream cleanup: centralized cleanup with done guard (3 endpoints) - Compaction data trimming: clear output/attachments on prune - Process exit cleanup: Instance.disposeAll() with 5s timeout - Serve cmd: graceful shutdown instead of blocking forever - Bash tool: ring buffer with 10MB cap instead of O(n²) concat - LSP index teardown: clear clients/broken/spawning on dispose - LSP open-files cap: evict oldest when >1000 tracked files - Format subscription: store and cleanup unsub handle - Permission/Question clearSession: reject pending on session delete - Session.remove() cleanup chain: FileTime, Permission, Question - ShareNext subscription cleanup: store unsub handles, cleanup on dispose - OAuth transport: close existing before replacing Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Closing this upstream PR to keep active work on the fork only. Current workflow: open PRs on dzianisv/opencode, merge into fork main, and do not keep active PRs in anomalyco/opencode. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Fixes #12687
Summary
Fix memory explosion (100GB+ RAM → macOS crash) caused by O(n²) allocation patterns in multiple hot paths and missing process cleanup handlers.
Changes
1. LLM response streaming (processor.ts) — Critical fix
2. PTY terminal buffer (pty/index.ts)
3. Bash tool output streaming (bash.ts)
4. Shell command output streaming (prompt.ts)
5. Copilot SDK tool call arguments (openai-compatible-chat-language-model.ts)
6. Copilot message conversion (convert-to-openai-compatible-chat-messages.ts)
7. Ripgrep line reader (ripgrep.ts)
8. WebFetch HTML text extraction (webfetch.ts)
9. Process cleanup handlers
Verification