GeezerVison is showing github.com — v2: sessions with path=NULL (around v1's add_session_path schema change) are missing from project session lists · Issue #51144 · anomalyco/opencode
v2: sessions with path=NULL (around v1's add_session_path schema change) are missing from project session lists #51144DescriptionDescription
Sessions with path = NULL are missing from project session lists after the v1→v2 upgrade, even though their project_id is correct.
v1 began with no path column; 20260428004200_add_session_path added it (default NULL), and v1's inserts still left it NULL for root-level sessions for a while (in our DB: a clean NULL window 2026-04-03→05-05, with every later session writing ''). The v1→v2 importer copies path verbatim, so these rows arrive in session_v2 with path IS NULL. The project-scoped picker sends {project, subpath: ''} and SessionStore.list filters with an exact eq(SessionTable.path, input.subpath) (packages/core/src/session/store.ts:108) — in SQL, NULL = '' is not true, so the rows are excluded. The projector only rewrites the path of the session that triggered a Resolved event; historical rows are never backfilled.
Scope in our DB (opencode 2.0.14, upgraded from 1.18.x): 90 sessions — 88 in one git repo (87 top-level, mostly user-initiated forks, ~1,300 messages total) + 2 in a second repo. All have directory = project.worktree, so the correct value is ''. They are only reachable via "all projects" scope / global search.
This is a different defect from #50980 (where the row is absent from session_v2 entirely) and from the project_id='global' family (#50551, #50800, #50999): here the project attribution is right, only path is null.
Plugins
None relevant (server-side data/filter behavior).
OpenCode version
2.0.14 (affected, by source comparison: 2.0.14–2.0.16; not fixed on latest tag)
Steps to reproduce
- In opencode v1, create sessions in a git repo root during the window where v1 didn't write
path (around the 20260428004200_add_session_path change — e.g. after the path column exists but before v1 started writing '').
- Upgrade to v2.0.14–2.0.16 and open that repo. The import copies
path = NULL into session_v2.
- List sessions in the project: the NULL-path sessions don't appear, though "all projects" scope shows them.
Check your own DB:
SELECT project_id, directory, COUNT(*) FROM session_v2 WHERE path IS NULL GROUP BY 1, 2;
Expected Behavior
Sessions whose directory equals the project worktree should be listed at subpath = '', i.e. NULL should be treated as the empty path (the dev branch already adds this: and(isNull(path), eq(directory, …)) at packages/opencode/src/session/session.ts:970-976).
Related issues
Operating System
Arch Linux, x86_64
Terminal
kitty Activity5h4d0wn1k commented on Sep 26, 2026 Thanks for this — the eq(SessionTable.path, input.subpath) trace at store.ts:108 and the NULL = '' SQL point both check out on my install.
One correction to the scope, from a much larger dataset (opencode 2.0.18, upgraded from 1.18.x; 4,364 rows in session_v2 across 43 projects):
The NULL = '' case is real, but it's the smaller half. eq(path, '') also excludes every row whose path is a real subdirectory, because 'sub/dir' != ''. Measured over top-level sessions in session_v2:
path state |
count |
reachable via the project picker |
path = '' |
16 |
yes |
path IS NULL |
34 |
no |
path = '<subdir>' |
197 |
no |
So 231 of 247 top-level sessions are unreachable through the picker, and only 34 of those are the NULL case. About 85% of the hidden rows are hidden simply because the filter demands '' while their path is an actual directory.
I'd argue this is one defect rather than two. The client sends subpath: '' unconditionally — packages/tui/src/component/dialog-session-list.tsx:70 on v2:
subpath: path.relative(current.project.directory, current.directory).replaceAll("\\", "/"),
path.relative() returns "" when the active directory is the project root, which is the common case. That "" then becomes an equality filter. The NULL semantics you describe are the same filter, just meeting rows whose path happens to be NULL instead of rows whose path is a directory.
The fix is one line, on the client, and it cures both halves at once:
const subpath = path.relative(current.project.directory, current.directory).replaceAll("\\", "/")
// ...
{ project: current.project.id, ...(subpath ? { subpath } : {}) }
A genuine subdirectory still filters, exactly as before.
One caveat on scope: the server guard should stay !== undefined. path = '' legitimately means "a session started at the project root" — Session.create derives it from path.relative(project.directory, location.directory), which is "" when the two match — so relaxing it server-side would remove the ability to filter for root-level sessions.
Two things that may be useful for reproducing:
- The panel's search box is hit by the same filter, because search reuses this request and only adds
search to it. A session that provably exists returns nothing when you type its title.
- A minimal repro that needs no database state at all: compare
GET /api/session?limit=50&order=desc&parentID=null&project=<ID>&subpath=
against the same URL with subpath omitted.
I have this on a branch with regression tests (asserting the parameter is absent at a project root and present in a subdirectory; the root case fails against unfixed v2). Posting the measurement first since it substantially widens the reported scope — I'll open a PR against v2 after this. 5h4d0wn1k commented on Sep 26, 2026 Checked dev and you're right it's already handled there — packages/opencode/src/session/session.ts:967-977 guards the filter on truthiness and adds the nested-subdirectory and NULL branches. That's more complete than the one-liner I was proposing, so I'll drop that.
The gap is that dev is the 1.18.x line (1.18.32 in packages/cli/package.json, which is the current release), while 2.0.x is v2 (2.0.18 there). On v2 the equivalent code is packages/core/src/session/store.ts:108, still the unguarded eq(path, input.subpath), with the TUI sending subpath: unconditionally at packages/tui/src/component/dialog-session-list.tsx:70. The numbers in my earlier comment are measured on 2.0.18, not on 1.18.x.
The two lines have diverged in shape as well as state — dev renamed subpath to path and added a scope field — so this isn't a straight cherry-pick. The semantics do port over though: or, isNull and like are all already imported in v2's store.ts, so the nested and NULL branches can be carried across behind the same truthiness guard.
Is a backport to v2 wanted, or is the 2.0.x line picking these up another way? Happy to prep it either way.
Correction to my own PR (#51514)
My original reasoning was that dev doesn't filter on subpath at all. That was wrong — I had read packages/core/src/session/store.ts on dev, which is the v2 code path and not the one the dev TUI calls. dev does filter, and does so correctly.
5h4d0wn1k commented on Sep 26, 2026 Correction to my own earlier comments on this issue, now that the PR (#51514) is up — it does the
opposite of what I recommended here, so the thread shouldn't be read without this.
- I said the server guard should stay
!== undefined to keep root-only filtering. My reasoning was
right about the mechanism but I had the priority backwards: I could not find any caller of that
filter in the v2 tree that needs root-only — the only one is the session picker, which wants the
whole project at a project root. So the guard is relaxed. The trade is real and I should have said
it earlier: subpath='' no longer selects root-level sessions only.
- I said
dev's nested and NULL branches could be carried across behind the same truthiness guard.
They port mechanically, but the NULL branch is the problem: dev constrains it with
eq(directory, …) and a project-scoped v2 query has no such conjunct, while NULL means "this
column was never populated" (bare ALTER TABLE with no backfill) rather than "at the project root"
— 2 of the 34 top-level NULL rows on my install are below their root. So the PR ports only the
truthiness guard.
The measurement tables in my first comment still stand. opencodejr commented on Oct 28, 2026 Thanks for the detailed report. I can confirm this on 2.0.14, and it still happens on the latest dev (9adc42b).
Steps I used (the script below does all of this):
- Start
opencode serve in a fresh git repo and create two sessions at the repo root.
- Set
path = NULL on one of them in session_v2. This matches the rows the v1 importer leaves behind: project_id and directory stay correct.
GET /api/session?project=<id> returns both sessions.
GET /api/session?project=<id>&subpath= (what the project picker sends) returns only the session with path = ''. The NULL-path one is missing.
As you found, the subpath filter in SessionStore.list matches path exactly, so NULL never equals ''. Nothing back-fills the NULL rows either. Until this is fixed, these sessions can still be reached through the "all projects" view and global search.
Related: #35750 (origin of the NULL path values), #54009 (add_session_path-era migration failure), #50980 and #59517 (sessions missing from session_v2 entirely), #50551 and #58846 (the project_id='global' family).
Reproduction script (repro.sh)
#!/usr/bin/env bash
# Repro for #51144: session_v2 rows with path=NULL are missing from project-scoped session lists.
# Usage: ./repro.sh (uses `opencode` from PATH)
# OC_DEV=/workspace/repo ./repro.sh (runs the CLI from a source checkout)
set -euo pipefail
ROOT=$(mktemp -d /tmp/opencode/repro51144.XXXX)
export HOME=$ROOT/home XDG_DATA_HOME=$ROOT/data XDG_CONFIG_HOME=$ROOT/config XDG_STATE_HOME=$ROOT/state XDG_CACHE_HOME=$ROOT/cache
mkdir -p "$HOME" "$ROOT/proj"
cd "$ROOT/proj" && git init -q && git -c user.email=a@b -c user.name=a commit -q --allow-empty -m init
PORT=${PORT:-47123}
export OPENCODE_SERVER_PASSWORD=repro51144
AUTH=(-u opencode:repro51144)
if [ -n "${OC_DEV:-}" ]; then
OC=(bun --conditions=browser --preload="$OC_DEV/packages/tui/node_modules/@opentui/solid/scripts/preload.js" "$OC_DEV/packages/cli/src/index.ts")
else
OC=(opencode)
fi
"${OC[@]}" --version
"${OC[@]}" serve --hostname 127.0.0.1 --port $PORT >"$ROOT/serve.log" 2>&1 &
PID=$!; trap 'kill $PID 2>/dev/null' EXIT
for i in $(seq 60); do curl -sf "${AUTH[@]}" "http://127.0.0.1:$PORT/api/session" >/dev/null 2>&1 && break; sleep 1; done
API=http://127.0.0.1:$PORT/api
mk() { curl -sf "${AUTH[@]}" -X POST "$API/session" -H 'content-type: application/json' \
-d "{\"title\":\"$1\",\"location\":{\"directory\":\"$ROOT/proj\"}}"; echo; }
mk keep-empty-path; mk will-be-null-path
DB=$(find "$ROOT" -name '*.db' | head -1); echo "DB: $DB"
# Simulate a V1-imported row whose path stayed NULL (directory == project worktree, project_id correct)
bun -e "
const {Database}=require('bun:sqlite');const db=new Database('$DB');
db.run(\"UPDATE session_v2 SET path=NULL WHERE title='will-be-null-path'\");
console.log(db.query('SELECT title, project_id, directory, path FROM session_v2').all());"
PROJECT=$(bun -e "const {Database}=require('bun:sqlite');console.log(new Database('$DB').query('SELECT project_id FROM session_v2 LIMIT 1').get().project_id)")
echo "--- project=$PROJECT (no subpath):"
curl -s "${AUTH[@]}" "$API/session?project=$PROJECT" | grep -o '"title":"[^"]*"' || true
echo "--- project=$PROJECT subpath='' (what the project picker sends):"
curl -s "${AUTH[@]}" "$API/session?project=$PROJECT&subpath=" | grep -o '"title":"[^"]*"' || true
Run it: bash repro.sh
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|