Skip to content

refactor(cli): implement canonical path resolution in TUI and worker commands#16023

Closed
OpeOginni wants to merge 2 commits intoanomalyco:devfrom
OpeOginni:fix/use-canonical-path-opencode-dir
Closed

refactor(cli): implement canonical path resolution in TUI and worker commands#16023
OpeOginni wants to merge 2 commits intoanomalyco:devfrom
OpeOginni:fix/use-canonical-path-opencode-dir

Conversation

@OpeOginni
Copy link
Contributor

@OpeOginni OpeOginni commented Mar 4, 2026

Issue for this PR

Closes #

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Fix inconsistent instance identity for case-variant paths
This fixes a regression where opencode ../dir could open TUI but streaming/UI state became inconsistent (for example, session updates/deletes not reflecting immediately).
Root cause: Instance cache keys used raw directory strings. On macOS case-insensitive filesystems, the same directory can appear with different casing (for example .../PERSONAL/... vs .../Personal/...) depending on caller/source (PWD, cwd, request headers). Those strings are not equal, so OpenCode created multiple logical instances for one physical directory.
What changed

  • Added Filesystem.canonical() in packages/opencode/src/util/filesystem.ts to normalize directory identity.
  • Updated Instance.provide() in packages/opencode/src/project/instance.ts to canonicalize input.directory before:
    • cache lookup,
    • cache insert,
    • project resolution/context creation.

How did you verify your code works?

Tested using bun run dev ../another-dir when inside a folder with an all caps name e.g /TEST

Screenshots / recordings

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions
Copy link
Contributor

github-actions bot commented Mar 4, 2026

The following comment was made by an LLM, it may be inaccurate:

Potential Duplicate Found

PR #15483: fix: symlink path resolution causing duplicate instances (#15482)

Why it's related: This PR also addresses duplicate instance creation caused by path resolution issues. It specifically deals with symlink path resolution creating duplicate instances, which is conceptually similar to PR #16023's fix for path-casing creating duplicate instances on case-insensitive filesystems. Both are addressing the root cause of multiple logical instances being created for the same physical directory.

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