Skip to content

fix(ai): restore Devin usage reports for session tokens stored as API keys - #2

Closed
eggpeat wants to merge 2 commits into
mainfrom
fix/devin-usage-reporting
Closed

eggpeat wants to merge 2 commits into
mainfrom
fix/devin-usage-reporting

Conversation

@eggpeat

@eggpeat eggpeat commented Oct 20, 2026 •

Copy link
Copy Markdown
Owner

What

omp reads Devin usage again for session tokens saved as API keys, by trying the CLI login format first and falling back to the raw key only after a 401, the same order chat already uses. Separately, /usage and omp usage --json no longer list a Devin browser login as "no usage data" next to its own working report.

  • packages/ai/src/usage/devin.ts: GetUserStatus sends devinCliMetadata first for every credential type, with one retry using devinWireMetadata only on HTTP 401 when the encoded key differs. Legacy Windsurf keys (devin: legacy Windsurf Enterprise seats can't authenticate in omp (login 401, chat/usage send prefixed session token) can1357/oh-my-pi#12958) keep working through that retry, which replaces the test that pinned raw keys for api_key credentials.
  • packages/coding-agent/src/slash-commands/helpers/usage-accounts.ts: collectUnreportedAccounts does not claim an account is missing when it has no email, account, project or org identity at all and its provider returned reports. Identified accounts keep the existing org-gated attribution.

Why

Since about Oct 19-20, Devin answers 401 {"code":"unauthenticated","message":"invalid api key"} to the raw-key form for a session token stored as api_key, so the usage report was null and quota showed as unknown. Devin browser logins store only the token (its JWT carries just session_id), while the usage report carries an orgId, so the org gate flagged the account as unreported.

Testing

  • Live, with the account's real Devin credentials: the patched fetch returned a report on its first request for the old API-key credential (HTTP 401 before the fix) and for the browser login.
  • New tests reports API-key usage when only the CLI session-token form is accepted, falls back to the raw key once only after HTTP 401 with a different encoding and does not list identity-less OAuth accounts as missing beside an org-attributed report fail on the parent commit (0 pass, 3 fail) and pass with the fix.
  • bun test packages/ai/test/devin-account-usage.test.ts packages/coding-agent/test/usage-cli.test.ts: 114 pass, 0 fail.
  • bun check: passes.

  • bun check passes
  • Tested locally
  • CHANGELOG updated with the required attribution (if user-facing; internal issue fixes use issue links, external contributions add the PR link and contributor credit after creation)

Devin Review

… keys

Devin now rejects the raw-key GetUserStatus form for session tokens saved as api_key credentials (401 'invalid api key'), leaving quota unknown. Usage now mirrors chat auth: CLI session-token metadata first, one raw-key retry only after 401 when the encoding differs, so legacy Windsurf keys (can1357#12958) keep working.

collectUnreportedAccounts no longer lists an OAuth account with no identity at all as missing when its provider returned reports; Devin browser logins store no email, account or org, and their report carries an org.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Devin Review found 1 potential issue.

Devin Review

const ids = [account.email, account.accountId, account.projectId]
.filter((value): value is string => typeof value === "string" && value.length > 0)
.map(value => value.toLowerCase());
if (!accountOrg && ids.length === 0) return false;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Missing OAuth usage hidden by sibling report

When one identity-less OAuth account fails and a sibling reports usage, collectUnreportedAccounts treats both as covered. Neither /usage nor omp usage --json shows the failed account as missing.

Learn more

Usage reports are fetched for each stored credential by UsageService, but this helper receives only reports and identity slices of credentials. Devin browser logins can supply no stored email, account ID, project, or org. The early return therefore cannot distinguish a successful identity-less account from a failed sibling when one report exists for the provider. Previously an org-attributed sibling did not cover an org-less account, so this change hides that failed account's missing-usage row.

Example: Two Devin browser logins store tokens A and B without identity fields. A returns a report with an org ID, while B's usage request fails. The provider has one report, so both accounts pass the early return; the dashboard shows A's report without B's missing-usage row.

Recommended fix: Carry a stable credential-to-report association through the usage fetch and account collection paths, then suppress a missing row only for the credential that yielded a report. Do not infer coverage from provider presence when multiple identity-less credentials exist.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

@eggpeat eggpeat closed this Oct 20, 2026
@eggpeat
eggpeat deleted the fix/devin-usage-reporting branch October 20, 2026 19:26
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