fix(bridge): harden PythonBridge error handling and bound buffers (STO-1411)#42
Merged
Merged
Conversation
…und buffers
Address STO-1411 codebase audit findings in src/python-bridge.ts:
- Handle child.stdin.write() failures and stdin stream 'error' events
(EPIPE / closed stdin) by rejecting the pending request immediately as
StdinWriteError/StdinError instead of hanging until timeout or crashing
the Node process with an unhandled stream error.
- Make callSync() throw PythonBridgeError for { success: false, code }
responses so its error semantics match async call(); guard the catch
block against re-wrapping PythonBridgeError as ProcessError.
- Bound the per-request stderr buffer (64KB) and the stdout line buffer
(1MB); on stdout overflow reject with ResponseOverflow, reset the
buffer, and kill the process.
- Add idempotent failPendingRequest() helper shared by the new failure
paths.
Tests: 29/29 pass (4 new cases + updated stdin.write assertions),
tsc --noEmit clean.
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.
Summary
Fixes the 4 codebase-audit findings in
src/python-bridge.ts(STO-1411,openswarm review --max).python-bridge.ts:336stdin.write()failures andstdin'error'events (EPIPE / closed stdin) now reject the pending request immediately asStdinWriteError/StdinErrorinstead of hanging until timeout or crashing Node with an unhandled stream error.python-bridge.ts:357callSync()now throwsPythonBridgeErrorfor{ success: false, code }responses so its error semantics match asynccall(); the catch block no longer re-wrapsPythonBridgeErrorasProcessError.python-bridge.ts:178python-bridge.ts:223ResponseOverflow, reset buffer, kill process.Adds an idempotent
failPendingRequest()helper shared by the new failure paths.Verification
Ran via an ephemeral ts-jest harness (repo has no bundled TS toolchain — CLI scaffolding was never built):
stdin.writecallback signature.tsc --noEmitclean (strict,@types/node).No live KIS API calls (mock/type level only) — no account/order side effects. E2E is out of scope (no CLI entrypoint).
🤖 Generated with Claude Code