FE-1411: Make the Petrinaut CLI protocol handler async-safe - #9225
Draft
kube wants to merge 1 commit into
Conversation
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.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
2 Skipped Deployments
|
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.
🌟 What is the purpose of this PR?
Preparation layer for running a trial's seeded simulations on worker threads (FE-1408 stack):
optimization.evaluatebecomes 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 PR → FE-1408 (worker pool).
🔗 Related links
🔍 What does this change?
@hashintel/petrinaut-clionly:OptimizationProtocol.evaluatereturns aPromise;handleProtocolLineis async and awaits it. All errors still become one{ id, error }line.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:
@hashintel/petrinaut-cliis private)📜 Does this require a change to the docs?
The changes in this PR:
🕸️ Does this require a change to the Turbo Graph?
The changes in this PR:
🛡 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 toresolves/rejects.❓ How to test this?
🤖 Generated with Claude Code