Skip to content

fix(bridge): harden PythonBridge error handling and bound buffers (STO-1411)#42

Merged
unohee merged 1 commit into
mainfrom
unoheeofficial/sto-1411-python-bridge-error-handling
Jul 1, 2026
Merged

fix(bridge): harden PythonBridge error handling and bound buffers (STO-1411)#42
unohee merged 1 commit into
mainfrom
unoheeofficial/sto-1411-python-bridge-error-handling

Conversation

@unohee

@unohee unohee commented Jul 1, 2026

Copy link
Copy Markdown
Owner

Summary

Fixes the 4 codebase-audit findings in src/python-bridge.ts (STO-1411, openswarm review --max).

Type Location Fix
bug python-bridge.ts:336 stdin.write() failures and stdin 'error' events (EPIPE / closed stdin) now reject the pending request immediately as StdinWriteError/StdinError instead of hanging until timeout or crashing Node with an unhandled stream error.
bug python-bridge.ts:357 callSync() now throws PythonBridgeError for { success: false, code } responses so its error semantics match async call(); the catch block no longer re-wraps PythonBridgeError as ProcessError.
perf python-bridge.ts:178 per-request stderr buffer bounded to 64KB (tail kept).
perf python-bridge.ts:223 stdout line buffer bounded to 1MB; on overflow reject with ResponseOverflow, 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):

  • jest: 29/29 pass — 25 existing + 4 new (stdin write error, stdin stream error, stdout overflow, callSync failure-response throw). Updated 2 existing assertions for the new stdin.write callback signature.
  • tsc --noEmit clean (strict, @types/node).
  • Node 22 type-stripping syntax check passes.

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

…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.
@unohee unohee merged commit 148c574 into main Jul 1, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant