Skip to content

fix(fabricator): harden framing, prevent stdio deadlocks, and add regression tests - #294

Open
chrhoffmann wants to merge 1 commit into
yao-pkg:mainfrom
chrhoffmann:fix/fabricator-framing-stdio
Open

fix(fabricator): harden framing, prevent stdio deadlocks, and add regression tests#294
chrhoffmann wants to merge 1 commit into
yao-pkg:mainfrom
chrhoffmann:fix/fabricator-framing-stdio

Conversation

@chrhoffmann

Copy link
Copy Markdown

Summary

This PR fixes non-deterministic hangs in bytecode fabrication by hardening parent/child framing in the fabricator path and adding focused regression tests.

Problem

pkg could hang during builds due to corrupted frame headers and stream-boundary truncation in fabricator IPC, with additional risk from debug stderr handling under backpressure.

Root Cause

  • A single mutable 4-byte header buffer was reused across async stdin.write() calls.
  • Child parser reset its input buffer in ways that could drop trailing bytes when chunks crossed frame boundaries.
  • Debug-mode stderr wiring could contribute to pipe/backpressure deadlock patterns.

Changes

fabricator.ts

  • Hardened frame parsing in the inline child script:
    • process multiple frames per chunk
    • preserve unconsumed trailing bytes between iterations
  • Added defensive frame-size guards for both snap/body headers.
  • Kept stderr piped and routed debug output via logger.
  • Removed unexpected-close console side effects in favor of debug logging.
  • Added buildFabricatorRequestChunks(...) to construct isolated frame chunks with distinct headers.
  • Exported fabricatorScript for direct regression testing.

fabricator.test.ts

Added targeted unit regressions:

  • header isolation (no shared header-buffer aliasing)
  • multi-frame decode when payload boundaries are split across writes
  • invalid size-header rejection (fast-fail path)

Validation

  • npm run test:unit
  • npm run lint
  • npm run build
  • Regression tests reproduce the original failure modes (header aliasing, cross-boundary truncation) and pass with the fix applied.

Risk / Compatibility

  • Scope is localized to fabricator framing/stdio path.
  • No CLI/API surface changes.
  • Low regression risk due to explicit regressions and full local checks passing.

Reviewer Checklist

  • Verify frame protocol and stderr/debug handling in fabricator.ts
  • Confirm regressions in fabricator.test.ts cover the reported failure modes
  • Confirm CI passes on main target (yao-pkg/pkg)

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