Skip to content

Age GitHub App tokens with suspend-aware elapsed time - #1209

Closed
eowca wants to merge 4 commits into
mainfrom
lean178/1157-token-cache-clock
Closed

eowca wants to merge 4 commits into
mainfrom
lean178/1157-token-cache-clock

Conversation

@eowca

@eowca eowca commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Age GitHub App tokens with suspend-aware elapsed time

Context and goal

  • Goal: The GitHub App token cache refreshes based on elapsed time that includes suspend.
  • Problem: A backward host clock correction can leave an expired installation token looking fresh in the process cache.
  • Context: The cache uses the existing 3,000-second refresh interval before the credential expires at one hour.

Closes #1157

Acceptance

  • At 3,620 seconds of elapsed time, a wall-clock reading only 2,620 seconds ahead of mint time triggers refresh.
  • Ordinary cache hits reuse fresh credentials. Suspends that cross the existing cache lifetime refresh the token, including a suspend during minting or retry.

Notes

The cache stores installation credentials and may outlive clock adjustments. Keep the existing identity selection, expiry margin and helper behavior. Hosts without a suspend-aware clock skip cache reuse.

  • The rollback replay reused token 1 on the pre-fix code and minted token 2 after the fix. Existing cache-hit and suspend replays also passed.

Base

main @ a4fa169

Validation

Recorded for db8afa5a17ce

  • uv run --group dev ruff check src tests: exit 0
  • uv run --group dev tach check: exit 0
  • uv run --python 3.14 python scripts/check_architecture_docs.py: exit 0
  • scripts/size_budget.sh: exit 0
  • uv run --group dev pytest -q: exit 0

Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

Review

Architecture-Review: unchanged; GitHub identities and credential sources stay the same while cache expiry uses elapsed boot time.
Co-Authored-By: Codex <noreply@openai.com>

@loopzero-feder-positronics loopzero-feder-positronics Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

loopzero primary review by claude on 5a35ab212b1c105e6f5d2525f49cae6edb321d27, 25.0s: approve (0 critical, 0 important, 2 suggestion)

Settings per native call (launch configuration and CLI claims, not backend attestation):

  • Call 1: requested model claude-opus-5-5 (effort medium); CLI-reported model claude-opus-5-5 (effort unknown); configured model claude-opus-5-5 (effort medium)

Native Claude output is retained in the restricted local review receipt.

Comment thread src/loopzero/github.py
return ""
_app_token_cache = (result.stdout.strip(), minted)
token = result.stdout.strip()
if minted is None:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: No test covers the path for hosts without a suspend-aware clock

When _app_token_clock() returns None (no time.CLOCK_BOOTTIME, or clock_gettime raises OSError), app_token() now returns the minted token without caching it. Every later call then runs the helper again. That includes _refresh_publisher_token (cli.py:862), which will always see a different token and call login again. This matches the task notes, but no test pins it down. A later change could start caching (token, None) or comparing against None without any test failing. Smallest fix: add a test that deletes CLOCK_BOOTTIME with monkeypatch.delattr(github.time, 'CLOCK_BOOTTIME', raising=False), then checks that two calls run the helper twice and that _app_token_cache stays empty.

Comment thread tests/test_gh_contract.py
fake.assert_complete()


def test_app_token_expires_after_wall_clock_rollback(tmp_path, monkeypatch):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Rollback regression test is in the gh contract suite instead of next to the other app-token tests

test_gh_contract.py holds strict-fake contract tests. The other app-token cache tests are in tests/test_github.py (test_app_identity_selection_and_cache, test_app_token_age_counts_suspend_during_mint_and_retry). The new test also drops the type hints the neighbouring tests use (tmp_path: Path, monkeypatch: pytest.MonkeyPatch). It also sets CLOCK_BOOTTIME and clock_gettime directly, while the edited tests patch _app_token_clock. Keeping it in the contract file is reasonable, because it exercises the real _app_token_clock lookup. Moving it next to its siblings would make it easier to find and keep the files consistent.

Co-Authored-By: Codex <noreply@openai.com>

@loopzero-feder-positronics loopzero-feder-positronics Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

loopzero delta review by claude on e0558633dcae7ac61da5323913a01dcf1d32cc47, 9.0s: approve (0 critical, 0 important, 0 suggestion)

Settings per native call (launch configuration and CLI claims, not backend attestation):

  • Call 1: requested model claude-opus-5-5 (effort medium); CLI-reported model claude-opus-5-5 (effort unknown); configured model claude-opus-5-5 (effort medium)

Native Claude output is retained in the restricted local review receipt.

@eowca

eowca commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

OD (auth, reserved class): cleared at head e055863. Read the diff (github.py +15/-4). The change only narrows when a cached App token is reused: freshness is measured with CLOCK_BOOTTIME, which counts suspend time and cannot be moved backwards, instead of wall-clock time. Without that clock, each call uses its token only once and does not cache it. Token identity, scope, helper, expiry margin and the 3,000 s interval are unchanged, and no trust boundary moves. All our hosts and CI are Linux, so they keep caching. On a host without CLOCK_BOOTTIME (for example macOS) every call mints a token; acceptable, but note it in the architecture account if it becomes a supported host. Merge through the normal route; this also settles the auth decision on #1157.

@eowca eowca removed the hold label Nov 26, 2026
@eowca
eowca marked this pull request as ready for review November 26, 2026 02:00
@eowca

eowca commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

@Mergifyio queue

@mergify

mergify Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

❌ Left the queue · checks fails with this pull request

2 min in the queue, with no time running CI.

So far

  • ✅ Entered the queue Thu 26 Nov, 02:02 · rule main · triggered by @eowca with the @mergifyio queue command
  • ❌ Checks failed · draft #1362
  • 🚫 Left the queue 02:04 · db8afa5

The failure is in this pull request. It failed tested alone on top of main.

Reason

The merge conditions cannot be satisfied due to failing checks

  • checks

Failing checks:

To get back in the queue

  • Push a fix: the pull request is queued again once its queue conditions match.
  • If the failure is a flake, comment @mergifyio queue to queue it again as it is.

Merge conditions not met when it left the queue

  • any of · required by GitHub repository ruleset rule main: PR only, Mergify queue, existing checks required:
    • check-neutral = checks
    • check-skipped = checks
    • check-success = checks
  • any of · required by GitHub repository ruleset rule main: PR only, Mergify queue, existing checks required:
    • check-neutral = Loop-zero Eligibility
    • check-skipped = Loop-zero Eligibility
    • check-success = Loop-zero Eligibility
1 merge condition met
  • github-review-approved · required by GitHub repository ruleset rule main: PR only, Mergify queue, existing checks required

Times in UTC · dashboard · how the merge queue works

@mergify mergify Bot added the queued label Nov 26, 2026
@eowca

eowca commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

No description provided.

@eowca

eowca commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by #1373. The replacement carries the cleared token-cache change and the same rollback replay within the current test-size budget.

@eowca eowca closed this Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Stop reusing expired GitHub App tokens after a clock rollback

1 participant