trae 0.2.30: a Trae CN check-in goes on a 15-digit device id (#709)

sept13-yu's bisect on #709 (2026-11-05): with the plugin's own headers
and body ({"req_source":1}), the same token and account, seconds apart,
only x-device-id changed, the account's own 16-digit id got 9074 and a
15-digit one (a random, never-registered one too) was taken. Three
accounts, two machines on two ISPs, magpie's headers and wild-work's
alike: 16 refused every time, 15 taken every time. Every account signed
in since 0.2.16 has a 16-digit id and ugDevice sent it as it was, so
every client-less account's first claim got 9074. 0.2.29's second claim
uses trae-mate's 15-digit uid-derived id, which is likely why it lands.

ugDevice (only used for the ug pages, status and claim, of a trae-cn
account no local client is signed in as) now keeps an id that is
already 15 digits and otherwise makes a 15-digit one from the account's
own device id and uid: the same derivation it used for pre-0.2.16
19-digit ids, now modulo 9e14 with a 1e14 floor, so the first digit is
never 0 (shapeDevice can start with 0, which as a number is 14 digits).
Stable per account, changes only with a new sign-in, never another
account's.

Left alone, and why:
- newDevice stays 16 digits. That id is registered at sign-in, sent on
  every chat request and bound into the renewed JWT; nothing measured
  says chat or renewal want 15, and the bisect showed registration
  doesn't matter for the claim.
- An account whose local Trae CN client is signed in as it keeps the
  client's own device (the bisect didn't touch that path).
- Trae Global: no check-in, 19 digits as before.
- 0.2.29's one extra claim in clientShapeHeaders after a 9074 stays as
  the fallback: the bisect never sent that request with a 16-digit id,
  so "nothing but the id matters in it" isn't measured. It costs one
  claim on a 9074 day only.

Run (mote, bun): packages/trae bun test, 240 pass 0 fail; bun
scripts/check.mjs, 44 packages ok.
Broken by hand: the old index.mjs under the new tests on mote, 11 red,
among them the new "signed in since 0.2.16 (16 digits) checks in on a
15-digit id" test and the request-header tests. Golden ids
(166487253502651, 245914665436526) worked out by a separate Python port
of the derivation, which also reproduces the old 2866487253502651.
Not tried: a real Trae CN account check-in (no account here); whether
the chat or renewal care about the id length.
This commit is contained in:
yetone
2026-11-05 10:13:03 +08:00
parent 73362966e7
commit 13371a3e52
6 changed files with 104 additions and 49 deletions
+22 -11
View File
@@ -46,7 +46,8 @@ authorization page: `device_id` and `machine_id` (32 hex). Every
request then sends that same device. The relays saw requests dropped when the
device was new each time. A Trae CN `device_id` is 16 digits since 0.2.16, the
shape of the ids Trae's device service gives its clients (15 or 16 digits);
Trae Global's stays 19.
Trae Global's stays 19. The daily check-in goes on a 15-digit id made from it
(see Daily check-in).
### Enterprise (SaaS) accounts
@@ -427,14 +428,21 @@ answered it 9074 even with the client's headers.
files — harmless if they differ, since a folder that isn't there, or a
key that isn't named, is simply not read. A client started with its own
`--user-data-dir` is not found: there is no list of those to read.
- **Every other account's device (0.2.16):** its own device id, in the
client's shape. Trae CN answered a claim on the plugin's 19-digit id
9074, while the same account and token on a 16-digit id were taken
(magpie-community/plugins#194). An account signed in since 0.2.16 has a
16-digit id and checks in on it. One signed in before checks in on a
16-digit id made from its own device id and uid: the same id every day,
never rotated, and no other account's. Its chat requests and renewals
keep the 19-digit device it signed in with.
- **Every other account's device (0.2.16, 15 digits since 0.2.30):** its
own device id, in the shape Trae CN takes. Trae CN answered a claim on the
plugin's 19-digit id 9074, while the same account and token on a
16-digit id were taken (magpie-community/plugins#194). On 2026-11-05 it
answered 16 digits 9074 too (plugins#709): with the plugin's own
headers and body, the same token and account, seconds apart, the
account's own 16-digit id got 9074 and a 15-digit one, even a random
one nothing had registered, was taken — on three accounts, from two
machines on two ISPs, and with wild-work's headers alike. So since
0.2.30 every account checks in on a 15-digit id made from its own device
id and uid (one already 15 digits goes as it is): the same id every day,
never rotated, never starting with 0, and no other account's. Its chat
requests and renewals keep the device it signed in with (16 digits, or
19 before 0.2.16): nothing measured asks for another there, and the
device is bound into the renewed sign-in.
- **What comes back:** Trae's answer as it is. A 401 or code 1001 marks
the account for a new sign-in. Code 9095 means this device has checked
in today, and that holds for the day. Code 9074 means Trae did not take
@@ -465,8 +473,11 @@ answered it 9074 even with the client's headers.
daily through providers-hub, and on plugins#709 wild-work, which also
sends body `{}`, `x-user-region: CN` and a 15-digit id, had every claim
taken first time, so its 8-second retry never ran: waiting is not what
changes a 9074. Which field Trae CN wants hasn't been measured, so the
request goes whole, and only once: a second 9074 is the day's answer,
changes a 9074. plugins#709's bisect then found the id's length to be
what decides (16 refused, 15 taken, headers and body changing nothing),
and since 0.2.30 the first claim goes on 15 digits (above). This request
is kept as the fallback, since it wasn't measured with a 16-digit id, and
goes only once: a second 9074 is the day's answer,
no other code is claimed again, and an account whose own client's
device the claim rode is not. Not yet tried on a real Trae CN account.
- **Which device, said (0.2.25):** a 9074 or 9095 message ends with
+39 -14
View File
@@ -32,9 +32,9 @@ test("a check-in page is sent as the account, its answer back as it is", async (
// device headers and a client's User-Agent, not Bun's
expect(r.json).toEqual({ req_source: 1 })
expect(r.headers.get("authorization")).toBe("Cloud-IDE-JWT jwt-1")
// the account's own device in the client's 16-digit shape: this
// account signed in before 0.2.16 with 19 digits (#194)
expect(r.headers.get("x-device-id")).toBe("2866487253502651")
// the account's own device in the 15-digit shape Trae CN takes: this
// account signed in before 0.2.16 with 19 digits (#194, plugins#709)
expect(r.headers.get("x-device-id")).toBe("166487253502651")
expect(r.headers.get("x-device-type")).toBe("Windows")
expect(r.headers.get("x-os-version")).toBe("10.0.22631")
expect(r.headers.get("x-app-version")).toBe("0.1.69")
@@ -93,25 +93,48 @@ test("other hosts' pages and other paths aren't sent as a page", async () => {
})
// #194: Trae CN answered a claim on the plugin's 19-digit device id 9074,
// and the same account and token on a 16-digit one were taken. The
// check-in goes on the account's own device in that shape; it is never
// rotated, and no two accounts share one.
test("an account signed in before 0.2.16 checks in on one 16-digit id made from its own device, every time", () => {
// and the same account and token on a 16-digit one were taken. Since
// plugins#709 (2026-11-05) it answers 16 digits 9074 too, and the same
// account, token, headers and body on 15 digits are taken. The check-in
// goes on the account's own device in that shape; it is never rotated, and
// no two accounts share one.
test("an account signed in before 0.2.16 checks in on one 15-digit id made from its own device, every time", () => {
const a = signedIn()
const id = _internal.ugDevice(a)
expect(id).toMatch(/^[1-9]\d{15}$/)
expect(id).toMatch(/^[1-9]\d{14}$/)
// worked out by a separate Python port of the derivation
expect(id).toBe("166487253502651")
// the same on every check-in, and not the 19 digits cut short
expect(_internal.ugDevice(signedIn())).toBe(id)
expect(id).not.toBe("1234567890123456")
expect(id).not.toBe("123456789012345")
// another account's, or another device's, is not this one
expect(_internal.ugDevice(signedIn({ uid: "u-2" }))).not.toBe(id)
expect(_internal.ugDevice(signedIn({ deviceId: "9876543210987654321" }))).not.toBe(id)
// an account with no uid still has its own
expect(_internal.ugDevice(signedIn({ uid: "" }))).toMatch(/^[1-9]\d{15}$/)
expect(_internal.ugDevice(signedIn({ uid: "" }))).toMatch(/^[1-9]\d{14}$/)
})
test("an id already in the client's shape is the account's own, as it is", () => {
expect(_internal.ugDevice(signedIn({ deviceId: "1234567890123456" }))).toBe("1234567890123456")
// plugins#709: the reporter's bisect, three accounts, magpie's own
// headers and body: the account's own 16-digit id 9074, a 15-digit one
// taken, seconds apart. An account signed in since 0.2.16 has 16 digits,
// so its check-in goes on a 15-digit id made from it: the same every
// time, and not the 16 digits cut short.
test("an account signed in since 0.2.16 (16 digits) checks in on a 15-digit id made from its own device", () => {
const id = _internal.ugDevice(signedIn({ deviceId: "1234567890123456" }))
expect(id).toMatch(/^[1-9]\d{14}$/)
expect(id).toBe("245914665436526")
expect(_internal.ugDevice(signedIn({ deviceId: "1234567890123456" }))).toBe(id)
expect(id).not.toBe("123456789012345")
expect(_internal.ugDevice(signedIn({ deviceId: "1234567890123456", uid: "u-2" }))).not.toBe(id)
expect(_internal.ugDevice(signedIn({ deviceId: "6543210987654321" }))).not.toBe(id)
// every fresh Trae CN sign-in's device: none is checked in on as it is
for (let i = 0; i < 50; i++) {
const d = _internal.newDevice(_internal.SITES["trae-cn"]).deviceId
expect(_internal.ugDevice(signedIn({ deviceId: d }))).toMatch(/^[1-9]\d{14}$/)
}
})
test("an id already 15 digits is the account's own, as it is", () => {
expect(_internal.ugDevice(signedIn({ deviceId: "123456789012345" }))).toBe("123456789012345")
expect(_internal.ugDevice(signedIn({ deviceId: "", uid: "" }))).toBe("")
})
@@ -121,16 +144,18 @@ test("a new Trae CN sign-in's device is 16 digits; Trae Global's stays 19", () =
expect(_internal.newDevice(_internal.SITES["trae-global"]).deviceId).toMatch(/^[1-9]\d{18}$/)
})
test("an account with a 16-digit device checks in on it; an old one's chat pages keep the 19 digits it signed in with", async () => {
test("an account with a 16-digit device checks in on 15 digits; chat pages keep the device each signed in with", async () => {
f = fakeTrae()
f.route("POST /trae/api/v2/ug/checkin_credits/claim", () => json({ code: 0 }))
f.route("POST /trae/api/v2/pay/ide_user_ent_usage", () => json({ code: 0 }))
const o16 = await fetcher(signedIn({ deviceId: "1234567890123456" }))
await o16.fetch(f.origin + "/trae/api/v2/ug/checkin_credits/claim", { method: "POST", body: "{}" })
expect(f.seen.at(-1).headers.get("x-device-id")).toBe("245914665436526")
await o16.fetch(f.origin + "/trae/api/v2/pay/ide_user_ent_usage", { method: "POST", body: "{}" })
expect(f.seen.at(-1).headers.get("x-device-id")).toBe("1234567890123456")
const o19 = await fetcher()
await o19.fetch(f.origin + "/trae/api/v2/ug/checkin_credits/claim", { method: "POST", body: "{}" })
expect(f.seen.at(-1).headers.get("x-device-id")).toBe("2866487253502651")
expect(f.seen.at(-1).headers.get("x-device-id")).toBe("166487253502651")
await o19.fetch(f.origin + "/trae/api/v2/pay/ide_user_ent_usage", { method: "POST", body: "{}" })
expect(f.seen.at(-1).headers.get("x-device-id")).toBe("1234567890123456789")
})
+37 -19
View File
@@ -314,26 +314,38 @@ const sleep = (ms) => new Promise((r) => setTimeout(r, ms))
// gives the IDE a 15- or 16-digit one (iCubeAuthInfo://icube-dc:<id>, see
// clientDevice), and Trae CN answers a check-in claim on a 19-digit id
// 9074 where the same account and token on a 16-digit one are taken
// (magpie-community/plugins#194). Trae's global site keeps the 19 digits
// it was signed in with: nothing says its ids are shaped otherwise.
// (magpie-community/plugins#194). The check-in no longer goes on it: since
// plugins#709 Trae CN refuses 16 digits there too, and ugDevice makes the
// claim's 15-digit id. Trae's global site keeps the 19 digits it was signed
// in with: nothing says its ids are shaped otherwise.
const newDevice = (site) => ({ deviceId: digits(site?.id === "trae-cn" ? 16 : 19), machineId: randomBytes(16).toString("hex"), ...newDeviceKey() })
// ugDevice is the device id a Trae CN account's check-in goes on when this
// machine's client isn't signed in as it: its own when that already has a
// client's shape (15 or 16 digits), else, for an account signed in before
// 0.2.16 with 19 digits, a 16-digit id made from its own device id and
// uid. That one is the same on every check-in of the account, never
// rotated and never another account's: it is the account's own device in
// the shape Trae CN takes (#194), not a new device to get past a refusal,
// and a 9095 (this device is in for today) on it stays the day's answer.
// The chat's pages and the renewal keep the device the account signed in
// with.
// machine's client isn't signed in as it: its own when that is already 15
// digits, else a 15-digit id made from its own device id and uid. On
// 2026-11-05 (plugins#709) Trae CN answered the plugin's claim on an
// account's own 16-digit id 9074, and the same account, token, headers and
// body, seconds later, on a 15-digit id (a random one nothing had
// registered) were taken: on three accounts, from two machines on two
// ISPs, with magpie's headers and with wild-work's alike, 16 digits was
// refused every time and 15 taken every time. The client-less tools that
// check in (trae-mate, providers-hub, wild-work) all send 15 digits too.
// #194 had found 19 refused and 16 taken; a server-side change between
// the two is the plain reading. The id is the same on every check-in of
// the account, never rotated and never another account's, and its first
// digit is never 0 (a 0 would make it 14 digits as a number): it is the
// account's own device in the shape Trae CN takes, not a new device to get
// past a refusal, and a 9095 (this device is in for today) on it stays the
// day's answer. The chat's pages and the renewal keep the device the
// account signed in with (16 digits since 0.2.16, 19 before): nothing
// measured says they want another, and the device is bound into the
// renewed JWT.
function ugDevice(a) {
const id = String(a.deviceId ?? "")
if (/^\d{15,16}$/.test(id)) return id
if (/^\d{15}$/.test(id)) return id
if (!id && !a.uid) return id
const n = BigInt("0x" + createHash("sha256").update(`trae-cn-device\0${id}\0${a.uid ?? ""}`).digest("hex").slice(0, 30))
return String(1_000_000_000_000_000n + (n % 9_000_000_000_000_000n))
return String(100_000_000_000_000n + (n % 900_000_000_000_000n))
}
// newDeviceKey is the device's key pair, an ECDSA P-256 one as the clients
@@ -818,9 +830,13 @@ function ugHeaders(a, site, extra = {}, own) {
// account this plugin's claim gets 9074 on checks in daily through
// providers-hub. This is trae-mate's request as it is: its headers, and
// its device, market user and session ids made from the uid alone, so an
// account checks in on the device those tools already use for it. Which
// field is the one Trae CN wants hasn't been measured (plugins#709's
// bisect); the request goes whole.
// account checks in on the device those tools already use for it.
// plugins#709's bisect then found the id's length to be what Trae CN
// decides on (16 refused, 15 taken, the headers and body changing
// nothing), so since 0.2.30 the first claim goes on 15 digits too
// (ugDevice). This request stays as the one fallback after a 9074: the
// bisect didn't send it with a 16-digit id, so that nothing else in it
// matters is not measured.
const seeded = (seed, salt, n) => {
const out = []
for (let i = 0; out.length < n; i++) {
@@ -3213,7 +3229,7 @@ const makePlugin = (site) => async ({ client }) => {
const deviceId = ug && site.id === "trae-cn" ? await clientDevice(a.uid) : undefined
const own = deviceId ? { deviceId, ...thisMachine() } : undefined
// every other Trae CN account checks in on its own device, in the
// client's shape (ugDevice, #194)
// 15-digit shape Trae CN takes (ugDevice, #194, plugins#709)
if (ug && site.id === "trae-cn" && !own) a = { ...a, deviceId: ugDevice(a) }
const res = await fetch(url, {
method,
@@ -3283,9 +3299,11 @@ const makePlugin = (site) => async ({ client }) => {
// 9074: Trae did not take this claim for this account's device. Its own
// words say the pool is busy, which measurements do not bear out: the
// same account, token and headers were taken on a 16-digit id where a
// 19-digit one got 9074 (plugins#194), and on 2026-10-23 the same
// 19-digit one got 9074 (plugins#194), on 2026-10-23 the same
// account and headers were taken on a device id Trae had never seen
// while this account's own id answered 9074. So the message says what
// while this account's own id answered 9074, and on 2026-11-05 a
// 16-digit id got 9074 where 15 digits were taken (plugins#709, so the
// claim goes on 15 now: ugDevice). So the message says what
// Trae said and that the device is what it refused, rather than
// sending people to check in in Trae CN's app, which is not where the
// problem is. Its own device is never rotated: an account with no
+4 -3
View File
@@ -122,9 +122,10 @@ test("Trae's 9074 on the claim says the device is what Trae refused, and promise
expect(out.message).toContain("sent on magpie's own device for this account")
expect(out.message).not.toMatch(/sign (it )?in|log ?in|check in in the Trae CN app/i)
// the check-in rides ugDevice like every other ug page: the 19-digit
// sign-in device becomes the account's own 16-digit shape (#194); the
// sign-in device becomes the account's own 15-digit shape (#194,
// plugins#709); the
// one claim more goes on the id made from the uid (plugins#709, #722)
expect(f.seen.map((r) => r.headers.get("x-device-id"))).toEqual(["2866487253502651", "2866487253502651", "422507670212903"])
expect(f.seen.map((r) => r.headers.get("x-device-id"))).toEqual(["166487253502651", "166487253502651", "422507670212903"])
})
// plugins#709 and #722: with no Trae CN client on the machine, Trae CN
@@ -173,7 +174,7 @@ test("a 9074 with no client here is claimed once more in the client-less tools'
// none of the IDE's device headers, nor the chat's
for (const k of ["x-app-version", "x-device-brand", "x-device-type", "x-os-version", "x-uid", "x-ide-token"]) expect(h[k]).toBeUndefined()
// the read-back after it goes as before
expect(f.seen[3].headers.get("x-device-id")).toBe("2866487253502651")
expect(f.seen[3].headers.get("x-device-id")).toBe("166487253502651")
})
test("a second 9074 is the day's answer: two claims, never a third", async () => {
+1 -1
View File
@@ -68,7 +68,7 @@ async function checkIn(auth = signedIn()) {
// the account's own device, in the client's shape (ugDevice, #194)
const plugins = (h, a = signedIn()) => {
expect(h.get("x-device-id")).toBe(_internal.ugDevice(a))
expect(h.get("x-device-id")).toMatch(/^\d{16}$/)
expect(h.get("x-device-id")).toMatch(/^[1-9]\d{14}$/)
expect(h.get("x-device-brand")).toBeTruthy()
expect(h.get("x-device-type")).toBe("Windows")
expect(h.get("x-os-version")).toBe("10.0.22631")
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@magpie-community/opencode-trae-auth",
"version": "0.2.29",
"version": "0.2.30",
"description": "OpenCode provider plugins for Trae: Trae CN (trae.cn) and Trae Global (trae.ai), free tier included, with Trae's own browser sign-in",
"type": "module",
"main": "./opencode.mjs",