Skip to content

fix: read wrapped token refresh replies and report rejected refreshes - #30

Merged
kongesque merged 1 commit into
mainfrom
fix/token-refresh-envelope
Nov 16, 2026
Merged

kongesque merged 1 commit into
mainfrom
fix/token-refresh-envelope

Conversation

@kongesque

@kongesque kongesque commented Nov 9, 2026 •

Copy link
Copy Markdown
Owner

Summary

Issue #29: sessions stopped working 3–4 days after QR login. Every later refresh got HTTP 400 with gateway code 10201 until line login, and the CLI said "check your connection" (remote_failed).

  • Refresh reply shape. RefreshAccessTokenContext parsed /api/auth/tokenRefresh only as a bare TokenV3IssueResult. Every other gateway call here unwraps {code, message, data}, and Beeper decodes a wrapped refresh reply (beeper/line#260, 2026-10-07). Read as bare, a wrapped success has no access token, so the CLI saved nothing after LINE may already have rotated the refresh token. That matches every later refresh being rejected. Both shapes are now accepted, and an unreadable success gets the existing response_envelope diagnostic instead of an unlabelled error.
  • Rejected refresh. HTTP 400/401/403 and HTTP 200 error envelopes from tokenRefresh are now a refresh rejection (line.IsRefreshRejected), which counts as an authentication error:
    • Commands say "LINE rejected the token refresh; run line login to sign in again".
    • JSON uses the existing authentication_failed code and keeps the gateway diagnostic (HTTP status, gateway code).
    • line doctor fails line_auth with "Run line login."
    • line watch stops instead of retrying the rejected token forever.
    • It is not retried and does not invalidate the session, per AGENTS.md; forced-logout codes still invalidate as before. Only the refresh call produces this error, so other endpoints are unaffected.
  • Docs. The token refresh section of the CLI guide (en/ja/th/zh-TW) no longer promises seven days. JSON.md and SESSION.md (new dated issue bug: 🐛 Token refresh rejected (HTTP 400, gateway 10201) 3–4 days after QR login, well before the ~7-day boundary #29 section) are updated, with a changelog entry under Unreleased.

Refs #29.

Proven and inferred

Validation

  • Passed on macOS arm64 with Go 1.27.3: ./build.sh, ./bin/line help, go test -race ./internal/... ./cmd/line ./pkg/line/... ./pkg/e2ee, goimports, gofmt, go vet, staticcheck, ./scripts/check-toolchain.sh, and git diff --check.
  • New tests run the real client against a synthetic gateway: both reply shapes, malformed replies, the 400/10201 reply through the session layer, whoami (human and JSON), doctor, and watch. The new pkg/line and session tests fail on the previous client.go.
  • Not run locally: the ./pkg and ./pkg/ltsm suites (untouched), ./scripts/security-check.sh, and the Linux Secret Service and Windows DPAPI suites (CI).
  • Live test passed past the old failure point: QR login on 2026-11-09 at 09:46 UTC with this build, then a read-only line whoami roughly every 6 hours that logged only the outcome. As of 2026-11-16 04:13 UTC (162 hours, about 6.8 days): 31 checks, 0 failures, all on this build. v0.6.0 failed around day 3–4; the checks at 84, 91 and 98 hours passed. The log records command success, not individual refreshes, so no refresh reply was captured.
  • Translations haven't had native-speaker review.

Other gateway calls reply with a {code, message, data} envelope, and
beeper/line#260 decodes a wrapped token refresh reply. The CLI parsed the
refresh reply only as a bare token, so a wrapped success had no access
token: nothing was saved after LINE may already have rotated the refresh
token, and every later refresh was rejected (HTTP 400, gateway code
10201) until line login. Accept both shapes, and label an unreadable
success with the response_envelope diagnostic.

Treat HTTP 400/401/403 and HTTP 200 error envelopes from tokenRefresh as
a refresh rejection: an authentication error that asks for line login
(JSON authentication_failed) instead of "check your connection". It is
not retried and does not invalidate the session; forced-logout codes
still do. line doctor reports it, and line watch stops instead of
retrying the rejected token forever.

Stop documenting a seven-day refresh interval in the CLI guides.

Refs #29
@kongesque
kongesque marked this pull request as ready for review November 16, 2026 04:29
@kongesque
kongesque merged commit bc1d44e into main Nov 16, 2026
8 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.

1 participant