devin 0.1.39: an unreadable identity keeps its own slot (#993, #931)

An unreadable Devin identity no longer falls back to the shared name "Devin". `success` now names such an account `Devin · <12 hex>`, a SHA-256 of the API server and session token. The host de-duplicates plugin accounts by `metadata.email` (magpie `internal/plugin/host.js` `settle`/`whoOf`), so two different unreadable sign-ins used to replace each other's credential. Now each one keeps its own slot. Signing in again with the same key on the same server gives the same name, so it lands in the same slot. When `usage`'s `syncOrg` later reads the account, it renames the slot to the real email in place, as before. Fixes #931.

Ran (mica, bun 1.4.2, HOME=$(mktemp -d), PR head 14fa75a5 merged with origin/main 445f4143):
- bun test packages/devin: 209 pass, 0 fail; bun scripts/check.mjs devin ok
- root bun test: 8293 pass, 4 fail. The 4 are gumloop's "exclusive ledger updates > Node ..." reds that are already known on main (PR CI shows the same four). bun scripts/check.mjs: no failures
- 0.1.39 is free: npm has 0.1.38, and origin/dist tgz/ ends at 0.1.38

Broken by hand, one at a time, each made the new identity test red:
- fallback back to "Devin"
- key left out of the hash (server only)
- a random salt per sign-in (stable slot)
- the raw key in the name

Not changed / not tried: accounts saved earlier as "Devin" keep that name. A new unreadable sign-in with the same key now gets a "Devin · <hash>" slot beside the old one, where before it replaced it. The host's settle only matches by secret when neither side has a name. Not tried with a real Devin account (no vendor calls). magpie's Devin mover (migrate_side.go) only carries the built-in's saved user names and reads nothing from this fallback.

Co-authored-by: zhou.han <18181754+yetihan@users.noreply.github.com>
This commit is contained in:
zhou.han
2026-11-11 19:49:32 +08:00
committed by GitHub
co-authored by zhou.han
parent 445f4143de
commit d45eb69f23
4 changed files with 23 additions and 6 deletions
+5 -1
View File
@@ -25,7 +25,11 @@ plugin's own, `~/.cache/opencode-devin-auth/<hash of the token>/`, so the
CLI's own sign-in is never touched. A CLI that reads another
`credentials.toml` than that folder's (on Windows it reads
`%APPDATA%\devin\` whatever it is run with) isn't asked: it would name
its own account. Otherwise the account is named "Devin".
its own account. Otherwise the account is named
`Devin · <fingerprint>`, using a one-way fingerprint of the API server
and session token. Repeating the same sign-in keeps its slot, while two
accounts whose identities are both unreadable no longer replace each
other.
The token is kept where OpenCode keeps sign-ins (`auth.json`; in magpie,
`plugin-auth.json`) as `{ "type": "api", "key", "metadata": { "email", "plan", "orgId", "teamId" } }`.
+9 -2
View File
@@ -134,10 +134,17 @@ test.if(unix)("a key Devin refuses fails the sign-in, whatever the CLI says", as
await expect(_internal.success("key-refused", "https://server.codeium.com")).rejects.toThrow("Devin didn't take the sign-in")
}, SLOW)
test.if(unix)("when Devin can't tell, the CLI names the account only if it read the key's own folder", async () => {
test.if(unix)("unreadable identities keep separate stable slots until the CLI names the account", async () => {
devin(() => new Response("", { status: 503 }))
// the CLI read its own credentials.toml: not the key's account
expect((await _internal.success("key-c", "https://server.codeium.com")).metadata).toEqual({ email: "Devin" })
const c = await _internal.success("key-c", "https://server.codeium.com")
const cAgain = await _internal.success("key-c", "https://server.codeium.com")
const d = await _internal.success("key-d", "https://server.codeium.com")
expect(c.metadata.email).toMatch(/^Devin · [0-9a-f]{12}$/)
expect(cAgain.metadata.email).toBe(c.metadata.email)
expect(d.metadata.email).not.toBe(c.metadata.email)
expect(c.metadata.email).not.toContain("key-c")
expect(d.metadata.email).not.toContain("key-d")
// a CLI that honours the folder answers for the key
process.env.FAKE_HONOURS = "1"
process.env.FAKE_EMAIL = "c@x.dev"
+8 -2
View File
@@ -928,17 +928,23 @@ async function exchange(code, verifier, redirect) {
return { key, webapp: r.devinWebappHost, api: r.devinApiUrl }
}
// unknownAccount names a credential without revealing it. The same key on
// the same server keeps its slot, while two unreadable accounts don't both
// become "Devin" and replace each other in magpie (#931).
const unknownAccount = (key, server) =>
`Devin · ${createHash("sha256").update(server || SERVER).update("\0").update(key).digest("hex").slice(0, 12)}`
// success names a key's account as Devin does when asked with the key
// (GetUserStatus), or, when Devin can't tell, as the CLI does in a data
// folder of the plugin's own: never by the CLI alone, which on Windows
// names its own account whatever key it is given (#17). A key Devin or the
// CLI says nobody is signed in with fails it; with neither able to tell,
// the account is just "Devin".
// a stable fingerprint keeps that credential apart from another (#931).
async function success(key, server) {
let who = await whoByKey(key, server)
if (who === undefined) who = await identity(await homeFor(key, server))
if (who === null) throw new Error("Devin didn't take the sign-in: nobody is signed in with the token it gave")
const metadata = { email: who?.user || "Devin" }
const metadata = { email: who?.user || unknownAccount(key, server) }
if (who?.plan) metadata.plan = who.plan
const orgId = who?.orgId || who?.teamId
if (orgId) metadata.orgId = orgId
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@magpie-community/opencode-devin-auth",
"version": "0.1.38",
"version": "0.1.39",
"description": "Devin subscriptions (the devin CLI's account) in OpenCode and magpie",
"type": "module",
"main": "./index.mjs",