Skip to content

FE-1411: Make the Petrinaut CLI protocol handler async-safe - #9225

Draft
kube wants to merge 1 commit into
cf/fe-1410-optimization-manifest-define-the-seeds-per-trial-contract-infrom
cf/fe-1411-petrinaut-cli-make-the-protocol-handler-async-safe
Draft

FE-1411: Make the Petrinaut CLI protocol handler async-safe#9225
kube wants to merge 1 commit into
cf/fe-1410-optimization-manifest-define-the-seeds-per-trial-contract-infrom
cf/fe-1411-petrinaut-cli-make-the-protocol-handler-async-safe

Conversation

@kube

@kube kube commented Aug 16, 2026

Copy link
Copy Markdown
Collaborator

🌟 What is the purpose of this PR?

Preparation layer for running a trial's seeded simulations on worker threads (FE-1408 stack): optimization.evaluate becomes asynchronous, so the CLI's protocol dispatch and both transports must stop assuming a synchronous handler. This PR makes that safe with no request or response shape changes — every evaluate still resolves synchronously, so behaviour is identical.

Stack: FE-1410 (contract) → this PRFE-1408 (worker pool).

🔗 Related links

  • FE-1411 (internal) — this PR
  • FE-1408 (internal) — parent: seeded trials in the CLI

🔍 What does this change?

@hashintel/petrinaut-cli only:

  • OptimizationProtocol.evaluate returns a Promise; handleProtocolLine is async and awaits it. All errors still become one { id, error } line.
  • The stdio loop awaits each line, preserving strict request ordering.
  • The Unix-socket transport serializes per-connection handling on a promise chain and opens the server with allowHalfOpen: true, ending the socket itself once queued responses have flushed. Previously, Node's auto-close on the client's FIN could race responses that a deferred handler had not yet written; the trailing-buffer request received just before FIN is the observable case.

Pre-Merge Checklist 🚀

🚢 Has this modified a publishable library?

This PR:

  • modifies a workspace but not a publishable library (@hashintel/petrinaut-cli is private)

📜 Does this require a change to the docs?

The changes in this PR:

  • are not user-facing so no docs are required — no protocol or CLI surface changes.

🕸️ Does this require a change to the Turbo Graph?

The changes in this PR:

  • do not affect the execution graph

🛡 What tests cover this?

  • protocol.test.ts — all dispatch tests run through the awaited handler.
  • transports.test.ts — stdio and Unix-socket suites, including chunked and trailing-buffer socket requests whose responses must flush before close.
  • optimization.test.ts — evaluate assertions moved to resolves/rejects.

❓ How to test this?

turbo run test:unit --filter @hashintel/petrinaut-cli

🤖 Generated with Claude Code

Protocol dispatch becomes awaitable so optimization.evaluate can defer
simulation work without another protocol change: the stdio loop awaits
each line, and the Unix-socket transport serializes per-connection
handling on a promise chain, keeping one-response-per-line ordering and
holding the write side open (allowHalfOpen) until queued responses have
flushed. No request or response shape changes.
@kube kube self-assigned this Aug 16, 2026
@vercel

vercel Bot commented Aug 16, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
hash Ready Ready Preview Aug 16, 2026 5:23pm
2 Skipped Deployments
Project Deployment Actions Updated (UTC)
hashdotdesign-tokens Ignored Ignored Preview Aug 16, 2026 5:23pm
petrinaut Skipped Skipped Aug 16, 2026 5:23pm

@vercel
vercel Bot temporarily deployed to Preview – petrinaut August 16, 2026 17:12 Inactive
@github-actions github-actions Bot added area/libs Relates to first-party libraries/crates/packages (area) type/eng > frontend Owned by the @frontend team labels Aug 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/libs Relates to first-party libraries/crates/packages (area) type/eng > frontend Owned by the @frontend team

Development

Successfully merging this pull request may close these issues.

1 participant