Skip to content

refactor(cloud-agent-next): migrate to git-token-service RPC#2747

Merged
eshurakov merged 1 commit intomainfrom
eshurakov/lush-heart
Apr 29, 2026
Merged

refactor(cloud-agent-next): migrate to git-token-service RPC#2747
eshurakov merged 1 commit intomainfrom
eshurakov/lush-heart

Conversation

@eshurakov
Copy link
Copy Markdown
Contributor

@eshurakov eshurakov commented Apr 23, 2026

Summary

Replaces the in-worker GitHubTokenService and InstallationLookupService in cloud-agent-next with calls to the shared git-token-service Worker via a new GIT_TOKEN_SERVICE service binding, and removes the now-redundant token pre-fetching in the web app tRPC routers.

Architectural changes

  • cloud-agent-next no longer talks to Postgres (Hyperdrive) or KV to resolve GitHub App installations / cache tokens. A single GIT_TOKEN_SERVICE.getTokenForRepo / getToken / getGitLabToken RPC replaces both services.
  • Token resolution for GitHub repo installs and managed GitLab integrations is now consolidated in a new helper services/cloud-agent-next/src/services/git-token-service-client.ts, used from both the synchronous session-prepare path and the autoInitiate async preparation path.
  • A new gitlabTokenManaged flag is persisted in CloudAgentSession metadata. When set, startExecutionV2 refreshes the GitLab token on every execution via a new refreshManagedGitLabToken helper on the DO.
  • Web routers (cloud-agent-next-router.ts + organization-cloud-agent-next-router.ts) stop fetching GitHub/GitLab tokens for prepareSession and sendMessage. cloud-agent-next handles token resolution and refresh centrally. The No GitLab integration found. Please connect your GitLab account first. BAD_REQUEST previously surfaced by the web app is now raised inside cloud-agent-next at prepare time, preserving the UX.
  • wrangler.jsonc: wires the GIT_TOKEN_SERVICE binding (prod + dev) and drops GITHUB_APP_ID, GITHUB_LITE_APP_ID, the GITHUB_TOKEN_CACHE KV namespace and the HYPERDRIVE binding.

Net change: −549/+286. The old KV namespace (GITHUB_TOKEN_CACHE) and Hyperdrive config (HYPERDRIVE) in Cloudflare are now unbound; they can be decommissioned after rollout.

Verification

  • Manual verification

Visual Changes

N/A

Comment thread apps/web/src/routers/cloud-agent-next-router.ts
Comment thread services/cloud-agent-next/src/persistence/CloudAgentSession.ts Outdated
Comment thread services/cloud-agent-next/src/persistence/CloudAgentSession.ts
@kilo-code-bot
Copy link
Copy Markdown
Contributor

kilo-code-bot Bot commented Apr 23, 2026

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (0 files)

No files changed since the previous review.


Reviewed by gpt-5.5-2026-04-23 · 823,602 tokens

Comment thread services/cloud-agent-next/src/persistence/CloudAgentSession.ts
@eshurakov eshurakov requested a review from alex-alecu April 29, 2026 08:40
@eshurakov eshurakov force-pushed the eshurakov/lush-heart branch from bc097f2 to 98e042b Compare April 29, 2026 11:20
Replace the in-worker GitHubTokenService and InstallationLookupService
with calls to the shared git-token-service Worker via a GIT_TOKEN_SERVICE
service binding, and drop the now-redundant token fetching in the web
app routers.

- Wire GIT_TOKEN_SERVICE binding in wrangler.jsonc; drop GITHUB_APP_ID,
  GITHUB_LITE_APP_ID, and GITHUB_TOKEN_CACHE KV bindings. Restore the
  HYPERDRIVE binding for an upcoming feature.
- Resolve GitHub tokens for repo + managed GitLab tokens through a new
  shared helper (src/services/git-token-service-client.ts) used from
  both session-prepare and async-preparation paths.
- Persist gitlabTokenManaged in session metadata so the DO can refresh
  GitLab tokens on startExecutionV2 via refreshManagedGitLabToken.
  Successful refreshes are persisted via updateGitToken so later
  transient failures fall back to the last-known working token instead
  of the stale prepare-time token. Treat gitlabTokenManaged ===
  undefined as managed for backwards compatibility with pre-existing
  sessions.
- Fail closed on GitLab access revocation: no_integration_found and
  invalid_org_id reasons throw BAD_REQUEST at session prepare and
  startExecutionV2 instead of falling back to the stored token, so the
  session cannot keep using a managed token after the integration or
  org access was removed. Transient failures retain the last-known
  token fallback.
- Parameterize DurableObject<WorkerEnv> on the base class, removing 28
  'as unknown as WorkerEnv' casts in CloudAgentSession and aligning
  with the rest of the repo's DO pattern.
- Extract cloudflare-git-token-service into a standalone
  'git-token-service' dev group shared by cloud-agent, app-builder, and
  gastown. Switch its dev script to 'wrangler dev --env dev' so the
  locally-running worker is named 'git-token-service-dev', matching
  what cloud-agent-next and the security workers reference in their
  dev service bindings.
- Web routers (personal + org) no longer fetch GitHub/GitLab tokens
  for prepareSession/sendMessage — cloud-agent-next handles token
  resolution and refresh centrally.
@eshurakov eshurakov force-pushed the eshurakov/lush-heart branch from 98e042b to 9b8b5c8 Compare April 29, 2026 11:26
@eshurakov eshurakov merged commit 8c3b189 into main Apr 29, 2026
38 checks passed
@eshurakov eshurakov deleted the eshurakov/lush-heart branch April 29, 2026 15:00
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.

2 participants