✨ Replace free-port probing with attached services - #390
Merged
Conversation
PR #390: ✨ Replace free-port probing with cooperative services53 files, +3262 / -1918 Scope🔴 PR has 5180 lines changed. Split into focused PRs. 🟡 5180 lines changed. PRs under 400 receive more thorough review. 🟡 53 files changed. Are all changes related? Structural✅ No structural bloat detected. Slop✅ Slop indicators look low. Static Analysis✅ Oxlint found no issues. CorrectnessNo extraneous code patterns detected. |
Owner
Author
|
The scope warning is understood. This is one cross-package behavioral migration rather than several independent features:
The branch is arranged as three dependency-ordered commits for review: host/runtime API, replay-safe modifiers and integration, then documentation. Every changed file maps to an acceptance criterion in #381, and the aggregate ten-command verifier passes with an unchanged tracked tree. |
taras
marked this pull request as ready for review
August 8, 2026 17:14
6 tasks
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.
Why
Free-port probing reserves nothing, so a provider can lose the selected port before its process binds. It also gives durable replay no way to distinguish a live invocation-local endpoint from persisted state.
Closes #381.
Closes #137.
What changes
Before:
Providers selected a port with
findFreePort, launched a process separately, and could persist or replay an endpoint that no longer named a live service. The first implementation also delayed unterminated service stdout until teardown, allowed durable eval to collide with a live service binding, and did not translate observable process teardown failures.After:
A
service=<binding>exec block starts a scoped attached service. The child binds loopback port 0, authenticates one exact handshake record with a per-attachment token, and publishes a frozen endpoint only to the current invocation's live environment.ephemeral evalreruns on partial replay and can consume that endpoint without journaling it.Ordinary stdout is forwarded incrementally, while bounded handshake candidates are suppressed. Durable eval rejects exports that collide with live bindings before live execution, replay restoration, or an eval journal append. Ephemeral eval rejects durable collisions but may update an existing ephemeral live binding. Observable process teardown failures become
ServiceTeardownErrorand compose with active execution failures through invocation teardown aggregation.Completed replay does not start the attached service, and workflow execution explicitly denies inherited host service providers.
How it works
The stdout observer retains only bytes that can still match
XMD_SERVICE_READY:at line start. A mismatch releases those bytes immediately; only a real handshake candidate is buffered, with a finite bound. The durable operation validates live-name collisions before either execution or replay restoration, while consuming a matching replay entry so partial replay remains coherent.Review guide
Start with:
packages/cli/src/service-host.tsandpackages/core/tests/ephemeral-service.test.tsThen review:
packages/core/src/live-env.tsandpackages/core/src/eval-handler.tsfor namespace collision rulespackages/durable-streams/effect.tsfor validation before live execution or replay restorationpackages/cli/tests/service-host.test.tsfor byte-level observation, concurrency, cancellation, and teardown aggregationpackages/cli/tests/service-document.test.tsfor real-process supervision and nested lifetimesspecs/executable-mdx-spec.mdfor the durable/live contract and test matrixLook carefully at:
What must stay true
How to verify it
./dist/xmd test smoke-test/attached-service-ping-pong.test.md --component-dir smoke-test --component-dir packages/core/components --rawruns the real two-attachment ping-pong document through the compiled binary and production host adapter.deno test --allow-all packages/cli/tests/service-document.test.tsproves journal isolation, partial/completed replay, supervision, cleanup, and nested lifetime behavior with real processes.deno test --allow-all packages/cli/tests/service-host.test.tsproves incremental handshake observation, concurrent attachments, cancellation, and teardown errors.deno task verifypasses all ten applicable commands concurrently: lint, check, Deno tests, JSR dry-run, Node 22 typecheck/tests, Bun tests, docs, site check, and site build.ping→pong→pingexchange whose endpoints remain live-only across partial replay, live unterminated stdout, split byte forwarding, split/duplicate/bounded handshake-record suppression, partial-replay collisions, teardown error aggregation, post-handshake cancellation and listener release, unexpected exit during projected content, prompt failure cleanup without restart, and nested teardown ordering.Scope
Included
service, andephemeral evalfindFreePortand the Llamafile-specific provider exampleIntentionally unchanged
daemonremains the fixed-configuration subprocess primitive and does not publish an endpoint.New abstractions
Service,ServiceAttachment, andServiceEndpointdefine provider-neutral scoped attachment.The live environment carries invocation-only bindings without entering durable state.
EphemeralEvalgives middleware a scoped, non-journaled eval boundary.Durable-operation validation runs before live execution or replay restoration so a rejected operation creates no result event.
Each new abstraction has multiple concrete uses or a clear justification.
No speculative functionality is included.
Generated or mechanical changes
site/routes/docs/exec-eval.tsxwas formatted with the site formatter after its documentation update.Risks and limitations
127.0.0.1; non-loopback providers are rejected.Scope confirmation