Skip to content

fix(homeassistant): name the missing token variable - #56

Merged
pedropombeiro merged 1 commit into
mainfrom
fix/name-missing-token-var
Aug 19, 2026
Merged

pedropombeiro merged 1 commit into
mainfrom
fix/name-missing-token-var

Conversation

@pedropombeiro

Copy link
Copy Markdown
Owner

Root cause of the work-laptop failure

haToken used ${HA_OPENCODE_TOKEN}, and that variable was not in the opencode process environment. resolveHaConfig() returned undefined, so the poll never started. The notification arrived, tapping it did nothing, and the agent stayed blocked.

Reproduced locally, including the 5s backstop clear that identified the plugin as never having consumed the helper:

06:53:38 WEBHOOK waiting reason=question id=que_018cc03b70016m0uKDwckjc6GQ
         que_018cc…: not polling because haToken references HA_OPENCODE_TOKEN,
                     which is not set in the opencode process environment
06:54:22 HA WROTE RESPONSE -> question:que_018cc…:1
06:54:27 HA BACKSTOP CLEARED (plugin was too slow)

The 0.7.2 tracing did its job — it pointed straight at the config — but its message lumped three unrelated causes into one line.

Changes

Name the exact missing variable instead of a generic "config unavailable":

Situation Message
haApiUrl absent haApiUrl is not set
haToken absent haToken is not set
env var unset haToken references HA_OPENCODE_TOKEN, which is not set in the opencode process environment
several unset lists all of them
expands to empty haToken resolved to an empty value

Report partial expansion. ${A}${B} with only B unset previously resolved non-empty, so the plugin silently sent a truncated token that Home Assistant would reject. That now reports …so the token is incomplete while still attempting the poll.

README documents that expansion reads the opencode process environment rather than an interactive shell, that opencode does not read .env files, and that a mise [env] entry does reach the process.

Verification

Two findings established by testing rather than assumption:

  • opencode does not read .env — a .env var was invisible to a probe plugin while a shell-exported one was visible.
  • mise [env] does reach opencode plugins — verified with the same probe.

Also verified:

  • All six config states produce the correct message (unit harness).
  • The healthy path is unaffected: reply accepted (HTTP 200).
  • The failing path reproduced in a real opencode process at production timing, with the diagnostic appearing in the real log.

mise run typecheck, lint, build all pass.

Note

The user's work machine is already fixed by configuration; no code change was required to unblock it. This PR is about making the next occurrence self-diagnosing.

The work laptop reported only that the Home Assistant config was
unavailable, which lumped together three unrelated causes and left the
real one to guesswork.

When haToken uses ${ENV_VAR} expansion and the variable is missing from
the opencode process environment, the log now names that variable. A
token that only partly expands is also reported, since it would otherwise
be sent truncated and rejected by Home Assistant.

Documents that expansion reads the opencode process environment rather
than an interactive shell, that opencode does not read .env files, and
that a mise [env] entry does reach the process. Without this the failure
is invisible: the notification arrives and tapping it does nothing.
@pedropombeiro
pedropombeiro merged commit 9e559f3 into main Aug 19, 2026
2 checks passed
@pedropombeiro
pedropombeiro deleted the fix/name-missing-token-var branch August 19, 2026 07:04
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.

1 participant