Repository navigation
Description
Summary
GET /api/project returns 500 with Expected Project.Commands | undefined whenever any row in the project table is persisted with an invalid commands value (NULL, or the legacy [] array shape). The failure is total: the client cannot list or switch projects, and opening a new folder in the desktop app fails with UnexpectedStatus: 500. Creating a session in a directory that has no project row yet persists commands as SQL NULL, so the database poisons itself over time.
Environment
- opencode version: 2.2.5 (desktop app, bundled
cli\2.2.5-x64\opencode-cli.exe;/api/inforeports2.2.5). Note: a second, older CLI build (1.19.5) is also installed on this machine and shares the same database. - OS: Windows 10.0.26300 (win32 x64)
- Terminal: desktop app (Electron renderer); reproduction done over HTTP against the app's own local server
- Shell: cmd.exe / PowerShell (
C:\Windows\system32\cmd.exe) - Install/channel: desktop app release build, version 2.2.5
- Active plugins:
[email protected],./ext/voce
Reproduction
- Pick a directory that has no row in
projectyet (here: an empty temp directory). - Create a session there:
POST /api/sessionwith{"location":{"directory":"<fresh-dir>"},"title":"probe"}→200 - Inspect the database (
C:\Users\<user>\.local\share\opencode\opencode.db):Pre-existing rows created by older builds holdselect id, worktree, commands, typeof(commands) from project where worktree like '%<fresh-dir>%'; -- id | <fresh-dir> | (empty) | null <-- persisted as SQL NULL
'[]'instead. GET /api/project→500Server log:{"_tag":"UnknownError","message":"Server failed to encode its response. Check server logs for details.","ref":"err_…"}level=ERROR message="failed to encode response" kind=Body endpoint=server.project.t route="GET /api/project" reason="Expected Project.Commands | undefined\n at [0][\"commands\"]" http.url=/api/project http.status=500- Repair the data:
→
UPDATE project SET commands='{}' WHERE commands IS NULL OR commands NOT LIKE '{%';
GET /api/projectreturns200with a valid array;GET /api/sessionalso stops returning 500.
The index in the error message moves with the repair, which isolates the field: setting commands='{}' on a single project row moved the failure from at [0]["commands"] to at [1]["commands"].
Expected Behavior
POST /api/session (or any internal "ensure project for directory" path) should persist commands in a shape its own API can read back, i.e. {}, or the reader should treat NULL as "no commands" instead of rejecting the whole response. A single unreadable row should not take down the entire project list endpoint.
Actual Behavior
- New project rows are written with
commands = NULL. - The in-memory project object built during creation omits the key, so the instance that created it keeps working — the 500 only appears once the row is read back from disk (app restart, or a list rebuilt from the database). This makes it look intermittent and very hard to attribute.
- Legacy rows written by older builds contain
[](array), which is also invalid for the current schema, so an upgrade without a data migration breaks the endpoint for every existing project.
Additional Context
- The response schema (
/openapi.json) declaresProject.Commandsas an object with a single optional propertystart, andcommandsis not inProject'srequiredlist — so the encoder accepts an object or an absent value, but rejectsnulland rejects an array. The column is nullabletextwith no default (ALTER TABLE project ADD COLUMN commands text), which is why inserts that do not set it produceNULL. - Two different opencode builds share one database on this machine (desktop 2.2.5 and CLI 1.19.5), so the mixed
[]/NULLcontents also point at missing compatibility between the shapes written by different versions. - Impact seen by the user: after this state was reached, the desktop app showed
Richiesta non riuscita / UnexpectedStatus: 500every time another folder was selected; existing sessions kept working, which made it look like a per-folder permission problem rather than a global project-list failure. - Local workaround applied:
UPDATE project SET commands='{}' WHERE commands IS NULL OR commands NOT LIKE '{%'on 78 rows. No other data was touched.
Activity
opencodejr commentedon Nov 10, 2026
Thanks for the detailed report. I reproduced the 500 on 2.2.5, and it still happens on the latest
dev(57719d7). The cause turned out a little different from what the report suggests:commandsas SQLNULL, but that's handled:GET /api/projectkept returning 200, even after restarting the server.commandsis the legacy array'[]'. With one such row,GET /api/projectreturns 500 withExpected Project.Commands | undefined at [i]["commands"], so that single row takes down the whole list. The v1 data import copiescommandsacross unchecked, which fits your setup with a 1.19.5 CLI on the same database.GET /api/sessionstayed 200 in my runs, so I couldn't confirm that part.The script below reproduces it against
opencode servewith an isolated data directory. YourUPDATE ... SET commands='{}'workaround is a reasonable stopgap until this is addressed.Related: #61025 is the same failure pattern with an unparseable
worktreevalue, and #61028 is a PR that skips projects with an invalid stored worktree when listing.Reproduction script (repro.sh)
Run it:
bash repro.shevan188199-tech commentedon Nov 10, 2026
I'd like to take a look at this one if no one else is on it. Found with AI assistance.
DZH166 commentedon Nov 14, 2026
Working on this. Reproduced the failure mode locally on dev (1fa50dd): a
projectrow whose storedcommandsis a JSON array (the legacy shape the V1 import copies across unchecked) flows throughProject.list/fromRowand the response encode fails withExpected Project.Commands | undefined. Plan: validate the stored value againstProject.Commandsat the read boundary infromRowand treat non-object values as absent (likeNULLrows already are), with a regression test seeding a raw-SQL row. A PR will follow shortly.