Skip to content

bug(core): empty git repos share the same "global" project ID, causing sessions to leak across unrelated directories #39773

Closed as not planned

Description

@luanweslley77

Description

When opencode runs inside a Git repository that has no commits and no remote, project resolution falls back to project_id = "global" for ALL such repos. This causes session.list to return sessions from completely unrelated directories.

For example, repos at:
/home/user/testing (empty repo)
/home/user/projeto-a (empty repo)
/home/user/Área de trabalho/teste_Engram (empty repo)

all get project_id = "global". When you open /sessions in any of them, you see sessions from all of them mixed together because listByProject filters only by project_id, not by directory.

Expected: each directory/repo should have its own project identity (or at least sessions should be scoped by directory when project_id is global).

Plugins

No response

OpenCode version

1.18.10

Steps to reproduce

  1. mkdir -p /tmp/repo-a /tmp/repo-b
  2. cd /tmp/repo-a && git init && opencode # starts TUI
  3. In another terminal: cd /tmp/repo-b && git init && opencode
  4. Create a session in repo-a (e.g. "session from A")
  5. Create a session in repo-b (e.g. "session from B")
  6. In either TUI, type /sessions
    → Both "session from A" and "session from B" appear

Screenshot and/or share link

No response

Operating System

Fedora Linux 44 (KDE Plasma Desktop Edition) x86_64

Terminal

Konsole

Activity

  1. github-actions commented on Jul 31, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

    These issues all stem from the same root cause in Project.resolve: directories without a distinguishing git remote or root commit fall back to id = "global", causing session leakage across unrelated directories.

  2. github-actions commented on Sep 29, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

  3. Chudesnov commented on Nov 7, 2026

    @Chudesnov

    Reproduced on Windows 11, OpenCode Desktop 2.0.26 — with conditions even weaker than "empty repo": a corrupted .git triggers the same fallback.

    Minimal conditions: git discovery succeeds, but all three identity sources fail — no remote (exit 2), no cached .git/opencode marker, no root commit (rev-parse -q --verify HEAD -> exit 1). A mangled .git (HEAD -> ref: refs/heads/.invalid, no config, no refs) hits this exactly, as does any healthy git init without commits.

    Desktop symptom: the directory gets adopted into the pre-existing global project, so "Add project" opens whichever directory first claimed global's worktree — under that directory's name. Giving the repo a root commit resolves identity correctly.

  4. Chudesnov commented on Nov 7, 2026

    @Chudesnov

    Follow-up, since it affects what a fix must cover: repairing the repo is not sufficient to recover a directory that already squatted on global.

    After giving the repo a remote and a root commit, the desktop kept resolving "Add project" to global across an app restart. Two things keep the stale binding alive: stored session rows (session_v2.project_id = 'global' — instances bootstrap from the stored project instead of re-resolving), and the service's per-directory location cache (GET /api/location still returned id:"global" for a fully valid repo).

    POST /api/location/reload flushed it: the next resolve created the correct remote-derived project, and the projector migrated the affected session out of global automatically. So the fix needs a re-resolution/migration path for already-squatted directories, not just correct new resolves.

    (Correction to my comment above: desktop version is 2.2.6, not 2.0.26 — the updater state file was stale; main.log self-reports 2.2.6.)

  5. mahammedmahieousman commented on Nov 7, 2026

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions