Repository navigation
fix: cache GitHub CLI tokens for supervised reads - #41
Merged
Merged
Conversation
…y resolving lazily only for authenticated PR/contribution checks. Ledger-only watcher cycles no longer invoke gh. Verified with inactive reconciliation, PR security, and contributions tests
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.
Intent
Firstmate repo, bin/. Filed 2026-09-25 from evidence: every gh call spends about 3.5 s in gh's keyring token lookup on this Mac (the request itself takes 0.4 s), so the five-second per-read cap in bin/fm-contributions.sh fails most reads and 55 contribution records sat stuck with errors on 2026-09-25. Decide a token-caching approach that keeps the token out of plain files (for example resolve gh auth token once per session into the environment of firstmate's own gh calls) or raise the per-read bound. Standing rules: no secret value ever lands in a plain file, log, status line, or chat; the fix must work unattended inside the watcher and its poll scripts, not only in an interactive shell.
What Changed
Risk Assessment
✅ Low: The change is narrowly scoped to in-memory GitHub token caching and process-level credential isolation, with fallback behavior preserved and coverage added for the authenticated paths.
Testing
Live registration and polling completed without token leakage, with durable authenticated results; targeted adversarial tests confirmed custom checks do not receive the token.
Evidence: Live PR registration evidence
Source: Live PR registration evidence
Evidence: Live contribution poll evidence
Source: Live contribution poll evidence
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
🔧 **Review** - 1 issue found → auto-fixed ✅
bin/fm-watch.sh:2152- The watcher exports the resolved GitHub token into its entire process environment before dispatching every registered check. User-authored custom checks and the Relay/tool/mail/HP checks run through this same loop and can read${GH_TOKEN}or pass it onward, although the intent limits the credential to firstmate's own GitHub calls and forbids secret disclosure. Scope the token only to the PR/contribution check processes instead of exporting it globally. Related token setup sites are bin/fm-pr-check.sh:79 and bin/fm-contributions.sh:182, which are process-local and do not create this sibling-check exposure.🔧 Fix applied.
✅ Re-checked - no issues remain.
✅ **Test** - passed
✅ No issues found.
bash tests/fm-contributions.test.shbash tests/fm-pr-check-security.test.shLivebin/fm-pr-check.shregistration against GitHubLivebin/fm-contributions.sh pollagainst GitHub✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.
Acceptance proof
/usr/bin/time -p: withoutGH_TOKEN,gh auth tokentook 2.56 s,gh api usertook 2.83 s, andgh api 'repos/kunchenguid/firstmate/pulls?per_page=1'took 3.10 s; withGH_TOKEN, the same commands took 0.01 s, 0.37 s, and 0.50 s respectively.fm_gh_token_exportkeeps the credential only in process memory, honors an existingGH_TOKENorGITHUB_TOKEN, and never writes or prints its resolved value.GH_TOKEN; the review fix scopes it away from unrelated custom, Relay, tool, mail, and HP checks.ghregressions record only token presence and prove one resolution followed by authenticated reads:bin/fm-test-run.sh tests/fm-contributions.test.shandbin/fm-test-run.sh tests/fm-pr-check-security.test.shpass.bin/fm-lint.shpasses.Red-green evidence
tests/fm-contributions.test.shfailed withcontribution poll did not resolve the keyring token exactly oncebefore the implementation.tests/fm-pr-check-security.test.shfailed withPR registration did not resolve the keyring token exactly oncebefore the implementation.Follow-ups
Built by: pi/openai-codex/gpt-5.6-sol at medium