Skip to content

fix(client): treat an empty XDG_STATE_HOME as unset - #61288

Open
JorgeRojas2712 wants to merge 2 commits into
anomalyco:devfrom
JorgeRojas2712:fix/client-empty-xdg-state-home
Open

JorgeRojas2712 wants to merge 2 commits into
anomalyco:devfrom
JorgeRojas2712:fix/client-empty-xdg-state-home

Conversation

@JorgeRojas2712

@JorgeRojas2712 JorgeRojas2712 commented Nov 2, 2026 •

Copy link
Copy Markdown

Issue for this PR

Closes #61259

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

fallback() resolved the default service registration with ??, so an empty XDG_STATE_HOME produced the relative path opencode/service.json. The server's roots() uses || and keeps writing to $HOME/.local/state, so a running service was invisible to default client discovery. The XDG spec treats an empty value like an unset one, so I changed the operator to match the server.

How did you verify your code works?

I reproduced it first with a temporary HOME: unset and absolute XDG_STATE_HOME resolved to the same path as the server, empty did not. After the change all three match.

  • bun test in packages/client: 260 pass, 0 fail.
  • bun run typecheck in packages/client: no errors.
  • New packages/client/test/service-fallback.test.ts covers unset, empty and absolute values. The empty case fails on dev without the source change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Added by the opencode bot (AI-generated).

Related: #56708

`fallback()` resolved the registration path with `??` while `roots()` uses
`||`, so an empty `XDG_STATE_HOME` made the client look at the relative
`opencode/service.json` while the server still wrote to
`$HOME/.local/state`. The XDG spec defines the same default for an unset and
an empty value, so a healthy service was invisible to default discovery.

Fixes anomalyco#61259

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The fix works. I ran the #61259 reproduction in both checkouts. On the base, an empty XDG_STATE_HOME makes the client look for the relative path opencode/service.json while the server writes to $HOME/.local/state/opencode/service.json. With this change, the unset, empty and absolute values all resolve to the same path as the server's roots(). In packages/client, the full test suite passes (260/0) and tsc --noEmit is clean. Every caller still uses options.file ?? fallback(), so an explicit file still takes precedence.

Public API: no API changes. The only change in behaviour is that the client now treats an empty XDG_STATE_HOME as unset, as the server and the XDG spec already do (backwards compatible).

One small point: the three-line doc comment isn't needed for a one-character fix and can be dropped to keep the change minimal. Also note that #60683 edits the same fallback() line, so one of the two will need a rebase.

Related: #56708

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The new commit only merges dev and doesn't change this fix. I re-ran the #61259 reproduction on the new head: with XDG_STATE_HOME unset, empty or set to a full path, the client and server resolve the same registration path, and service-fallback.test.ts passes. Public API is unchanged: the only change in behaviour is that the client now treats an empty XDG_STATE_HOME as unset, like the server already does (backwards compatible). Nothing new to raise.

@JorgeRojas2712

Copy link
Copy Markdown
Author

Hola 👋 Este PR está listo para revisión, pero los workflows siguen en action-required desde el 2 de noviembre, así que check, check-test, check-nix y check-bot-scope nunca llegaron a ejecutarse.

El bot de triage ya volvió a correr la reproducción de #61259 sobre el head actual y no encontró nada que objetar. ¿Falta algo más de mi parte, o hace falta que alguien apruebe los workflows para que el PR avance?

This branch has not been deployed

No deployments
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.

client: empty XDG_STATE_HOME prevents local service discovery

1 participant