Repository navigation
fix(claim): send X-Device-Mid from the env fallback (Android claim always failed with biz 3001) - #84
Merged
Conversation
Android injects the per-install device id as ZCODE_IDENTITY_DEVICE_MID and never writes identity.deviceMid into config.yaml, but the loader only read YAML — so the claim client sent no X-Device-Mid and the gateway answered biz 3001 "parameter error" on every claim POST. Preview survived only because the marketing face has its own derived fallback, which is why the app could enumerate plans and then fail to grab them. Observed on the Android app as `[claim] claim: invalid_request (3001) — parameter error` every 10 min while desktop/CLI claimed fine on the same account. - loader: resolve identity.deviceMid as env > YAML (blank counts as unset), matching the documented contract on ProxyIdentity and the order proxy/identity.ts already applies to the request headers, so the two planes agree on one fingerprint. - claim/runtime: add claimDeviceMid() and use it for BOTH the preview and claim clients — the billing face has no fallback of its own, so a config without identity.deviceMid must not reach it with the header omitted. - tests: env precedence / blank-env fallthrough in loader.test.ts, plus claim/runtime.test.ts for the shared-UUID contract.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Symptom
On the Android app (and any setup where
identity.deviceMidis not inconfig.yaml), the auto-claim scheduler logs this every cooldown cycle andnever claims anything:
The desktop/CLI path claims fine on the same account, and
GET /api/v1/zcode-plan/billing/previewstill enumerated plans — so it looked like the campaign rejected the account rather than the request being malformed.Root cause
Two gaps that combine:
src/proxy/identity.tsreadsX-Device-Midas env (ZCODE_IDENTITY_DEVICE_MID) > YAML, and the type docs onProxyIdentitysay the same ("Android: injected via the env var — env wins over YAML").resolveIdentity()insrc/config/loader.tsonly read YAML, soconfig.identity.deviceMidwasundefinedon Android (NodeRunner deliberately never writes it toconfig.yaml).startAutoClaim()'s billing client tookdeviceMid: config.identity.deviceMidwith no fallback, whilemarketingDeviceMidfell back tostableMarketingDeviceMid(). Preview therefore worked through the marketing face, and the claim POST went out withX-Device-Midomitted.Per the empirical note already in
src/claim/client.ts(0828 / wk-0918 campaigns), the gateway answers biz3001 "parameter error"to billing calls whoseX-Device-Midis missing or not a UUID — exactly the classificationclassifyClaimCode()produced.Fix
src/config/loader.ts: resolveidentity.deviceMidas env > YAML (blank counts as unset), matching the documented contract and the header-building order, so both planes share one fingerprint.src/claim/runtime.ts: newclaimDeviceMid()used for both the preview and claim clients — the billing face has no fallback of its own, so a config withoutidentity.deviceMidmust never reach it with the header dropped.loader.test.ts; newclaim/runtime.test.tspinning the shared stable-UUID contract.Verification
bun test: 1229 pass / 0 fail (66 → now 69 files, includes the new suite).Live on the Android app (endpoint
zcode.z.ai, planzai/start-plan,config.yamlwith noidentityblock): before the patch the scheduler produced the 3001 line every 10 min; after it the very next tick loggedand the plan shows up in the official client for the same account.
No behaviour change for desktop/CLI users:
ensureDeviceMidInConfig()keeps the YAML value and nothing else reads this field.