anomalyco / anomalyco/opencode

[Bug] Desktop: removing a project does not purge cache, re-adding resurrects stale path

Open
#47,803 1 comment 0 reactions 1 assignee View on GitHub

@Hona is already working on this.

Since Sep 7, 2026.

Dominant language
TypeScript
Stars
209k
Forks
27.5k
Avg merge
7h 2m
Merged PRs (30d)
384

Description

Bug report — Desktop: removing a project does not purge cache, re-adding resurrects stale config

Gerado a partir do caso real 2026-09-07. Repo alvo: anomalyco/opencode (dev, template .github/ISSUE_TEMPLATE/bug-report.yml).

Description

Removing a project in Opencode Desktop (sidebar > remove) does not remove it from the persisted cache. When the user re-adds the project from its new location, Desktop silently resolves back to the old project record and resurrects the old configuration instead of using the new folder.

Concrete case:

  • Old location (deleted/moved): D:\IFBA\20252_TCC\orientador-llm (D:/IFBA/20252_TCC/orientador-llm)
  • New location: D:\IFBA\OCI\vibe-code\orientador-llm (D:/IFBA/OCI/vibe-code/orientador-llm)
  • After remove + re-add, any prompt (including openspec skills) fails before the LLM call with:
level=ERROR run=690f44ca/5fb9df8f/b8feb4ba message=failed
error="PlatformError: NotFound: FileSystem.realPath (D:/IFBA/20252_TCC/orientador-llm)
  (cause: ENOENT: no such file or directory, lstat 'D:\\IFBA\\20252_TCC\\orientador-llm')"
cause="...@opencode-aidesktop/resources/app.asar/..."

followed by:

message="prompt_async failed" sessionID=ses_f83c2ca20ffe4IiHQT04XDX4cg
cause="Die(PlatformError: NotFound: FileSystem.realPath (D:\\IFBA\\20252_TCC\\orientador-llm) ...)"

Test-Path D:\IFBA\20252_TCC\orientador-llm = False. The real directory is D:\IFBA\OCI\vibe-code\orientador-llm (confirmed in the same log at 14:23:49 creating instance).

Plugins

openspec skills (openspec-propose, openspec-explore, openspec-apply-change, openspec-archive-change, openspec-sync-specs) installed in both .claude/skills and .opencode/skills (duplicate-skill WARNs in log, non-fatal). No custom Desktop plugins relevant.

OpenCode version

  • CLI: 1.18.28 (opencode --version)
  • Desktop sessions in log: version=1.18.29 (e.g. ses_f8411b479ffeMkTySSrRPjVa9k, ses_f83c2ca20ffe4IiHQT04XDX4cg)
  • Sidecar: @opencode-aidesktop (Electron, app.asar/out/main/chunks/node-C7Unr5h8.js)

Steps to reproduce

  1. Have a Desktop project at D:\IFBA\20252_TCC\orientador-llm, with sessions.
  2. Move the folder on disk to D:\IFBA\OCI\vibe-code\orientador-llm (old path ceases to exist).
  3. In Desktop, remove the project from the sidebar.
  4. Re-add the project selecting the new folder D:\IFBA\OCI\vibe-code\orientador-llm.
  5. Open a session and send any prompt (e.g. invoke openspec skill).
  6. Observe PlatformError: NotFound ... D:/IFBA/20252_TCC/orientador-llm and prompt_async failed. Log: C:\Users\leandro\.local\share\opencode\log\opencode.log (167k lines, 07/09 14:16–14:23, runs 690f44ca, 5fb9df8f, b8feb4ba).

Screenshot and/or share link

No /share link (prompt never reaches the LLM). Evidence excerpts above are from opencode.log tail. Full log available on request (36 MB).

Operating System

Windows 11 x64, Test-Path PowerShell, project on D:\.

Terminal

  • C:\Program Files\PowerShell\7\pwsh.EXE (PowerShell 7.5.5, also 7.6.2 banner in pty buffer)
  • Desktop pty: pty_ed090b7db001Vn66Ap04zsVDVa

Root cause (found while debugging, to help maintainers)

Three persistence layers keep pointing at the old path after UI removal:

  1. C:\Users\<user>\AppData\Roaming\ai.opencode.desktop\opencode.global.dat → key server:

    {"projects":{"local":[
      {"worktree":"D:\\IFBA\\20252_TCC\\orientador-llm","expanded":true},
      ...
    ]},"lastProject":{"local":"D:\\IFBA\\OCI\\vibe-code\\orientador-llm"}}
    

    The old worktree entry survives UI removal.

  2. C:\Users\<user>\.local\share\opencode\opencode.dbproject id=edca4e2b38f99bd7ac7dfc0078a04fb682afe27f:

    worktree='D:/IFBA/20252_TCC/orientador-llm'
    sandboxes='["D:/IFBA/OCI/vibe-code/orientador-llm"]'
    

    plus project_directory:

    edca... | D:/IFBA/OCI/vibe-code/orientador-llm
    

    The new folder was registered as a sandbox alias of the old project, so re-adding resolves to the same project_id and resurrects old state. session table for this project shows 8 rows split across both directories (4 old + 4 new).

  3. opencode.workspace.RDpcSUZCQVwy.*.dat (5 files) — prefix is base64 of the old path:
    RDpcSUZCQVwyMDI1Ml9UQ0Ncb3JpZW50YWRvci1sbG0D:\IFBA\20252_TCC\orientador-llm.
    Layout sessionTabs keys also embed it: local␀RDpcSUZCQVwyMDI1Ml9UQ0Ncb3JpZW50YWRvci1sbG0/ses_....

Related history in log: WARN duplicate skill name for openspec (.claude/skills vs .opencode/skills) and older ERROR failed to load skill ENOENT in worktree .../quiet-nebula/.opencode/skills/openspec-* (2026-07-09) — same stale-path family.

Suggested fix

  • On project removal in Desktop, purge all three layers (or tombstone with explicit user consent): remove server.projects.local[] entry in opencode.global.dat, delete project + project_directory rows (or cascade/archive sessions), and delete opencode.workspace.<b64-old-path>.*.dat + related layout.sessionTabs keys.
  • On project add, if worktree does not exist on disk (lstat ENOENT), do not silently alias via sandboxes: show a "path not found / moved?" dialog offering Migrate (UPDATE project.worktree, clear sandboxes) vs Remove stale record.
  • Normalize Windows paths (\ vs /, case) before hashing/comparing project_id so D:\IFBA\... and D:/IFBA/... do not fork.
  • Guard FileSystem.realPath at bootstrap: fail fast with actionable UI error ("project folder moved — update or remove") instead of prompt_async failed on every message.
  • Consider a Vacuum / Prune missing projects action in Desktop settings + CLI (opencode project prune --missing).

Workaround used

Close Desktop, backup .dat/.db, delete old worktree object from global.dat, run UPDATE project SET worktree='D:/IFBA/OCI/vibe-code/orientador-llm', sandboxes='[]' WHERE id='edca...', delete stale opencode.workspace.RDpcSUZCQVwy.*.dat. Script saved at D:\IFBA\OCI\vibe-code\orientador-llm\.temp\fix-desktop-workspace.ps1.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.