fix(httpapi): install Instance ALS for adapter Promise bridge#25417
Merged
kitlangton merged 1 commit intodevfrom May 2, 2026
Merged
fix(httpapi): install Instance ALS for adapter Promise bridge#25417kitlangton merged 1 commit intodevfrom
kitlangton merged 1 commit intodevfrom
Conversation
4b94fc2 to
51734c1
Compare
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.
Summary
The TUI's "New Workspace → Worktree" creates a workspace via
POST /experimental/workspace. On the new Effect HttpApi backend the request returned a 500 with the toast `Failed to create workspace: unknown error`. Schema validation passed (PR #25412), but the inner handler tripped on `InstanceState.context` failing with `No context found for instance`.This PR fixes the underlying bridge-context issue and adds a regression test that reproduces the live failure path against the real built-in `WorktreeAdapter`.
Reproduction
```
POST /experimental/workspace
backend = effect-httpapi
http.response.status_code = 500
exception.type = instance
exception.message = No context found for instance
at use (src/util/local-context.ts:15)
at instance-state.ts:29
at Workspace.create (control-plane/workspace.ts:463)
```
Root Cause
The HttpApi instance-context middleware sets `InstanceRef` on the request fiber via `InstanceStore.provide`. That works for any code that stays inside Effect.
`Workspace.create` calls into the `WorkspaceAdapter` via `Effect.promise(() => adapter.configure(...))`. `WorktreeAdapter.configure` is async JS that does `await loadWorktree()` then `await AppRuntime.runPromise(Worktree.makeWorktreeInfo())`. By the time the nested `AppRuntime.runPromise` reaches `attach()`, the parent Effect fiber is suspended in JS-promise-land:
So `attach()` finds no instance context, the new fiber starts with `InstanceRef = undefined`, and `InstanceState.context` (which falls back to `Instance.current`) throws.
Node's `AsyncLocalStorage` does propagate across `async`/`await`. The fix is to install legacy `Instance.context`/`WorkspaceContext` ALS exactly at the Effect→JS bridge so any nested runtime call inherits it.
Fix
This keeps all bridging in one helper alongside the existing `EffectBridge.make` plumbing and avoids the `WorkspaceRef` ALS gap that would have appeared if I had open-coded the helper twice.
Tests
Why this approach (and not the alternatives)
Followups