refactor(simulation): scope Drive lifecycle with Effect#36908
Merged
Conversation
# ------------------------ >8 ------------------------ # Do not modify or remove the line above. # Everything below it will be ignored. # # Conflicts: # packages/server/src/routes.ts
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
Make OpenCode Drive simulation lifecycle ownership Effect-native across the backend, TUI frontend, renderer, recording timeline, control WebSockets, manifest loading, and simulated provider boundary.
Drive still exercises the real OpenCode model request/response pipeline. Only the provider network boundary is simulated, through a scoped
SimulatedProviderservice that streams provider response events supplied by Drive.The screenshot path also bundles Commit Mono in compiled binaries and renders block glyphs geometrically so terminal borders remain continuous.
Before / After
Before: simulation state and control servers were split across process-global route/provider registries and imperative WebSocket ownership. Renderer, recording, pending invocation, and socket cleanup could outlive their run. Compiled screenshot rendering depended on runtime font resolution and block glyph side bearings produced visible seams.
After: each simulation run owns its network routes, request log, provider invocations, bounded queues, control servers, renderer, and recording timeline in one Effect scope. Shutdown interrupts control workers and attachments before renderer/timeline finalization. Drive reconnects replay pending invocations, the latest attached controller replaces the previous one, and consumer interruption releases backpressured provider responses. Compiled screenshots load embedded Commit Mono assets on demand and fill block geometry without gaps.
How
packages/simulation/src/backend/simulated-provider.tsdefines the high-level provider stream service and scoped Drive adapter.packages/simulation/src/control-server.tsprovides the shared bounded, sequential JSON-RPC WebSocket server used by backend and frontend control surfaces.packages/simulation/src/backend/network.tsmakes route and log state local to each acquired run and timestamps through EffectClock.packages/simulation/src/backend/openai.tsconverts provider response events into schema-checked OpenAI SSE while preserving the real LLM pipeline.packages/simulation/src/manifest.tsresolves manifests throughConfig,FileSystem, andSchemawith typed failures.packages/simulation/src/frontend/{simulation,renderer,server,actions}.tsscope renderer, timeline, control server, actions, and filesystem writes.packages/tui/src/app.tsxacquires Drive rendering through the application Effect scope.packages/simulation/src/frontend/png.tsembeds Commit Mono and renders█,▀, and▄as exact cell geometry.Scope
uias Drive's low-level protocol-compatible control API.llm.attachwins.Testing
bun test && bun run typecheckinpackages/simulation: 19 tests, 57 assertions.bun run test && bun run typecheckinpackages/server: 9 tests passed after merging currentv2.bun run test && bun run typecheckinpackages/tui: 230 passed, 1 skipped, 0 failed.bun run typecheckinpackages/cli.Demo
This screenshot was produced through the compiled Drive screenshot path with embedded Commit Mono and continuous block edges.
Flow
sequenceDiagram participant Drive participant UI as TUI control server participant Backend as Backend control server participant Provider as SimulatedProvider participant LLM as OpenCode LLM pipeline Drive->>UI: ui action / prompt UI->>LLM: normal application request LLM->>Provider: stream(provider request) Provider-->>Drive: llm.request Drive->>Backend: llm.chunk / llm.finish Backend-->>Provider: bounded response events Provider-->>LLM: provider stream LLM-->>UI: normal session events UI-->>Drive: rendered state / screenshot / recording