8000 fix(ghcli): refresh login with token by opsmon · Pull Request #259 · aenix-io/aeman · GitHub
[go: up one dir, main page]

Skip to content

fix(ghcli): refresh login with token - #259

Merged
kvaps merged 1 commit into
aenix-io:mainfrom
opsmon:issue-186
Nov 2, 2026
Merged

kvaps merged 1 commit into
aenix-io:mainfrom
opsmon:issue-186

Conversation

@opsmon
@opsmon opsmon commented Sep 28, 2026
Copy link
Copy Markdown
Contributor

fix(ghcli): refresh login with token

Summary

  • move the cached GitHub login from package-level state into each TokenSource
  • invalidate the cached login when the five-minute token refresh returns a different token
  • implement TokenAndLogin so a token and its owner are returned from one locked view of the source
  • keep unanswered identity lookups scoped to their source and token
  • update the behavior matrix and add regression coverage for account switches and independent sources

Problem

internal/ghcli refreshed the token every five minutes but cached the corresponding GitHub login for the lifetime of the process. After gh auth login switched accounts, a long-running server could therefore push with the new credential while attributing commits to the previous account. The package-level login cache could also leak an identity between separate credential sources.

Solution

The token and identity caches now have the same owner and lifecycle. Login reads the current token before trusting its cached identity, and a changed token clears that identity so gh api user is queried again. Independent TokenSource instances no longer share login state.

TokenSource also implements forge.Credential, allowing callers to obtain the token and login together without a refresh splitting the pair across credentials.

Testing

  • go test -race ./internal/ghcli ./cmd/aeman ./docs/design
  • golangci-lint run ./internal/ghcli/...
  • git diff --check

The full repository checks currently report unrelated existing failures:

  • make test: date-sensitive September/October assertions in pkg/boardservice
  • make lint: existing gosec G703 finding in cmd/aeman/service.go:651

Fixes #186

Keep the authenticated login in each TokenSource and invalidate it when gh returns a different token. Return token and login as one credential pair so independent sources and account switches cannot reuse a process-wide identity.

Fixes aenix-io#186

Assisted-by: LLM

Signed-off-by: frolov.so <opsmon.sh@yandex.com>
@kvaps
kvaps merged commit bc4da89 into aenix-io:main Nov 2, 2026
2 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.

The gh credential and the identity it belongs to expire on different clocks

2 participants

0