Skip to content

fix(haiku): report a refused OAuth token instead of dropping it in silence - #184

Merged
fdaviddpt merged 1 commit into
mainfrom
max/haiku-token-fallback-followup
Jul 26, 2026
Merged

fdaviddpt merged 1 commit into
mainfrom
max/haiku-token-fallback-followup

Conversation

@fdaviddpt

Copy link
Copy Markdown
Contributor

Follow-up to #179 (merged as 0ffa30f). Both items came out of reviewing that change after it landed.

1. The refusal was silent — the PR's own stated goal

_looks_like_token rejected a malformed REMEMBER_OAUTH_TOKEN / haiku.oauth_token and returned nothing. No log, no raise. Reproduced against the merged code:

os.environ["REMEMBER_OAUTH_TOKEN"] = "too short"
_inject_configured_oauth_token({})   # -> {}   no exception, no log line

call_haiku then ran unauthenticated and produced the same confusing 401 the fallback exists to prevent — with a worse origin, since the operator could not tell "rejected" from "never set". README, CHANGELOG and the docstring all said the value "fails at configuration time". Nothing failed.

A refusal is now reported: source and length, never the value. It goes to the daily log, not stderr — save-session.sh captures call-haiku's stderr to a temp file and only echoes it when the call fails, so a warning written there is discarded on exactly the path that matters.

An empty value stays silent. "oauth_token": "" is how the bundled config ships the key, and it reaches this code on every save through the merged config; warning on it would mean a WARNING line per save for every user.

2. A second config reader, free to drift

_configured_oauth_token() hand-rolled its own layer order ($REMEMBER_DIR/config.json, then ~/.remember/config.json), skipping the bundled-defaults layer and ignoring REMEMBER_CONFIG — the merged config lib-memory-dir.sh builds from all three layers and exports before invoking the pipeline. That is the drift #177 tracks.

It now reads REMEMBER_CONFIG first. The raw paths stay as a fallback for direct python use (tests, a manual python3 -m pipeline.shell call) where no shell wrapper ran. The loop continues past a candidate whose key is present-but-empty rather than returning None.

3. Permissions on the merged config

Routing a credential through ${TMPDIR}/remember-config-$$.json raises the stakes on that file's mode. Sourced standalone it is 644:

$ bash -c 'source scripts/lib-memory-dir.sh; stat -f "%Sp" "$REMEMBER_CONFIG"'
-rw-r--r--

Not a live exposure: every entry point (save-session.sh, run-consolidation.sh, and all three hooks) sources resolve-paths.sh first, which sets umask 077 (#68) — measured through the real chain it is already 600. But lib-memory-dir.sh documents itself as sourceable on its own, so it now creates the file under (umask 077; : > ...) before any layer is written into it. jq's >, the jq-free Python merge, and the cp fallback all write into the existing file and keep its mode.

Tests

Six new, in tests/test_haiku.py and tests/test_umask.py:

  • a refused token is logged, and the value itself never reaches the log
  • an empty configured value logs nothing
  • a non-string oauth_token is refused and logged, and does not raise
  • a malformed env token still falls through to a valid config token, and the log names which value was ignored
  • REMEMBER_CONFIG wins over the raw project-layer config.json
  • the merged config is mode 600 with the caller's umask at 022

Three go red against the pre-fix code (test_rejected_token_is_logged_not_silently_dropped, test_non_string_configured_token_is_rejected_and_logged, test_merged_config_wins_over_raw_project_config). test_empty_configured_token_logs_nothing passes both ways by design — it guards against noise this change could have introduced.

Full suite: 717 passed, 41 skipped.

Docs

README, CHANGELOG and config.example.json no longer claim a configuration-time failure; they say the value is refused and reported in the daily log, and never passed to the CLI.

Not changed

A misconfigured token produces the warning twice per save — summarize and NDC are two separate call-haiku processes, so in-process dedup cannot work, and twice is still the right signal.

…lence

Follow-up to #179, both findings from review of the merged change.

A configured `REMEMBER_OAUTH_TOKEN` / `haiku.oauth_token` that failed the
shape check was discarded without a word, so a typo'd or truncated token was
indistinguishable from never having set one: the nested `claude -p` ran
unauthenticated and produced exactly the confusing 401 the fallback exists to
prevent, now with a misleading origin. The docs claimed it "fails at
configuration time" — nothing failed.

A refusal is now logged (source and length, never the value) into the daily
log rather than stderr: `save-session.sh` captures `call-haiku`'s stderr to a
temp file and only echoes it when the call *fails*, so a warning written there
would vanish on the path that matters. An empty value stays silent — that is
how the bundled config ships the key, and it reaches this code on every save.

The config lookup now goes through the merged `REMEMBER_CONFIG` that
lib-memory-dir.sh exports, instead of re-deriving the layer order in Python —
one config resolution, not two free to drift (#177). The raw paths remain as a
fallback for direct python use, where no shell wrapper ran.

And lib-memory-dir.sh now creates that merged file under `umask 077` before
any layer is written into it. Every entry point sources resolve-paths.sh
(umask 077, #68) first, so it is already 600 in practice — but the file
documents itself as sourceable on its own, and its mode must not depend on the
caller now that it can carry a live credential.

Tests: refusal is logged and the value is not; empty stays silent; a non-string
value is refused; a malformed env token still falls through to a valid config
one; the merged config wins over the raw project layer; the merged file is 600
with the caller's umask at 022. Three of them go red against the pre-fix code.

Co-Authored-By: Max <noreply>
@fdaviddpt
fdaviddpt merged commit a310363 into main Jul 26, 2026
12 checks passed
@fdaviddpt
fdaviddpt deleted the max/haiku-token-fallback-followup branch July 26, 2026 20:36
fdaviddpt pushed a commit that referenced this pull request Jul 26, 2026
CHANGELOG only: keep the #182 entry alongside the #184 rewording of the
OAuth-token entry that landed on main.

Co-Authored-By: Max <noreply>
fdaviddpt added a commit that referenced this pull request Jul 29, 2026
)

The condition this fallback exists for — the Claude Code desktop/Agent-SDK
host redacting CLAUDE_CODE_OAUTH_TOKEN from a spawned subprocess — cannot
occur in CI, so the only evidence it works was a manual run reported in a
comment on #179. This writes that procedure down: confirming the negative
precondition, the positive assertion, the malformed-token case (#184), and
what to record so a reader can judge staleness.

Closes #197

Co-authored-by: t <[email protected]>
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.

2 participants