Skip to content

fix: tolerate undecodable .credentials.json during store-backed resume - #1566

Open
doge-th wants to merge 1 commit into
anthropics:mainfrom
doge-th:fix/resume-tolerate-undecodable-credentials
Open

doge-th wants to merge 1 commit into
anthropics:mainfrom
doge-th:fix/resume-tolerate-undecodable-credentials

Conversation

@doge-th

@doge-th doge-th commented Nov 21, 2026

Copy link
Copy Markdown

Summary

Fixes #1521.

_copy_auth_files decoded .credentials.json with strict UTF-8 and no error handling, unconditionally and before the env-API-key branch. A single invalid byte in the file — e.g. a truncated write from an interrupted login — raised UnicodeDecodeError and aborted the resume before the CLI was even spawned, even when the caller authenticates via ANTHROPIC_API_KEY and never reads that file.

The change treats an undecodable credentials file like a missing one: skip it and log a warning, matching the best-effort policy of the neighbouring seed-file helpers (_read_if_present, _strip_settings_for_resume).

  • No credentials file is seeded in that case, so the subprocess falls back to env/API-key auth (or the Keychain fallback, which now overrides creds_json as before).
  • Other seed files are unaffected.

Test plan

  • Added TestHappyPath::test_corrupt_credentials_file_does_not_abort_resume: seeding an invalid-UTF-8 .credentials.json no longer aborts materialization, no credentials file is written, and the transcript is still materialized.
  • Verified the new test fails on unpatched main with UnicodeDecodeError at session_resume.py:345 (the exact line from the issue) and passes with the fix.
  • pytest tests/: 1757 passed, 6 skipped.
  • ruff check, ruff format --check, mypy src/ scripts/ all clean.

`_copy_auth_files` decoded .credentials.json with strict UTF-8 and no
error handling, so a single invalid byte — e.g. a truncated write from
an interrupted login — raised UnicodeDecodeError and aborted the resume
before the CLI was even spawned, even when the caller authenticates via
ANTHROPIC_API_KEY and never needs the file.

Treat an undecodable credentials file like a missing one: skip it and
log a warning, matching the best-effort policy of the neighbouring
seed-file helpers.

Fixes anthropics#1521

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.

Corrupt .credentials.json aborts store-backed resume even with API-key auth

1 participant