Skip to content

Conversation

@notlikejuice
Copy link
Owner

Summary

  • cache GitHub Copilot auth token to disk

Testing

  • npm run lint
  • npm test

https://chatgpt.com/codex/tasks/task_e_684f6dfde9fc8326a69a2fe6d88940e0

Copilot AI review requested due to automatic review settings June 16, 2025 01:29
@notlikejuice notlikejuice merged commit 2bfc886 into main Jun 16, 2025
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds on-disk caching for the GitHub Copilot authentication token to avoid unnecessary network requests.

  • Reads and reuses a valid token from ~/.codex/copilot-token.json if not expired
  • Persists newly fetched tokens with secure file permissions
  • Imports fs, os, and path and defines a constant cache file path
Comments suppressed due to low confidence (2)

codex-cli/src/utils/openai-client.ts:91

  • [nitpick] The variable name disk is ambiguous. Consider renaming it to something like cachedTokenData or diskCache to clarify its purpose.
const disk = JSON.parse(fs.readFileSync(COPILOT_TOKEN_FILE, "utf-8"));

codex-cli/src/utils/openai-client.ts:90

  • The new disk caching logic isn’t covered by existing tests. Please add unit tests that simulate fresh fetch, valid cache reuse, and expired cache scenarios.
try {

return this.copilotToken;
}
try {
const disk = JSON.parse(fs.readFileSync(COPILOT_TOKEN_FILE, "utf-8"));
Copy link

Copilot AI Jun 16, 2025

Choose a reason for hiding this comment

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

This uses synchronous file I/O within an async function, which can block the event loop. Consider using fs.promises.readFile or other async APIs to avoid blocking.

Suggested change
const disk = JSON.parse(fs.readFileSync(COPILOT_TOKEN_FILE, "utf-8"));
const disk = JSON.parse(await fs.promises.readFile(COPILOT_TOKEN_FILE, "utf-8"));

Copilot uses AI. Check for mistakes.
Comment on lines +103 to +104
} catch {
/* ignore */
Copy link

Copilot AI Jun 16, 2025

Choose a reason for hiding this comment

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

Silently swallowing all errors may make debugging difficult. Consider logging or handling specific error cases to aid in diagnosing cache read failures.

Suggested change
} catch {
/* ignore */
} catch (error) {
console.error("Failed to read Copilot token from disk:", error);

Copilot uses AI. Check for mistakes.
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.

2 participants