trae 0.2.29: a 9074 with no client here is claimed once more as client-less tools send it (#709, #722)

With no Trae CN client on the machine, Trae CN answers the plugin's
check-in claim 9074 every day (#722: jiabaoyu, never once taken; #709:
two accounts on a headless box). The same accounts check in through
tools that also have no client: providers-hub daily (#722), wild-work
(#709). #709 first put this down to account-level rate limiting cleared
by wild-work's 8s retry, but its reporter's own log then showed every
wild-work claim taken first time (~100ms, no 9074 since 09-19), so the
retry never ran and waiting is not the difference. What the working
tools share and the plugin doesn't: body {}, x-user-region: CN, a
15-digit id, no Electron UA / 0.1.69, none of the IDE's device headers.
providers-hub sends luckymiaow/trae-mate's request (MIT): those headers
and an id made from the uid alone, never registered at a sign-in.

Now an account no client here is signed in as gets one more claim, at
once, after a 9074, in trae-mate's request as it is (clientShapeHeaders;
its device, market user and session ids from the uid). Once: a second
9074 is the day's answer; no other code is claimed again; an account
that rode its own client's device is not; an account with no uid is
not. The first claim is unchanged, so an account it already works for
sends nothing new. Which single field Trae CN wants is still #709's
bisect.

Run (mote, bun): packages/trae bun test, 239 pass 0 fail; bun
scripts/check.mjs, every package ok.
Broken by hand: the old index.mjs under the new tests, 5 red (the
claimed-once-more, two-claims-never-three, and three message/device
tests); the guard widened to any non-zero code, "only a 9074 is claimed
again" and the 9095 test red. The golden ids for uid u-1 were worked out
with a separate Python port of trae-mate's device_map.rs.
Not tried: a real Trae CN account (no account used); whether the whole
request or one field of it is what Trae CN takes.
This commit is contained in:
yetone
2026-11-04 19:09:13 +08:00
parent ebdd4fd247
commit d677c436d3
5 changed files with 213 additions and 23 deletions
+21 -4
View File
@@ -448,10 +448,27 @@ answered it 9074 even with the client's headers.
client on this machine is the one thing seen to change a 9074, but it
hasn't been tried on a real account, so it isn't named in the message;
nor is it named when the claim already rode a client's device, where it
would only tell the user to do what they did. No device id is ever
changed or rotated to get round a 9095 or a 9074, and no account is
given another account's device or its own client's device unless a
client is signed in as that account.
would only tell the user to do what they did. The account's own device
is never rotated: a 9095 is the day's answer, and a 9074 gets the one
claim more below, on the one id made from the uid, and nothing after
it. No account is given another account's device or its own client's
device unless a client is signed in as that account.
- **A 9074 with no client here is claimed once more (0.2.29):** an
account no Trae CN client on this machine is signed in as gets one more
claim, at once, after a 9074, in the request that tools checking Trae
CN accounts in with no client send: luckymiaow/trae-mate's (MIT), as
iJetLi/dsh-providers-hub sends it too. Body `{}`, `x-user-region: CN`,
User-Agent `VSCode 1.107.1 (TRAE SOLO CN)`, its market, LSCBD and
session headers, and a 15-digit device id made from the uid alone
(trae-mate's `device_map.rs`), with none of the IDE's device headers.
On plugins#722 the account this plugin's claim got 9074 on checks in
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,
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
the device the claim went on: this machine's Trae CN client's, signed in
as the account, or magpie's own for it, with how many client profiles
+92 -13
View File
@@ -807,6 +807,64 @@ function ugHeaders(a, site, extra = {}, own) {
return { ...h, ...extra }
}
// clientShape is the claim request that three tools which check in Trae CN
// accounts with no Trae CN client on the machine send, and which Trae CN
// takes: luckymiaow/trae-mate (checkin.rs build_headers, device_map.rs;
// MIT), iJetLi/dsh-providers-hub's port of it (traeCheckinHeaders), and
// rockswang/wild-work. All three send body {}, `x-user-region: CN` and a
// 15-digit device id, none sends the Electron User-Agent or 0.1.69, and
// none retries a 9074 (wild-work's 8s retry never ran: every one of its
// claims was taken first time, plugins#709). On plugins#722 the same
// 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.
const seeded = (seed, salt, n) => {
const out = []
for (let i = 0; out.length < n; i++) {
const c = Buffer.alloc(4)
c.writeUInt32BE(i)
out.push(...createHash("sha256").update(`${salt}:${seed}`).update(c).digest())
}
return out.slice(0, n)
}
const shapeDevice = (uid) => seeded(String(uid), "devid", 15).map((b) => b % 10).join("")
function shapeMarketUser(uid) {
const b = seeded(String(uid), "market", 16)
b[6] = (b[6] & 0x0f) | 0x40
b[8] = (b[8] & 0x3f) | 0x80
const h = Buffer.from(b).toString("hex")
return `${h.slice(0, 8)}-${h.slice(8, 12)}-${h.slice(12, 16)}-${h.slice(16, 20)}-${h.slice(20)}`
}
function clientShapeHeaders(a) {
const uid = String(a.uid)
return {
Authorization: `Cloud-IDE-JWT ${a.token}`,
Accept: "*/*",
"Accept-Encoding": "gzip, deflate",
"Accept-Language": "zh-CN",
"Content-Type": "application/json",
"User-Agent": "VSCode 1.107.1 (TRAE SOLO CN)",
"x-market-client-id": "VSCode 1.107.1",
"x-market-user-id": shapeMarketUser(uid),
"x-user-region": "CN",
"x-device-id": shapeDevice(uid),
"x-lgw-req-sdk-type": "3",
"package-type": "stable_cn",
"x-lscbd-aid": "787976",
"x-lscbd-platform": "windows",
"app-version": "0.1.45",
"x-tt-trace-id": `00-${randomBytes(8).toString("hex")}-01`,
"vscode-sessionid": Buffer.from(seeded(uid, "sess", 32)).toString("hex"),
"x-request-id": randomUUID(),
"sec-fetch-dest": "empty",
"sec-fetch-mode": "no-cors",
"sec-fetch-site": "none",
}
}
// ---- this machine's own Trae CN client ----------------------------------------------
// Trae CN's desktop client keeps its state in a VS Code-style
@@ -3193,14 +3251,35 @@ const makePlugin = (site) => async ({ client }) => {
const body = first.body
if (body.checked_in) return { outcome: "done", ...(Number(body.credits) > 0 ? { credit: Number(body.credits) } : {}) }
if (!body.enable) return { outcome: "inactive" }
const claim = await ownRequest(getAuth, a0, site.hosts.auth + site.checkin.claim.path, "POST", "{}")
const claimText = await claim.text()
let answer
try { answer = JSON.parse(claimText) } catch {}
const ce = errorOf(answer)
const read = async (res) => {
const text = await res.text()
let v
try { v = JSON.parse(text) } catch {}
return { claim: res, claimText: text, answer: v, ce: errorOf(v) }
}
let { claim, claimText, answer, ce } = await read(await ownRequest(getAuth, a0, site.hosts.auth + site.checkin.claim.path, "POST", "{}"))
// A 9074 on an account no Trae CN client here is signed in as is
// claimed once more, at once, as the tools that check such accounts in
// send it (clientShape, plugins#709, #722) — once, never on another
// code, and never for an account that rode its own client's device. A
// 9074 means Trae took nothing, so the second claim can't take the day
// twice; what it answers is the day's answer, read the same way.
let again = ""
if (String(ce.code) === "9074" && site.id === "trae-cn" && a0.uid && !(await clientDevice(a0.uid))) {
let a
try {
a = await fresh(getAuth)
} catch (e) {
if (!(e instanceof Expired)) throw e
}
if (a) {
;({ claim, claimText, answer, ce } = await read(await fetch(site.hosts.auth + site.checkin.claim.path, { method: "POST", headers: clientShapeHeaders(a), body: "{}", signal: AbortSignal.timeout(20_000) })))
again = "; claimed again in the request Trae CN's client-less check-in tools send"
}
}
if (claim.status === 401 || lapsedCode(ce.code, site)) return { outcome: "failed", message: ce.message || `${a0.name || a0.uid}: Trae's sign-in has expired` }
// 9095: this device is in for today, whoever took it — the day's answer
if (String(ce.code) === "9095") return { outcome: "ineligible", message: `${ce.message || "this device has checked in today"} (${await deviceNote(a0.uid)})` }
if (String(ce.code) === "9095") return { outcome: "ineligible", message: `${ce.message || "this device has checked in today"} (${await deviceNote(a0.uid)}${again})` }
// 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
@@ -3209,18 +3288,18 @@ const makePlugin = (site) => async ({ client }) => {
// while this account's own id answered 9074. 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. No device id is made up or rotated to get round this:
// the account keeps its own until a client of its own is here to sign
// it in. Nothing is said of signing one in: it is the one thing seen
// to change a 9074, but it hasn't been tried on a real account, and
// on a claim that already rode a client's device it is what the user
// did — the advice would only send them back to do it again. What it
// problem is. Its own device is never rotated: an account with no
// client here gets one more claim in the client-less tools' request,
// on the one id they make from its uid (above), and nothing after
// that. Nothing is said of signing a client in: on a claim that
// already rode a client's device it is what the user did — the
// advice would only send them back to do it again. What it
// does say, after both 9074 and 9095, is which device the claim went
// on and why (deviceNote): moxuanchen (plugins#436) had to run
// clientDevice by hand to learn that the account Trae CN took (A, 100
// credits) rode the client's device and the one it refused 9074 (B)
// rode magpie's own, since both of that machine's profiles were A's.
if (String(ce.code) === "9074") return { outcome: "ineligible", message: `${ce.message} (9074) — Trae CN did not take this check-in for this account's device (${await deviceNote(a0.uid)})` }
if (String(ce.code) === "9074") return { outcome: "ineligible", message: `${ce.message} (9074) — Trae CN did not take this check-in for this account's device (${await deviceNote(a0.uid)}${again})` }
if (claim.status !== 200 || (ce.code && String(ce.code) !== "0")) return { outcome: "failed", message: ce.message || statusLine(claim.status) }
if (!answer || typeof answer !== "object" || Array.isArray(answer)) return { outcome: "failed", message: `check-in claim: unreadable reply ${claimText.trim().slice(0, 120) || "(empty)"}` }
// a claim's own code 0 is not proof the day is in: Trae answers it for
+84 -2
View File
@@ -122,8 +122,90 @@ 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)
expect(f.seen.map((r) => r.headers.get("x-device-id"))).toEqual(["2866487253502651", "2866487253502651"])
// sign-in device becomes the account's own 16-digit shape (#194); 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"])
})
// plugins#709 and #722: with no Trae CN client on the machine, Trae CN
// answers the plugin's claim 9074 every day, while three tools that check
// the same accounts in with no client are taken first time — trae-mate,
// providers-hub (#722's reporter, daily) and wild-work (#709's log: no
// 9074 at all, so its 8s retry never ran). A 9074 there is claimed once
// more, at once, in trae-mate's request: body {}, x-user-region CN, its
// headers, and the 15-digit id it makes from the uid. The bytes are #709's
// literal 9074 and Trae CN's real success (plugins#194).
const REFUSED = '{"code":9074,"message":"当前参与用户太多,请稍后再试"}'
const raw = (text) => new Response(text, { headers: { "content-type": "application/json" } })
const shaped = (r) => r.headers.get("user-agent") === "VSCode 1.107.1 (TRAE SOLO CN)"
test("a 9074 with no client here is claimed once more in the client-less tools' request, and taken", async () => {
f = fakeTrae()
let claimed = false
f.route("POST " + STATUS, () => json({ code: 0, enable: true, checked_in: claimed, credits: 100 }))
f.route("POST " + CLAIM, (r) => {
if (!shaped(r)) return raw(REFUSED)
claimed = true
return raw('{"code":0,"message":"success"}')
})
expect(await checkin()).toEqual({ outcome: "claimed", credit: 100 })
expect(f.seen.map((r) => r.path)).toEqual([STATUS, CLAIM, CLAIM, STATUS])
const second = f.seen[2]
expect(second.json).toEqual({})
const h = Object.fromEntries(second.headers)
// trae-mate's device_map.rs ids for uid "u-1", worked out apart from the plugin
expect(h["x-device-id"]).toBe("422507670212903")
expect(h["x-market-user-id"]).toBe("f8c30378-f888-4639-bdd1-9e53e2d66f48")
expect(h["vscode-sessionid"]).toBe("d169d4eac9d32be67855cbec44a37e20b06b57dc68b4e252edace023e037e7e7")
expect(h).toMatchObject({
authorization: "Cloud-IDE-JWT jwt-1",
"x-user-region": "CN",
"x-market-client-id": "VSCode 1.107.1",
"x-lgw-req-sdk-type": "3",
"package-type": "stable_cn",
"x-lscbd-aid": "787976",
"x-lscbd-platform": "windows",
"app-version": "0.1.45",
"accept-language": "zh-CN",
})
expect(h["x-tt-trace-id"]).toMatch(/^00-[0-9a-f]{16}-01$/)
expect(h["x-request-id"]).toMatch(/^[0-9a-f-]{36}$/)
// 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")
})
test("a second 9074 is the day's answer: two claims, never a third", async () => {
f = fakeTrae()
f.route("POST " + STATUS, () => json({ code: 0, enable: true, checked_in: false }))
f.route("POST " + CLAIM, () => raw(REFUSED))
const out = await checkin()
expect(out.outcome).toBe("ineligible")
expect(out.message).toContain("(9074)")
expect(out.message).toContain("claimed again")
expect(f.seen.map((r) => r.path)).toEqual([STATUS, CLAIM, CLAIM])
expect(f.seen.map(shaped)).toEqual([false, false, true])
})
test("only a 9074 is claimed again: another refusal is one claim", async () => {
for (const answer of ['{"code":9095,"message":"当前设备今日已经签到"}', '{"code":1005,"message":"x"}', '{"code":9004,"message":"x"}']) {
f = fakeTrae()
f.route("POST " + STATUS, () => json({ code: 0, enable: true, checked_in: false }))
f.route("POST " + CLAIM, () => raw(answer))
await checkin()
expect(f.seen.map((r) => r.path)).toEqual([STATUS, CLAIM])
f.close()
f = undefined
}
})
test("an account with no uid is not claimed again", async () => {
f = fakeTrae()
f.route("POST " + STATUS, () => json({ code: 0, enable: true, checked_in: false }))
f.route("POST " + CLAIM, () => raw(REFUSED))
expect((await checkin(TraeCNAuthPlugin, signedIn({ uid: "" }))).outcome).toBe("ineligible")
expect(f.seen.map((r) => r.path)).toEqual([STATUS, CLAIM])
})
// a claim's code 0 is not the answer: Trae answers it for a claim that
+15 -3
View File
@@ -273,12 +273,24 @@ test("B's 9074 says it went on magpie's own device, since both profiles here are
const out = await refused("uid-b")
expect(out).toEqual({
outcome: "ineligible",
message: "当前参与用户太多,请稍后再试 (9074) — Trae CN did not take this check-in for this account's device (sent on magpie's own device for this account: 2 Trae CN client profiles are on this machine, none signed in as this account)",
message: "当前参与用户太多,请稍后再试 (9074) — Trae CN did not take this check-in for this account's device (sent on magpie's own device for this account: 2 Trae CN client profiles are on this machine, none signed in as this account; claimed again in the request Trae CN's client-less check-in tools send)",
})
// it names neither uid nor either device
expect(out.message).not.toContain("uid-a")
expect(out.message).not.toContain(DC)
expect(f.seen.at(-1).headers.get("x-device-id")).toBe(_internal.ugDevice(signedIn({ uid: "uid-b" })))
// the first claim on magpie's own device; B has no client here, so the
// 9074 is claimed once more on the id made from its uid (plugins#709)
const claims = f.seen.filter((r) => r.path.endsWith("/claim"))
expect(claims.map((r) => r.headers.get("x-device-id"))).toEqual([_internal.ugDevice(signedIn({ uid: "uid-b" })), expect.stringMatching(/^\d{15}$/)])
expect(claims[1].headers.get("x-device-id")).not.toBe(DC)
})
test("a 9074 on the account's own client's device is not claimed again (plugins#709)", async () => {
reporterProfiles()
const out = await refused("uid-a")
expect(out.outcome).toBe("ineligible")
expect(out.message).not.toContain("claimed again")
expect(f.seen.filter((r) => r.path.endsWith("/claim")).map((r) => r.headers.get("x-device-id"))).toEqual([DC])
})
test("A's refusal says it went on the client's device; one account in two profiles is no conflict (#436)", async () => {
@@ -301,5 +313,5 @@ test("a client device another account's profile also has is named as shared (#43
test("one profile, signed in as someone else, is counted in the singular (#436)", async () => {
client("uid-a")
const out = await refused("uid-b")
expect(out.message).toContain("(sent on magpie's own device for this account: 1 Trae CN client profile is on this machine, none signed in as this account)")
expect(out.message).toContain("(sent on magpie's own device for this account: 1 Trae CN client profile is on this machine, none signed in as this account; claimed again")
})
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@magpie-community/opencode-trae-auth",
"version": "0.2.28",
"version": "0.2.29",
"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",