Skip to content

Drop ALS fallbacks from containsPath and workspace routing#25374

Merged
kitlangton merged 1 commit intodevfrom
kit/drop-als-fallbacks
May 2, 2026
Merged

Drop ALS fallbacks from containsPath and workspace routing#25374
kitlangton merged 1 commit intodevfrom
kit/drop-als-fallbacks

Conversation

@kitlangton
Copy link
Copy Markdown
Contributor

@kitlangton kitlangton commented May 2, 2026

Summary

  • `Instance.containsPath` now requires an explicit `InstanceContext` — every existing caller already passes one, so the implicit `Instance.directory` / `Instance.worktree` ALS reads were dead.
  • `WorkspaceRoutingMiddleware.currentDirectory()` read `Instance.directory` in a try/catch, but it runs at the routing phase before any instance is bound. The try always threw, the catch always returned `process.cwd()`. Dead branch removed.

Why

Two of the smaller items from the ALS reader audit. Each one shrinks the reader surface without forcing any caller-side change.

On the `process.cwd()` fallback

The new direct `process.cwd()` matches the legacy Hono `InstanceMiddleware` (server/routes/instance/middleware.ts:11), which uses the same chain: `query("directory") || header("x-opencode-directory") || process.cwd()`. If we want a server-bound root (e.g. `opencode serve --directory /foo` captured into a Context.Reference) we should add it to both routing layers in lock-step — separate change.

Tests

  • `bun run test test/file/path-traversal.test.ts test/project/instance.test.ts test/server/httpapi-instance-context.test.ts` — 30/30 pass
  • `bun run typecheck` — clean

… routing

containsPath now requires an explicit InstanceContext — every existing
caller already passes one. Removes the implicit Instance.directory /
Instance.worktree reads.

WorkspaceRoutingMiddleware's currentDirectory() helper read Instance.directory
in a try/catch, but it runs at the routing phase before any instance is
bound — the try always threw and the catch always returned process.cwd().
Dead branch removed.

Both changes shrink the ALS reader surface by 2 sites.
@kitlangton kitlangton force-pushed the kit/drop-als-fallbacks branch from 2b10c53 to f9a3d0b Compare May 2, 2026 02:58
@kitlangton kitlangton merged commit 1571933 into dev May 2, 2026
10 checks passed
@kitlangton kitlangton deleted the kit/drop-als-fallbacks branch May 2, 2026 03:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant