refactor(opencode): retire bus automation facades - #1453
Conversation
|
Warning Review limit reached
More reviews will be available in 1 minute and 49 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits. 🚦 How do rate limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (33)
📝 WalkthroughWalkthroughRemoves the static ChangesBus Facade Removal and Caller Migration
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 9
🧹 Nitpick comments (1)
packages/opencode/src/server/routes/instance/httpapi/handlers/session.ts (1)
149-155: ⚡ Quick winUse a named
Effect.fnfor this helper effect.
publishPromptAsyncErroris a traced effect boundary inpackages/opencode/**/*.ts; define it withEffect.fn("Session.publishPromptAsyncError")instead of a plain function returningEffect.gen.As per coding guidelines,
packages/opencode/**/*.ts: “UseEffect.fn("Domain.method")for named/traced effects andEffect.fnUntracedfor internal helpers.”🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/opencode/src/server/routes/instance/httpapi/handlers/session.ts` around lines 149 - 155, The helper function handling the prompt async error publishing should be defined using Effect.fn for proper tracing and naming rather than as a plain function returning Effect.gen. Refactor the function that logs the error and publishes the SessionNs.Event.Error event to use Effect.fn("Session.publishPromptAsyncError") as the named effect definition, which will enable automatic tracing while maintaining the same behavior of logging and publishing the error with the sessionID and error details.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/opencode/src/automation/index.ts`:
- Around line 276-291: The registerDisposer callback at lines 277-279 only
deletes the state map entry without cleaning up active automation runs. You need
to enhance this callback to first retrieve the state for the given directory
using activeStates.get(), then iterate through all AbortControllers in the
activeRuns map within that state and call abort() on each one to cancel pending
work, and only then delete the state entry from activeStates. This ensures that
no work continues running after the instance is disposed and prevents orphaned
operations from keeping resources alive.
In `@packages/opencode/src/bus/index.ts`:
- Around line 87-110: The GlobalBus.emit call is currently inside the try block,
so errors thrown by its listeners get caught by the catch block that's meant to
handle only missing instance errors. This masks actual bus listener failures.
Move the GlobalBus.emit call that publishes the event with directory, project,
and workspace information outside of the try-catch block so it executes after
the catch block completes. Keep the event envelope construction (directory,
context, workspace variable assignments) inside the try block, but defer the
emit. The fallback GlobalBus.emit with directory "global" should remain in the
catch block as the error handler for missing instances.
In `@packages/opencode/src/config/command.ts`:
- Around line 32-34: The publishSessionError call in the reportLoadError
function is using void to ignore the promise, which can result in unhandled
rejections if the function fails. Add a catch handler to the publishSessionError
promise to explicitly handle any potential rejections, ensuring the error is
logged or handled gracefully rather than surfacing as an unhandled promise
rejection.
In `@packages/opencode/src/file/watcher.ts`:
- Around line 626-628: The fire-and-forget publish calls using void on lines
626-628 and 777-781 can result in unhandled promise rejections if the publish
operation fails. Instead of using void to suppress the promises, attach a
.catch() handler to each publish call to log any failures, similar to how the
rescan paths already handle publish failures. This applies to all three event
type handlers (create, update, delete) in both locations where they are used.
In `@packages/opencode/src/lsp/client.ts`:
- Around line 67-69: The `Effect.runPromise` call that publishes
`Event.Diagnostics` via `options.bus.publish` is being discarded with `void`,
which means any rejection from this promise will become an unhandled rejection
since it's being called from an LSP notification callback. Instead of using
`void` to discard the promise, attach a `.catch()` handler to the promise
returned by `Effect.runPromise` to log any errors that occur during the publish
operation, ensuring all rejections are properly caught and logged rather than
becoming unhandled promise rejections.
In `@packages/opencode/src/session/llm.ts`:
- Around line 303-307: The callback function inside bus.subscribeCallback for
Permission.Event.Replied is not doing anything with evt.properties.reply - it's
just reading the value without forwarding it. This is a no-op that prevents the
approval from being properly completed. Modify the callback to actually forward
or resolve the reply value (evt.properties.reply) to complete the approval
handler instead of discarding it. The reply should be passed to whatever
mechanism is waiting for the approval response in this async flow.
In `@packages/opencode/test/server/automation-routes.test.ts`:
- Around line 29-38: The subscribeAutomationEvent function filters GlobalBus
events only by payload.type, which allows events from other test instances to
interfere with the current test's event stream, causing flaky assertions. Modify
the listener callback to also check for an instance or scope identifier in
addition to the type check before invoking the callback. This requires adding an
instance-scoped identifier to the event filtering logic in the listener function
that processes events from GlobalBus.on, ensuring that only events from the
current test instance are processed and preventing cross-test event
contamination.
In `@packages/opencode/test/server/automation-runner.test.ts`:
- Around line 27-37: The subscribeAutomationEvent function's internal listener
only filters events by type, which allows same-type events from other tests to
trigger the callback and cause test pollution. Enhance the listener's filtering
logic to include additional scoping criteria such as directory, project,
workspace, or add an explicit predicate parameter to the function signature that
can be used to filter events before the callback is invoked. This scoping check
should be performed in the listener before calling the callback to ensure only
events relevant to the current test trigger the handler.
In `@packages/opencode/test/tool/automate-manage.test.ts`:
- Around line 23-33: The subscribeAutomationEvent function currently filters
events only by payload.type, which is insufficient for a process-wide GlobalBus
emitter and can incorrectly capture unrelated events from other tests. Enhance
the event filtering logic in the listener function to include additional scope
checks such as directory, project, or workspace identifiers from the event
payload, or alternatively add a required predicate parameter to the function
signature that allows callers to provide custom filtering logic before the
callback is dispatched.
---
Nitpick comments:
In `@packages/opencode/src/server/routes/instance/httpapi/handlers/session.ts`:
- Around line 149-155: The helper function handling the prompt async error
publishing should be defined using Effect.fn for proper tracing and naming
rather than as a plain function returning Effect.gen. Refactor the function that
logs the error and publishes the SessionNs.Event.Error event to use
Effect.fn("Session.publishPromptAsyncError") as the named effect definition,
which will enable automatic tracing while maintaining the same behavior of
logging and publishing the error with the sessionID and error details.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 605c48ee-f637-4272-a23c-20d3817c17af
📒 Files selected for processing (33)
packages/opencode/src/automation/index.tspackages/opencode/src/bus/index.tspackages/opencode/src/cli/cmd/github.tspackages/opencode/src/cli/cmd/mcp.tspackages/opencode/src/cli/upgrade.tspackages/opencode/src/config/agent.tspackages/opencode/src/config/command.tspackages/opencode/src/file/watcher.tspackages/opencode/src/lsp/client.tspackages/opencode/src/lsp/index.tspackages/opencode/src/lsp/server.tspackages/opencode/src/server/instance/event.tspackages/opencode/src/server/routes/instance/httpapi/handlers/session.tspackages/opencode/src/session/llm.tspackages/opencode/src/sync/index.tspackages/opencode/test/bus/bus-integration.test.tspackages/opencode/test/bus/bus.test.tspackages/opencode/test/effect/legacy-boundaries.test.tspackages/opencode/test/file/watcher.test.tspackages/opencode/test/lib/bus.tspackages/opencode/test/lsp/client.test.tspackages/opencode/test/mcp/lifecycle.test.tspackages/opencode/test/mcp/oauth-browser.test.tspackages/opencode/test/permission/next.test.tspackages/opencode/test/pty/pty-session.test.tspackages/opencode/test/server/automation-routes.test.tspackages/opencode/test/server/automation-runner.test.tspackages/opencode/test/server/automation-scheduler.test.tspackages/opencode/test/server/event-stream-routes.test.tspackages/opencode/test/session/session.test.tspackages/opencode/test/session/turn-change-aggregate.test.tspackages/opencode/test/sync/index.test.tspackages/opencode/test/tool/automate-manage.test.ts
0a1a1ac to
a4f5d67
Compare
2580e1d to
7482e02
Compare
7482e02 to
42f87a0
Compare
Summary
Retire the Bus and Automation per-service runtime facades and move direct callers to injected services, AppRuntime-owned boundaries, or explicit scoped event publication.
Why
Related to #936. Bus and Automation still carried service-owned runtime bridges (
makeRuntime(Service, layer)/automationRuntime) after the broader Effect graph had moved toAppRuntime. This PR removes those compatibility runtimes and adds a guardrail so they cannot quietly return.Related Issue
Related to #936
Human Review Status
Pending
Review Focus
Please focus on Bus event semantics, Automation active-run state ownership, and the small caller migrations that previously depended on synchronous callback facades.
Risk Notes
Bus callback subscriptions now go through caller-owned service boundaries rather than namespace facades. Automation direct publish helpers keep their Promise-shaped public API while emitting scoped GlobalBus events without a per-service runtime. No UI, dependency, generated output, Worktree adaptor, Hono route source, OpenAPI, or SDK files changed.
Fresh-eye result: no P0/P1 findings. One P2 was found and fixed before PR creation:
Automation.publishDefinitionUpdated/publishRunUpdatedshould preserve their Promise-shaped helper API even though the runtime facade is gone.Skipped checklist items: visible UI/copy check does not apply because this is a backend Effect/runtime cleanup.
How To Verify
Screenshots or Recordings
Not applicable: no visible UI changes.
Checklist
bug,enhancement,task,documentation. Type labels are author-added; the labeler bot does NOT assign them. Add the label in the GitHub UI, then tick this.app,ui,platform,harness,ci. The labeler bot assigns these on PR open based on changed paths. Confirm the bot's choice (or override if wrong), then tick this.P0,P1,P2,P3. The priority-triage bot suggests one on PR open. Confirm or override, then tick this.Pending,Approved by @<reviewer>, orNot required: <reason>(default isPending; "not required" is restricted to bot-authored low-risk PRs).dev, and my PR title and commit messages use Conventional Commits in English.Summary by CodeRabbit
Release Notes
Bus.Servicewith Effect-based wiring across automation, LSP, file watching, and session services.