Skip to content

feat(agents): renew every CLI credential through one path, report failures to Sentry - #304

Merged
artempartos merged 3 commits into
developfrom
artempartos/unified-credential-refresh
Sep 24, 2026
Merged

artempartos merged 3 commits into
developfrom
artempartos/unified-credential-refresh

Conversation

@artempartos

Copy link
Copy Markdown
Contributor

Why

Audit of production on 2026-09-24: every credential row, the sweep's log, Sentry and live containers. The question was whether every agent CLI renews its token, and whether they all do it the same way.

Runtime Before (prod) After
claude_code sweep refreshes every 8h ✅; 9 rows invalid_grant (known pinning/rotation class) unchanged, failures now in Sentry
codex ✅ 401 retry recorded, rejection reason kept
cursor_cli ❌ every refresh 404s on prod (#287 not deployed); the web 401 path logged at INFO and recorded nothing; 10 rows expired since May–Aug still active 401 retry goes through renew! → recorded + Sentry
kiro_cli ✅ refresh works; an IdC login still dies at the directory's 8h session cap (cred 121: expiry never moved past login+8h, then invalid_grant) expected, now in Sentry
antigravity_cli container-only (agy refreshes itself); expiry hidden server-side refresh with agy's consumer OAuth client, pair verified against a live credential (3599s, refresh token not rotated)
grok declared reauth_only ("no refresh token"), which is wrong: the OIDC blob stores a refresh token for auth.x.ai's public client server-side refresh via auth.x.ai/oauth2/token (6h tokens)
gemini_cli API key unchanged: nothing to refresh

Before this change no refresh failure reached Sentry as an error. Each one was a Rails.logger.warn, which shows up as an INFO log line.

What changes

  • AgentCredential#renew! is the only renewal path. The sweep, the launch top-up and the web-side 401 retry (Cursor/Codex fetch_available_models) all go through it. It records the outcome: success clears the error, failure counts toward condemning the credential and sends the mail. It also reports every failure as AgentCredential::RefreshFailed via Rails.error. config/initializers/sentry.rb forwards only that source to Sentry, one issue per runtime × caller × permanent/transient.
  • Cursor and Codex refresh! return the vendor's reason (HTTP code/body) instead of "refresh failed".
  • Grok and Antigravity: refresh: :server. The contract test now pins coverage at every runtime except gemini_cli.
  • The :held guard applies only to rotating refresh tokens. Cursor and Antigravity are static, so a holder's copy stays valid. Waiting for the holder to go quiet only let the token expire.
  • Design doc: new §3.2 with the audit, and the updated matrix.

Deploy notes

  • Antigravity needs ANTIGRAVITY_OAUTH_CLIENT_ID / ANTIGRAVITY_OAUTH_CLIENT_SECRET in the prod environment (values are in agy's binary; I'll hand them over out of band). Without them the runtime keeps its old container-only lifecycle. They stay out of the repo on purpose: GitHub secret scanning reports a committed GOCSPX- secret to Google, which would revoke the client for every agy user.
  • Prod is behind develop. Deploying develop alone fixes Cursor (fix(cursor): refresh against the endpoint the IDE actually uses #287) and starts sweeping the rows whose expires_at was never derived. Expect a burst of RefreshFailed on the first sweeps: those long-dead Cursor/Claude/Kiro rows will finally be condemned, and their owners mailed.

Verification

Targeted suites (models, all agent adapters, container strategies, sweep activity: 675 runs) are green in an isolated container. rubocop and brakeman are clean. Full suite: CI.

🤖 Generated with Claude Code

artempartos and others added 3 commits September 24, 2026 04:13
…lures to Sentry

A production audit (2026-09-24) found refresh failures invisible: every one was a
warn-level log line, and the web-side 401 retry in Cursor/Codex recorded nothing on the
credential (43 Cursor 404s in 14 days, all rows at refresh_failure_count = 0).

AgentCredential#renew! is now the only way a credential is renewed — sweep, launch
top-up and the 401 retry. It records the outcome and reports each failure to Sentry as
AgentCredential::RefreshFailed, grouped per runtime, caller and permanence.

Grok and Antigravity gain server-side refresh. Production blobs show Grok's OIDC login
stores a refresh token for auth.x.ai's public client, and agy's consumer OAuth client was
verified against a live credential (static refresh token, 1h access token). The
Antigravity client pair comes from the environment: a committed GOCSPX- secret would be
reported to Google and revoked for every agy user.

The :held guard now applies only to rotating refresh tokens; Cursor and Antigravity keep
the holder's copy valid, so waiting only let their tokens expire.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
@artempartos
artempartos merged commit cb839d2 into develop Sep 24, 2026
7 checks passed
aixle-com Bot pushed a commit that referenced this pull request Dec 1, 2026
…unner-layers.md (runners 17b, #304) (#919)

* feat(coder): Coder services for a second consumer (runners 17b, #304)

Holder and explicit hold in LockService, Allocator#allocate(wait: false) with
the ready-machine handover, Allocator#delete(holder:), Coder::WorkspaceStatus,
WorkspaceService#status, #ensure_started_async and QuotaError.

Signed-off-by: Alex <[email protected]>

* test(coder): inline the build-wait assertion

Signed-off-by: Alex <[email protected]>

* fix(coder): bind the holder key in the lock ownership query

Signed-off-by: Alex <[email protected]>

* fix(coder): move HTTP classification into Coder::Api, keep non-quota create failures, redact build errors

WorkspaceService no longer reads HTTP status or body: Coder::Api returns nil
for a gone workspace and raises QuotaRefusedError for a quota refusal.
Allocator#allocate(wait: false) raises a non-quota create failure instead of
ExhaustedError, and redacts the build error of a failed workspace.

Signed-off-by: Alex <[email protected]>

* test(coder): fix the stubs of the unknown-verdict retry test

Signed-off-by: Alex <[email protected]>

* docs(coder): state the concurrent same-holder case, and test two holds for one holder

Signed-off-by: Alex <[email protected]>

* refactor(coder): the Coder services in Core and Infrastructure, Coder::Holder and Coder::Errors (17b, C1)

Moves app/services/coder into core/ and infrastructure/ as in runner-layers.md
section 11.1, extracts Coder::Holder and Coder::Errors to the top of the
namespace and renames the constants at every caller. No logic change.

Signed-off-by: Alex <[email protected]>

* refactor(coder): Coder::Core::Commands, and the lock wrappers on Allocator (17b, C2)

The hold check, touch and call that coder_ssh_exec, coder_job_status and
coder_prepare_repo each repeated move into Coder::Core::Commands.
Allocator gains release, .release_all_for_session and .sweep_expired_locks!,
which coder_release_machine, IntegrationCleanupService and the sweep call;
the sweep activity and job stop writing IntegrationData themselves.

Signed-off-by: Alex <[email protected]>

* test(coder): the layering test of the Coder services (17b, C3)

Signed-off-by: Alex <[email protected]>

* fix(coder): Commands.prepare_repo! reads the repository after the hold check, and test the sweep (17b)

coder_prepare_repo refused a session with no hold before it looked for the
repository, and still does. LockService.sweep_expired! gets its own test.

Signed-off-by: Alex <[email protected]>

* fix(sessions): the wait's message no longer outlives the wait on launchError (17b)

AdmittedPhaseActivity wrote wait_reason and last_error when a session waited
for capacity and cleared only wait_reason when the phase went on, so a session
that was already running still showed the wait through launch_error. A phase
that goes on, or fails for its own reason, now clears the message the wait
wrote. A last_error that no wait wrote is kept.

Signed-off-by: Alex <[email protected]>

* chore(coder): rubocop fixes, and the status of the layer rework in runner-layers.md (17b)

Signed-off-by: Alex <[email protected]>

* Keep SessionAdmission launch-wait rules in the model

Add waiting_for_launch? and clear_wait_error so the admitted phase
activity no longer reads LAUNCH_WAITS.

Signed-off-by: Alex <[email protected]>

* Coder: a wait ends with its message, entry points name only Core, Holder and Errors, held_by?

- SessionAdmissionService#release! and #close_queued! clear a launch wait's message
  through SessionAdmission#stop_waiting.
- The token, lock, SSH and repository errors move to Coder::Errors; Pool and the
  workspace listing for coder.rake go through Coder::Core::PoolRules. The layering test
  covers the entry points.
- LockService#held_by_session? is held_by?, as it takes any holder.

Signed-off-by: Alex <[email protected]>

* Coder layering test: allow IntegrationService::ConfigurationError, the connect form's own error

Signed-off-by: Alex <[email protected]>

* Coder::Interface: the one public module of the Coder services

Every caller outside app/services/coder (the coder_* tools, jobs, activities,
the integrations controller, the cleanup service, coder.rake) goes through
Coder::Interface, made of one-line delegations. Core::PoolRules is folded into
it, the connect form's errors move to Coder::Errors, and the layering test
checks both rules.

Signed-off-by: Alex <[email protected]>

* Integrations controller: build the connection-test service without a type check

Signed-off-by: Alex <[email protected]>

* Fix the malformed Coder interface table in runner-layers.md

Signed-off-by: Alex <[email protected]>

---------

Signed-off-by: Alex <[email protected]>
Co-authored-by: Alex <[email protected]>
artempartos added a commit that referenced this pull request Dec 2, 2026
* origin/develop: (23 commits)
  ci(images): publish web, otlp-ingest and runner-relay for linux/arm64 (#983)
  fix(k8s): give a pod's image pull its own start budget (#979)
  build(dev): pull published agent images instead of building them (#980)
  fix(deps): bump coder-cli to v2.34.22 (CVE fixes) (#956)
  chore(agents): raise agent CLI pins for canary #943 (#975)
  docs(runners): record the §12.5 staging validation of the coder runner (row 18) (#978)
  build(dev): run local Temporal on the CLI dev server image (#954)
  fix(deps): websocket-driver 0.9.2 security batch, cross-spawn and tar re-resolve (#976)
  feat(web): link the docs portal from the app footer and sidebar (#379) (#969)
  feat(onboarding): Getting started page and product tour (#51) (#879)
  feat(dashboard): keep the table's sort in the URL (#974)
  fix(kiro): offer the models the account has today, not those of its last login (#973)
  feat(dashboard): keep the period and filters in the URL (#972)
  feat(company-settings): confirm worker count changes before saving (#971)
  feat(runners): the Coder runner in the UI: form, Environments section and docs (runners 17e, #315) (#963)
  docs(trackers): tech design for trackers chosen per session (#959)
  chore: remove the integrations backfill tooling left from #298 (#964)
  feat(runners): a coder runner created from the console (runners 17d, #309) (#960)
  chore(release): 1.23.0 (#961)
  feat(coder): Coder services for a second consumer, in the layers of runner-layers.md (runners 17b, #304) (#919)
  ...

# Conflicts:
#	CHANGELOG.md
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.

1 participant