perf(autopilot): daemon の read-GraphQL 予算枯渇を緩和(listItems 重複排除 / Bot 分散 / 未観測時抑制)#1128
Open
smalruby3-editor-bot[bot] wants to merge 1 commit into
Open
perf(autopilot): daemon の read-GraphQL 予算枯渇を緩和(listItems 重複排除 / Bot 分散 / 未観測時抑制)#1128smalruby3-editor-bot[bot] wants to merge 1 commit into
smalruby3-editor-bot[bot] wants to merge 1 commit into
Conversation
… refresh read (personal) トークンの GraphQL 予算が枯渇(実測 166/5000・skipLowPriority 発動)する一方 Bot GraphQL と両者の REST(core) は健全という一点集中を緩和する。 - B: listItems の重複排除。tick が取得した item スナップショットを state.itemsCache に保存し、 直後の refreshBoard は十分新しければ gh project item-list(~100 GraphQL pt)を撃ち直さず 再利用する。POST /refresh は forceFetch で最新を取り直す。 - C: 俯瞰ボードの読み取り(listItems キャッシュミス時 / enrichment / head-PR 補完)を project.boardToken()(既定 Bot)へ振り分け、遊んでいる Bot GraphQL 予算と併用して実効予算を 分散する。dispatch 判断の tick 系 read は従来どおり readToken。AUTOPILOT_BOARD_READS=read で復帰。 - D: 未観測時の定期 refreshBoard を抑制。直近 GET /board が無い間は board の read を撃たず、 トラッカー sticky 維持のためアップキープ間隔(既定 30 分)超過時のみ 1 度走らせる。 判断ロジックは phases.js の純粋関数(shouldReuseItemsCache / shouldRefreshBoardPeriodic)に集約し unit テストを追加。I/O は daemon.js に限定。.claude/rules/autopilot/github-api.md を同期。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Summary
autopilot daemon の GitHub API レート枯渇対策。read(個人)トークンの GraphQL 予算だけが
枯渇(実測
166/5000・skipLowPriority発動中)する一方、Bot の GraphQL と両トークンの REST(core) はほぼ満タン、という一点集中を緩和する。
調査で判明した消費源(1 interval サイクル ≈ 300 秒あたり、すべて read トークン):
tick()→listItems(gh project item-list)tick()→getIssueStates(closed 確認・バッチ)refreshBoard→listItems(再取得)refreshBoard→getBoardEnrichment→ ~240 pt/サイクル ≈ 2,880 pt/時(5000 の約 58%)を daemon 自身の定期 read が占め、
POST /refresh/POST /tickや人間の素のgh(read バケットは個人トークン=共有)で容易に枯渇していた。Changes Made
tickが取得した item スナップショットをstate.itemsCacheに保存し、直後に走る
refreshBoardは十分新しければ(既定 interval の半分以内)gh project item-list(~100 GraphQL pt)を撃ち直さず再利用する。
POST /refreshはforceFetch=trueで最新を取り直す。refreshBoardの読み取り(listItems キャッシュミス時 /enrichment / head-PR 補完)を
project.boardToken()(既定 Bot)に回し、遊んでいる Bot GraphQL 予算と併用して実効予算を分散する。dispatch 判断の tick 系 read は従来どおり
readToken。AUTOPILOT_BOARD_READS=readで従来へ戻せる。GET /boardが読まれていない間は定期の board 追従でread を撃たない(
maybeRefreshBoardPeriodic)。トラッカー sticky が古くなり過ぎないよう、アップキープ間隔(既定 30 分)超過時のみ 1 度走らせる。
POST /refresh・POST /tick直後・起動時は常に実行。判断ロジックは
phases.jsの純粋関数(shouldReuseItemsCache/shouldRefreshBoardPeriodic)に集約し、I/O は
daemon.js・トークン選択はproject.jsに限定(レイヤリング不変条件を維持)。効果(概算)
残る board read(enrichment)は C で Bot 側へ。
listItems + getIssueStates(~110 pt/サイクル)だけになる。
Test Coverage
tools/autopilot/test/board-budget.test.js(node:test):shouldReuseItemsCache/shouldRefreshBoardPeriodicの境界(新鮮/期限切れ/forceFetch/未観測/アップキープ/ISO 時刻)を網羅。tools/autopilot/test/daemon.test.jsの GET /board テストにnowを追加(新依存に追随)。cd tools/autopilot && node --test: 419 pass / 1 fail。fail はpackages/admin/.gitignoreのnode_modules symlink 無視チェックで、本 PR と無関係・develop 既存(本 PR は
tools/autopilotと.claude/rulesのみ変更)。Docs
.claude/rules/autopilot/github-api.mdを同期(board 読み取り = Bot の例外、listItems 重複排除、未観測時抑制の規約を追記)。
注意
daemon はコード・settings を起動時スナップショットするため、反映には daemon 再起動が必要
(
update autopilot)。🤖 Generated with Claude Code