Move instance loading into Effect service#25277
Open
kitlangton wants to merge 8 commits intodevfrom
Open
Conversation
kitlangton
commented
May 1, 2026
| : await project | ||
| .runPromise((svc) => svc.fromDirectory(input.directory)) | ||
| .then(({ project, sandbox }) => ({ | ||
| export interface Store { |
Contributor
Author
There was a problem hiding this comment.
this should probably be called interface right?
kitlangton
commented
May 1, 2026
|
|
||
| const reload = Effect.fn("InstanceStore.reload")(function* (input: LoadInput) { | ||
| const directory = AppFileSystem.resolve(input.directory) | ||
| Log.Default.info("reloading instance", { directory }) |
kitlangton
commented
May 1, 2026
| workspace: WorkspaceContext.workspaceID, | ||
| payload: { | ||
| type: "server.instance.disposed", | ||
| properties: { |
kitlangton
commented
May 1, 2026
| }), | ||
| ) | ||
|
|
||
| const disposeContext = Effect.fn("InstanceStore.disposeContext")(function* (ctx: InstanceContext) { |
e4aedda to
8a63cbe
Compare
kitlangton
commented
May 1, 2026
| export class Service extends Context.Service<Service, Interface>()("@opencode/InstanceStore") {} | ||
|
|
||
| interface Entry { | ||
| readonly deferred: Deferred.Deferred<InstanceContext> |
The manual Deferred slot + uninterruptibleMask + identity check collapses into Effect.cachedWithTTL(_, Duration.zero): concurrent callers share the in-flight execution, and the cache expires on completion so the next call runs fresh. Adds a test pinning the re-arm semantic.
Previously reload always called disposeInstance + emitted server.instance.disposed even when no previous entry existed in the cache, sending a phantom dispose event for an instance that was never loaded.
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
InstanceStorefor instance load, cache, reload, and disposal.InstanceStorein HttpApi instance context middleware so routed requests receiveInstanceRefandWorkspaceRefwithout entering legacy ALS.InstanceStorebehavior and update HttpApi instance-context test wiring.Tests
bun run test:ci test/project/instance.test.tsbun run test:ci test/server/httpapi-instance-context.test.tsbun run test:ci test/effect/instance-state.test.tsgit diff --checkNotes
bun typecheckwas blocked locally after using dependency symlinks from the main checkout by an unrelated@opencode-ai/pluginexport mismatch (WorkspaceAdaptervsWorkspaceAdaptor).