Skip to content

refactor(core): drop redundant reconstructions in rpc and project - #57948

Merged
rekram1-node merged 2 commits into
devfrom
core-integration-rpc-workspace
Oct 22, 2026
Merged

rekram1-node merged 2 commits into
devfrom
core-integration-rpc-workspace

Conversation

@rekram1-node

@rekram1-node rekram1-node commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Rpc and Project in @opencode/core carried redundant schema reconstructions:

  • Rpc reconstructed Location.Ref.make({ directory: ref.directory, workspaceID: ref.workspaceID }) on every event publish and logical event projection even though ref is already a Location.Ref.
  • Project's hgDiscover re-wrapped dotHg: AbsolutePath with AbsolutePath.make(dotHg).

Change

Pass ref and dotHg directly in rpc.ts and project.ts:

 packages/core/src/
 ├── rpc.ts
 │   ├── register -> events.emit
-│   │   └── Location.Ref.make({ directory: ref.directory, workspaceID: ref.workspaceID })
+│   │   └── location: ref
 │   └── logicalEvent
-│       └── Location.Ref.make({ directory: ref.directory, workspaceID: ref.workspaceID })
+│       └── location: ref
 └── project.ts
     └── hgDiscover(dotHg: AbsolutePath)
-        └── const store = AbsolutePath.make(dotHg)
+        └── cached(dotHg) / vcs: { type: "hg", store: dotHg }

Out of scope

  • Behavior changes to RPC event routing or Mercurial discovery.

@opencode-agent opencode-agent Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly a clean no-op cleanup: the rpc.ts and project.ts edits keep the same behaviour, since ref is already a Location.Ref and dotHg is already an AbsolutePath. Core tests and the packages/core type check pass. I also checked import order directly.

Public API: unchanged.

Two concerns, both inline:

  • workspace.ts import cycle. Importing Environment from ./environment/index.js creates a cycle back into workspace.ts. Loading @opencode/core/workspace as the first module now throws ReferenceError: Cannot access 'node' before initialization (environment/environment.ts:40). On the base it loads fine. Current entrypoints load the environment module first, so this is latent, but it depends on import order.
  • Small OAuth behaviour change. It conflicts with the "no behaviour changes" scope.

Comment thread packages/core/src/workspace.ts Outdated
import { make } from "effect/process/ChildProcessSpawner"
import type { EnvironmentDriver } from "./environment/driver.js"
import { execDefaults } from "./environment/exec-defaults.js"
import { Environment } from "./environment/index.js"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This adds an import cycle: workspace.ts → environment/index.js → environment/environment.ts → workspace.ts. environment.ts reads Workspace.node at module top level, so importing @opencode/core/workspace before anything that loads the environment module now throws ReferenceError: Cannot access 'node' before initialization (repro: bun -e 'await import("./src/workspace.ts")' in packages/core; the base loads fine). Two ways to fix it without the cycle: move makeFiles into a module that doesn't pull in environment.ts (e.g. next to execDefaults), or keep the direct execDefaults import here.

if (attempt.authorization.mode === "code" && input.code === undefined) {
return yield* new CodeRequiredError({ attemptID: input.attemptID })
}
if (attempt.completing)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving the missing-code check below the completing check changes behaviour. A code-mode complete without code while another completion is in flight used to fail with CodeRequiredError; now it hits the Effect.die defect. To keep this a pure refactor, keep the missing-code check before the completing check.

@rekram1-node rekram1-node changed the title refactor(core): drop redundant casts and reconstructions in integration, rpc, project, and workspace refactor(core): drop redundant reconstructions in rpc and project Oct 22, 2026
@rekram1-node
rekram1-node merged commit b6c0327 into dev Oct 22, 2026
14 checks passed
@rekram1-node
rekram1-node deleted the core-integration-rpc-workspace branch October 22, 2026 01:05

@opencode-agent opencode-agent Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both earlier points are addressed: the workspace.ts import cycle and the OAuth reorder in integration.ts are reverted, and @opencode/core/workspace now loads on its own again. The remaining rpc.ts/project.ts changes are true no-ops. Core tests and the packages/core type check pass.

Public API: unchanged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant