Repository navigation
fix(github-app): refresh the agent token early and often - #164
Merged
Merged
Conversation
Installation tokens live 60 minutes, and the refresh job ran every 50 minutes, so a 10-minute launchd deferral or sleep let the token lapse. `github-app-token refresh` now keeps a token with at least 20 minutes left and mints only when less remains, the status file is missing or corrupt, or the last refresh failed. `--force` always mints. The launchd agent and systemd timer check every 5 minutes. Closes #163 Refs furedea/dotfiles#241 Co-Authored-By: Claude Opus 5.5 <[email protected]>
The skip trusted only the state JSON, so a missing, corrupt, or replaced hosts.yml, or a changed App or installation, kept a wrong token for tens of minutes. The state now records the issuing App and installation and a SHA-256 of the token. Refresh keeps the token only when both match, and status reports a missing or mismatched hosts.yml. Records written by older releases lack these fields, so they mint once. Refs #163 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Refs #163 Co-Authored-By: Claude Opus 5.5 <[email protected]>
A token minted for a configured installation was kept after the ID was unset, so refresh never checked whether the App had several installations. The issuer now records whether the installation was configured or resolved as the App's only one, and refresh keeps a token only when the selection mode matches too. Refs #163 Co-Authored-By: Claude Opus 5.5 <[email protected]>
furedea
added a commit
that referenced
this pull request
Oct 21, 2026
🤖 I have created a release *beep* *boop* --- ## [0.9.5](agent-harness-v0.9.4...agent-harness-v0.9.5) (2026-10-20) ### Bug Fixes * **github-app:** refresh the agent token early and often ([#164](#164)) ([46a25fb](46a25fb)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
github-app-token refreshは,次の条件をすべて満たすときだけ発行せずに成功終了する.--forceを付けると常に発行する.hosts.ymlを読め,そのoauth_tokenの SHA-256 が記録と一致するconfigured)」か「App の唯一のインストールを解決(only_installation)」として記録する.ずっと未設定ならそのまま使い続ける.設定済みから未設定へ,またはその逆に変えたら発行し直すので,未設定側では唯一のインストールを解決し直し,インストールが複数あれば失敗する.ringで計算)だけを記録する.発行元と指紋がない旧形式の記録は 1 回だけ発行し直す.statusはhosts.ymlがない場合,壊れている場合,記録と違うトークンを持つ場合,旧形式の記録の場合も失敗を報告する.flowchart LR A[5 分ごと / ログイン時] --> B{--force?} B -->|yes| M[発行] B -->|no| C{状態を読める かつ 前回失敗なし} C -->|no| M C -->|yes| D{発行元が App ID・選び方・インストール ID に一致} D -->|no| M D -->|yes| E{hosts.yml のトークンが記録した指紋と一致} E -->|no| M E -->|yes| F{残り 20 分以上} F -->|no| M F -->|yes| S[発行せず成功終了]src/github_app.rsMINT_BELOW_REMAINING_SECS(20 分)とRefreshRequest.forceを追加.発行元,hosts.ymlの指紋,残り時間がすべて揃うときだけスキップし,statusでhosts.ymlの欠落・不一致・旧形式の記録を報告src/github_app/token_files.rsissuer(app_id,installation_id,selection)とtoken_sha256を追加し,hosts.ymlと照合するhosts_tokenを追加src/cli.rsrefresh --forceを追加nix/agent_github_app_token_module.nixStartIntervalを 300 秒,systemd のOnCalendarを*:0/5に変更し,コメントで「5 分ごとに確認し 20 分未満で発行」を説明tests/agent_github_app_token.nix*:0/50の固定値を 300 秒 /*:0/5に更新README.md,README_ja.md--force,statusの失敗条件を記載docs/adr/0021_refresh_the_agent_token_from_a_github_app.md## Amendment (2026-10-20)を追記受け入れ条件
hosts.ymlがない,壊れている,別のトークンを持つときは発行し,statusが失敗を報告する--forceは残り時間に関係なく発行するdarwin-rebuild switch後,ログに 5 分ごとの実行が残り,トークンが失効しない検証結果
GitHubAppApiを差し替えるテストを先に追加し,red を確認してから実装した.hosts.ymlの欠落・破損・不一致,App 切り替え,インストール切り替え,旧形式の記録の 6 件が redSome(42)→Noneでインストールが複数なら失敗,Some(42)→Noneで唯一のインストール 43 なら発行,None→Some(42)で発行の 3 件が redcargo fmt --check,cargo clippy --all-targets -- -D warnings:okcargo test:全件 ok(lib 114 件を含む)nix flake check:all checks passed(Nix テストは実装前に red を確認)補足
Closes #163
Refs furedea/dotfiles#241
🤖 Generated with Claude Code