Skip to content

Handle windows with no folder in the session lookup - #8130

Merged
code-asher merged 1 commit into
coder:mainfrom
b84330808:fix-session-lookup-folderless-window
Dec 2, 2026
Merged

code-asher merged 1 commit into
coder:mainfrom
b84330808:fix-session-lookup-folderless-window

Conversation

@b84330808

Copy link
Copy Markdown
Contributor

Fixes #6977

When a window has no folder open, its extension host still registers itself with the session server, but without a workspace (workspace is undefined in the extension host for an empty window, so it drops out of the JSON). As soon as there is a second session, sorting the candidates calls entry.workspace.folders on that entry and throws, so GET /session returns 500 and code-server <file> / code-server -r <file> from a shell outside the integrated terminal fails with Unexpected status code: 500. The lookup throws before it gets to pruning dead sockets, so the bad entry never goes away, which matches "works in fresh sessions, breaks after a while, restarting fixes it" from the issue.

This treats a session without a workspace as not matching any file, so it is still used as a fallback like any other window.

Added a test for the candidate sort and one for --reuse-window with a folderless window registered next to a folder window. Both fail without the change (TypeError: Cannot read properties of undefined (reading 'folders') and Unexpected status code: 500). The unit suite passes on Ubuntu (426 tests, GitHub Actions on my fork). I haven't run it against a full build.

Code registers a window that has no folder open without a workspace, so
once one is registered alongside another window, every session lookup
threw and `code-server <file>` from an outside shell failed with
"Unexpected status code: 500" until code-server was restarted.

Fixes coder#6977
@b84330808
b84330808 requested a review from a team as a code owner November 14, 2026 21:31

@code-asher code-asher left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good find, thank you!

@code-asher
code-asher merged commit fd72fd8 into coder:main Dec 2, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

code-server -r filename results 'error Unexpected status code: 500'

2 participants