Repository navigation
Description
Description
Idle sessions get a new time_updated without any new user-visible activity, so they jump to the top of the session list.
I have four sessions that had been idle for 1–2 hours. Around two background-service restarts (serve --service at 11:41:10 and 11:43:26 local time) each of them received a new time_updated, with no corresponding new row in session_message:
last session_message |
new time_updated |
time_idle |
|---|---|---|
| 09:57:04 | 11:43:30 | 09:57:04 |
| 10:06:42 | 11:42:15 | 10:06:42 |
| 10:16:02 | 11:41:22 | 10:16:02 |
| 11:42:58 | 11:43:29 | 11:42:58 |
time_viewed also stayed at the old value, time_suspended is NULL, resume_attempts is 0. For the three older sessions no session_message.time_updated changed either, so the session row itself was written, not a message.
Because GET /api/session sorts by time_updated DESC, the list reorders itself: old conversations reappear at the top after a restart, and with two clients attached (desktop + phone) the order changes while it is being read.
A control request does not reproduce it:
GET /api/session/<id>
time_updated before: 1794615764251
time_updated after: 1794615764251
This only rules out the single-session GET; it does not rule out the session-list endpoint or client event subscriptions.
Steps to reproduce
- Leave a few sessions idle for an hour, no suspended/background work.
- Record
time_updated,time_idle,time_suspendedand the maxseqinsession_message. - Restart the background service (and/or attach a second client).
- Re-read the row:
time_updatedmoved forward while no message was added.
Not yet isolated to a single trigger — cold start vs. client event subscription vs. two clients is still open. The plan is to copy the DB (OPENCODE_DB), stop all clients, do one isolated serve --service with debug logging, and diff session_v2 / session_message / session_inbox; then repeat with one list request, one client, two clients.
Expected Behavior
Recency of an idle session should only change when the session actually receives user-visible activity or an explicit metadata edit. Internal recovery/bookkeeping (inbox, stale execution settling) should not make an old session look recently active.
Actual Behavior
time_updated is rewritten by something other than conversation activity, and the global list reorders.
Additional Context
Relevant code in the 2.3.0 bundle:
- The session projector has a helper equivalent to
updateSession(db, sessionID, {time_updated: event.created}), used forsession.inbox.enqueued,session.step.startedandsession.step.failedwithout usage data, plus move/agent/model/rename/metadata/archive events. SessionRunner.drainrunssettleStaleCompactions/settleStaleToolCalls, but only after its admission checks; their events update message state, notsession_v2.time_updated.resumeSuspendedSessionsnormally selects sessions withtime_suspended IS NOT NULL;claim/release/countResumepreservetime_updated.- Execution start/terminal events preserve
time_updatedand changetime_idleinstead.
So an inbox/step/recovery event is the most plausible writer, but the originating event was not persisted in the event table, so the exact path is unverified.
Related UX note: the session list is global across projects and ordered by time_updated, so any internal timestamp write in one project changes the order seen in every project. Scoping the default list to the current project_id (with an explicit "all projects" mode) would contain the damage.
Activity
opencodejr commentedon Nov 14, 2026
Thanks for the detailed data. I tried to reproduce this on v2.3.0 and couldn't.
What I tried:
readtool call and a backgroundexploresubagent, so it had both a parent and a child session.time_idleset,time_suspendedNULL) and recordedsession_v2.time_updatedand thesession_messagecounts.In every case
time_updatedstayed exactly the same, and no rows were added tosession_message.The only time I saw
time_updatedmove after a restart was when the service was stopped while a turn was still suspended. The turn resumed after the restart and wrote new messages. That might explain your fourth session, whose last message was only about 30 seconds before its newtime_updated. It doesn't explain the three that had been idle for hours.The isolation run you described would help a lot. If you can, please share:
opencode --versionand your OS.eventrows and thesession_inboxrows around the restart, plus the debug log lines from theserve --servicestart (--log-level debug --print-logs).opencode run, imported or moved sessions, plugins or MCP servers.opencode pair) and whether any of them sends messages or changes models or agents when it connects.You can reply here with the details, or edit the issue. If you edit it, please also leave a comment saying you've updated it so we know you're done.
Related: #62655 (asks for a last-message timestamp in the session list, separate from
time.updated).ValDagon commentedon Nov 14, 2026
Isolated: the write lands milliseconds after the client's event stream tears down, not after the restart
I ran the investigation on a copy of the DB and then matched the production log against the row values. The write is not caused by the service restart, not by
GET /api/session, and not by client attach/detach on its own. It lands 0–5 ms after the client'sGET /api/eventsubscription ends, and in 17 of 18 cases 0–4 ms after the abortedPOST /api/rpc/experimental.browser/attachthat follows that stream close — i.e. in the browse-MCP attach handshake between the desktop client and the server.Method
sqlite3 "file:$HOME/.local/share/opencode/opencode.db?mode=ro" ".backup /tmp/oc63920/oc.db"— point-in-time copy, source opened read-only (499 sessions, 23 482 messages). Used.backupinstead of copyingdb+-wal+-shmby hand so the copy is consistent while the live service keeps writing.opencode serve --service --port 49387withOPENCODE_DBpointing at the copy and its ownHOME/XDG_*, so it has its ownservice.json, logs and lock files. The running desktop service (port 49374) was left alone.session_v2(id, time_updated, time_idle, time_viewed, time_suspended, resume_attempts, time_archived),session_message(id, session, type, seq, time_created, time_updated) andsession_inbox, then a diff that reports "time_updated changed without new messages: YES/NO".Factors, one at a time (each is a clean diff, no writes)
serve --serviceboot, zero clientsGET /api/sessionGET /api/session/{id}GET /api/session/{id}/message?limit=5&order=descGET /api/session/active/api/event+ poll loop (session list, session, message), 15 s, then disconnect/api/event+ polls, both disconnectPOST /api/session/{id}/viewwith a valid body ({"idle": …}, HTTP 204)time_vieweddoes not move eitherPOST /api/rpc/experimental.browser/attachwithout a registered clientrpc.unavailablein 37 ms — nothing to abort, no writeSIGTERMshutdown with an SSE client attachedGET /api/event → 200line the real restarts showSo: restart alone, the list endpoint, the detail endpoint, the polling shape, one client, two clients, and client detach on its own are all excluded.
What does write
All 20 sessions in the copy with
time_updatedmore than 60 s past their lastsession_messageand notime_archivedwere checked against the log. 18 fall inside the retained log window, and:/api/eventstream closing (GET /api/eventlogged with status 200 as the stream ends);499on/api/rpc/experimental.browser/attach— the aborted attach that follows that stream close. The 18th (ses_e2abd702…, 2026-11-13T17:43:22Z) is 1 ms after an SSE close but its own499comes 16.7 min later, so the stream close is the common ancestor and the aborted attach is the usual companion.No bump without a stream close, no exceptions.
Your four rows, mapped to concrete sessions (report times are local, log is UTC):
session_messagetime_updatedses_e26af054bffeWiLkByAF6HPIl7ses_e26bc4b84ffenQ5Ee8pgBl5LK2ses_e265a31c6ffeiN11BRMGEO45Juses_e28908eb1ffexunofM4se9m3L3time_idle,time_viewed,time_suspendedandresume_attemptsare untouched in every case, and the write is exactly one column:session_v2.time_updated.That also explains the shape you saw: the two restarts at 10:41:10Z / 10:43:26Z are the client reconnects, and each reconnect tears down the previous browser attach for the sessions that are open in the UI. Two open sessions produce two bumps a second apart (10:43:29.727 and 10:43:30.375); a reconnect a minute later produces a third one (10:42:15.685) with no restart involved.
session_messageis not involved in any of them, and neither is boot recovery — but note that boot recovery does write when a session was genuinely suspended at shutdown: in the first isolated boot the copy still contained one in-flight session, which the new process resumed and wrote three messages into (synthetic "The server restarted while you were working", a system notice, and a failedidle), clearingtime_suspended.time_updatedwas not touched there either.Two corrections to the report
eventtable is empty in this build —select count(*) from eventis 0 on the live DB with 499 sessions. The originating event was not "not persisted for this event"; nothing is ever persisted there, so its absence says nothing about the path.time_updated == time_archived(e.g. a bulkPATCH /api/session/{id} {"archived":true}loop at 11:01:29–11:01:33Z), andGET /api/sessionreturns archived sessions in the same recency-sorted list — in my probe they occupied slots 4–12, ahead of everything else. Even with the silent write fixed, any archive sweep will push those sessions to the top of the global list.Repro note for whoever fixes it
The write needs a real desktop client, because only it registers
experimental.browser; without a registered RPC the endpoint fails immediately withrpc.unavailableand nothing is aborted, which is why a headless server cannot reproduce it. Attach a desktop client (browse MCP configured) to an isolatedserveon a copied DB, open two sessions, restart the service, and diffsession_v2— the two open sessions gettime_updatedstamped at the aborted attach, with no new messages.Suggested direction is the one in the report: the attach handshake must not stamp
session_v2.time_updated, and the default list should be scoped toproject_idand/or ordered by the lastsession_messagerather than by a session column that internal bookkeeping can rewrite.opencodejr commentedon Nov 14, 2026
Seen with a simulated model or a mock server, not a real provider; a maintainer should confirm.
Thanks for isolating this. Your finding about the browser attach was the key. I could reproduce it on v2.3.0, and it still happens on the latest
dev(c9957fd).There was no desktop app here, so the script below uses curl to make the same
experimental.browser/attachcall the desktop's browser pane makes, against a realopencode serve. It then drops the connection. In the test:time_updateddidn't change.time_updatedforward, and the drop moved it forward again.session_v2.permissionchanged as well: the browser allow rules were added on attach and removed on drop. That's why it looked like onlytime_updatedwas written; thepermissioncolumn wasn't in your dump.GET /api/sessionthen reported the session'supdatedas the moment of the drop.Where it comes from in the code: the browser plugin grants and revokes browser access by updating the session's permissions (
syncPermissionsinpackages/plugin-browser/src/connection.ts). The session projector then stores a permissions change together withtime_updated: event.created(packages/core/src/session/projector.ts). So every desktop reconnect that detaches a browser pane makes its session look recently active.The archive point is separate: archiving a session sets
time_updatedon purpose, so ordering or filtering archived sessions in the list would be better as its own feature request.Reproduction script (repro.sh)
Run it:
bash repro.shValDagon commentedon Nov 14, 2026
Confirmed on a real desktop client (v2.3.0, macOS), plus one correction to what I posted above
Everything above was measured with a simulated client: a headless
serveplus SSEand a curl attach, because only a registered
experimental.browserRPC makes theendpoint hang long enough to abort. I have now run the same check on the shipping
desktop app.
Conditions: two sessions open in the app,
opencode service restart, app reopened,read-only snapshots of
session_v2andsession_messagebefore and after(503 sessions in each snapshot).
time_updatedses_e2656f84effeeGyMBufV26qakLses_e25a7d448ffeIuJbRuPa9S3yR1The other 501 sessions did not change. Server log around the write:
Two aborted attaches, matching the two open sessions, and the row is stamped 2 ms
after the second
499. Same shape as the isolated run, this time with the realclient and no mock.
Correction to my own report: the write is not one column.
I wrote "the write is exactly one column:
session_v2.time_updated". That was anartifact of my dump, which did not include
permission— the same reason you gavefor why the original report looked like a single-column write.
For this session:
permission=[{"action":"browser","resource":"*","effect":"allow"},{"action":"skill","resource":"browser","effect":"allow"}]permission=[]No
session_messagerow was added andmax(seq)did not move.time_viewedandtime_idlewere stamped at 14:19:12.637Z, three milliseconds after the pre-restarttime_updated, when the session was opened in the UI — that part is ordinary viewing,not the teardown. My snapshot only carries five columns, so I make no claim about the
remaining
time_*columns here.So
syncPermissionsholds on a live client too: grant on attach, revoke on drop, andthe projector stamps
time_updatedfor the permission change.If a real client counts as confirmation rather than simulation,
status/repro-simulatedis probably too weak a label now — I can't change labels from my side.
On the archive half: agreed that it is a separate request, and it now has its own
report — #63951.
r266-tech commentedon Nov 14, 2026
The projector fix is available in this patch: permission-only updates keep the current
time_updated. It uses an SQL self-assignment; leaving the field out still triggers Drizzle's$onUpdate.The new regression drives the real browser plugin through attach/detach and checks permissions, unchanged timestamps/list order, and no new messages. It fails on unmodified
dev d759c548aaand with the field omitted. All 56 focused tests andbun run checkpass locally on macOS/Bun 1.4.4; no model call or desktop UI is involved.I have 3 open PRs and the submission page enforces a 3-PR limit, so I’m sharing the patch here for review. AI-assisted implementation and validation.
Albert-Deng commentedon Nov 19, 2026
Same root cause reproduced from normal desktop use, with no restart and no curl, on Windows (Desktop 2.3.2).
Steps: open a session that has been idle for several days, change nothing.
Result in session_v2:
Two points that may help prioritize this:
It is not rare. This machine's server log recorded 146 browser/attach responses in a few days (107 with status 400, 39 with 499). Each successful attach and its later abort writes session.permission, so a long-lived tab is bumped at least twice, and often much later when a pending attach finally aborts (observed spans up to about 83 minutes). The write therefore lands while the user is doing nothing.
It is user-visible in the new Recent sidebar: sessions sort by time_updated, so old, untouched conversations keep jumping to the top without any new message.
The linked patch is still only a compare link because of the 3-PR limit. Would a maintainer take it, or is someone else allowed to open the PR with attribution? Happy to test a build on Windows.
r266-tech commentedon Nov 19, 2026
Thanks for the Windows confirmation. Maintainers are welcome to cherry-pick fa3486f058. It applies cleanly to
devatd33b578333. On macOS the recency regression fails on that base, and all 49 browser and session projector tests pass with the patch.If a build includes the fix, the Windows check is whether an old session stays in place in Recent when you open and close it without sending a message. AI-assisted validation.
MordorianGuy commentedon Nov 27, 2026
Confirmed on Windows desktop 2.4.2 — startup tab restore bumps every restored session sequentially
Same root cause, with a user-visible repro path: after an app update + service restart, the desktop client restores previously opened session tabs. Each restored session's browser attach aborts (499) and bumps its
time_updated. 18 sessions idle since Oct 24–Nov 23 (no new messages in any of them) were all bumped within ~50 seconds, so the whole "Recent" list filled up with long-abandoned conversations.Server log correlated 1:1 with
time_updatedvalues fromGET /api/session(local = UTC+3, log timestamps are UTC):(18 attach/499 + bump pairs in total, one per restored session, spaced ~0.5–2 s apart.)
One detail that may matter for the patch: none of the 18 bumped sessions have browser allow rules in their
permissionsafterwards — so in this build the bump happens on a row write where the permission column does not visibly change (consistent with Drizzle$onUpdatefiring on any update to the row, as described above).Environment: opencode desktop 2.4.2 on Windows 10 x64 (the CLI on PATH reports
v2.0.32), SQLite storage, single client. The unmerged patch referenced in this thread covers this write path, so I'm adding this datapoint here instead of opening a duplicate issue.r266-tech commentedon Nov 27, 2026
The patch is now in #65009. Seeing no browser rules after the 499 is consistent with attach granting them and detach revoking them. The PR regression checks the timestamp after each write, including the revoke that restores the original permissions.
If you get a Windows desktop build whose service includes
3d172e3db7, could you repeat the startup restore without sending a message? Comparing one idle tab’stime_updatedbefore shutdown and after restore, along with its position in Recent, would tell us whether the fix covers the desktop path you observed. The 2.4.2 trace gives us the before-patch result.