Skip to content

feat(cloud-agent): sandbox gh token refresh via refresh-session#2450

Merged
tatoalo merged 1 commit into
mainfrom
feat/log-sandbox-credential-refresh
Jun 1, 2026
Merged

feat(cloud-agent): sandbox gh token refresh via refresh-session#2450
tatoalo merged 1 commit into
mainfrom
feat/log-sandbox-credential-refresh

Conversation

@tatoalo
Copy link
Copy Markdown
Contributor

@tatoalo tatoalo commented Jun 1, 2026

Problem

agent-server's process env is frozen at launch, so its in-process tools (e.g. the signed-commit tool) kept
using the stale launch-time token after a rotation and nothing in the run log signalled that a refresh had happened.

Changes

  • resolve the gh token from the live agentsh env file first, falling back to the process env, so in-process tools pick up
    a mid-session rotation without rebuilding the session (signed-commit, claude/codex adapters)
  • short-circuit a credentials-only notification so it's safe mid-turn without rebuilding the session

@tatoalo tatoalo self-assigned this Jun 1, 2026
@tatoalo tatoalo force-pushed the feat/log-sandbox-credential-refresh branch from 4e2e150 to 7fe3cb4 Compare June 1, 2026 11:30
@tatoalo tatoalo marked this pull request as ready for review June 1, 2026 11:43
@tatoalo tatoalo requested a review from a team June 1, 2026 11:43
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Jun 1, 2026

Prompt To Fix All With AI
Fix the following 3 code review issues. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 3
packages/agent/src/utils/github-token.test.ts:15-25
**Prefer parameterised tests for the happy-path token-variable cases**

The two cases that exercise `GH_TOKEN` vs `GITHUB_TOKEN` precedence share the same structure and could be expressed as a single `it.each` table, keeping the distinct-behaviour tests (missing file, live-read, empty value) as individual `it` blocks. This also makes it easy to add new token variable names later without copy-paste.

### Issue 2 of 3
packages/agent/src/utils/github-token.test.ts:1-5
**`resolveGithubToken` — the public API — has no tests**

The test suite only exercises `readGithubTokenFromSandboxEnvFile` directly. `resolveGithubToken` adds an important second layer: it falls back to `readGithubTokenFromEnv()` (process env) when the sandbox file is absent. That fallback branch — the path taken in local/desktop environments — has no coverage, so a regression there (e.g. if the `??` chain were accidentally short-circuited) would go undetected.

### Issue 3 of 3
packages/agent/src/utils/github-token.ts:16
**Synchronous disk read on every tool invocation**

`readFileSync` blocks the Node.js event loop for the duration of the file read. Because `resolveGithubToken()` is called inside the async `signed-commit` handler (and similarly in `claude-agent` / `codex-agent`), every commit triggers a sync I/O operation. For a small `/tmp` file this is unlikely to be a problem in practice, but if token resolution is ever called from a hot path, consider switching to `fs.promises.readFile` and making the function async to stay non-blocking.

Reviews (1): Last reviewed commit: "feat(cloud-agent): sandbox gh token refr..." | Re-trigger Greptile

Comment thread packages/agent/src/utils/github-token.test.ts Outdated
Comment thread packages/agent/src/utils/github-token.test.ts Outdated
Comment thread packages/agent/src/utils/github-token.ts
@tatoalo tatoalo added the Create Release This will trigger a new release label Jun 1, 2026
@tatoalo tatoalo force-pushed the feat/log-sandbox-credential-refresh branch from 7fe3cb4 to 9b0e6bd Compare June 1, 2026 12:39
@tatoalo tatoalo enabled auto-merge (squash) June 1, 2026 12:40
@tatoalo tatoalo merged commit d504c31 into main Jun 1, 2026
18 checks passed
@tatoalo tatoalo deleted the feat/log-sandbox-credential-refresh branch June 1, 2026 12:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Create Release This will trigger a new release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants