Skip to content
This repository was archived by the owner on Aug 6, 2026. It is now read-only.

fix(cloud-agent): fall back to legacy env file for github token - #3653

Closed
tatoalo wants to merge 1 commit into
mainfrom
posthog-code/signed-commit-legacy-token-fallback
Closed

fix(cloud-agent): fall back to legacy env file for github token#3653
tatoalo wants to merge 1 commit into
mainfrom
posthog-code/signed-commit-legacy-token-fallback

Conversation

@tatoalo

@tatoalo tatoalo commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Problem

Follow-up to #3652 (already merged), which pointed the in-sandbox GitHub token reader at the backend's dedicated credential file. A review comment flagged a mixed-version rollout gap: the agent and the backend deploy independently, so a new agent can run against an older backend that still refreshes GitHub credentials only into the legacy /tmp/agent-env. In that window the reader looked only at /tmp/agent-github-env and, finding it absent, dropped straight to the process env frozen at launch — so a signed commit could use an expired or previous actor's token.

Why: keep signed commits using a live, refreshed token across the rollout window regardless of which backend version a sandbox is paired with, avoiding the Bad credentials (HTTP 401) failure #3652 addressed.

Changes

resolveGithubToken now chains the reads: dedicated /tmp/agent-github-env → legacy /tmp/agent-env (live-refreshed by older backends) → process env as a last resort. Under the current backend the legacy file excludes the token, so the dedicated file still wins; under an older backend the legacy fallback picks up the fresh token instead of the frozen one.

How did you test this?

  • pnpm --filter @posthog/agent... build (includes tsc typecheck) — passes
  • pnpm --filter @posthog/agent exec vitest run src/utils/github-token.test.ts — 9 tests pass, including new cases for github-over-legacy precedence and legacy fallback
  • biome check on the changed files — clean

Automatic notifications

  • Publish to changelog?
  • Alert Sales and Marketing teams?

Created with PostHog Code

During a mixed-version rollout a new agent can run against an older backend
that still refreshes GitHub credentials only into the legacy /tmp/agent-env.
The reader looked only at the dedicated /tmp/agent-github-env and, when absent,
dropped straight to the process env frozen at launch — signing commits with an
expired or previous actor's token.

Chain a fallback to the legacy live file before the frozen process env, so a
refreshed token is used under either backend version.

Generated-By: PostHog Code
Task-Id: 5d51048c-d903-459e-a770-028ab37f9099
@trunk-io

trunk-io Bot commented Jul 21, 2026

Copy link
Copy Markdown

Merging to main in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here

@github-actions

Copy link
Copy Markdown

React Doctor found no issues in the changed files. 🎉

Reviewed by React Doctor for commit 9162b87.

@tatoalo tatoalo closed this Jul 21, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant