Skip to content

fix(trae): redeem auth code on callback and handle CN host fallback - #309

Merged
caigee-cmd merged 3 commits into
caigee-cmd:mainfrom
favoroo:feat/trae-callback-checkin
Oct 19, 2026
Merged

caigee-cmd merged 3 commits into
caigee-cmd:mainfrom
favoroo:feat/trae-callback-checkin

Conversation

@favoroo

@favoroo favoroo commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fix Trae browser login so it completes on the callback itself.

  • Login completes on the callback itself. The loopback listener used to only park the authorization code and wait for a console poll, but the poll window is much shorter than a real browser login (SMS login can take minutes), so the code expired unused and the account showed account not found. The callback now exchanges the code and stores the credential immediately. Pasted callback URLs still work and now actually redeem; a URL carrying only loginTraceID is accepted; the single-use code is exchanged exactly once even when callback, poll, and paste overlap.

Review follow-ups (2026-10-19)

  • Device-id normalization split out: the aha-<md5> remapping conflicted with main's verified conclusion (numeric ids must be sent as-is; an aha- prefix is rejected with 9074), so that commit is removed from this PR and will come back as a separate PR with real-account verification (CN + Global, fresh logins with numeric device ids) before it is considered.
  • Debug logs trimmed: removed logs that could leak login state (callback URL, OAuth trace, code/verifier lengths, success logs). Failures now log only account, host, status, and the extracted error code — never the raw upstream payload or the callback URL. The acceptCallback parse failure no longer echoes the parse error either (it embeds the raw URL with the one-shot code).
  • Dead code removed: the never-assigned lastErr in ExchangeAuthCode and the unreachable post-loop return are gone.
  • Rebased onto latest main; go test ./... green.

Tests

  • go build ./..., go vet ./..., go test ./..., git diff --check
  • Trae provider tests cover the login fix.

@caigee-cmd caigee-cmd left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

感谢提交!浏览器登录在回调时直接完成换码这部分修复很有价值,解决了短信登录耗时长导致 code 过期、最终显示 account not found 的问题,单次 code 防重复兑换的处理也很周到。

合并前需要调整以下几点:

  1. 设备 ID 规范化与 main 的现有结论冲突。main 上 headers.go 的注释写的是:纯数字 id 必须原样发送,加 aha- 前缀反而会被 9074 拒绝。本 PR 改为把非 32 位 hex 的 id 一律 MD5 映射为 aha-<md5>,另外已经带 aha- 但后缀不是 32 位 hex 的 id 也会被改写。请任选其一:
    • 用真实账号(最好国内、国际各一个,覆盖纯数字 device id 的新登录)验证签到能成功,并在 PR 中附上脱敏后的结果;
    • 或者把设备 ID 改动拆到单独的 PR,本 PR 只保留登录修复。
  2. 请删除或收敛新增的调试日志。目前 StartLogin 会打出完整的 callback URL 和 trace(即 OAuth state),ExchangeAuthCode 失败时会打出完整的上游 payload,存在泄露登录态的风险。建议只保留失败日志,并且只记录 account、host、status 和错误码,不要输出 URL、state、payload。
  3. ExchangeAuthCode 里的 lastErr 从未赋值,循环后的 return credential, lastErr 是无效代码,请清理。
  4. 目前分支落后 main,请 rebase 到最新 main 后再跑一遍 go test ./...。

改完后 @ 我一下,我会尽快再看。谢谢!

One bilingual fragment per PR, per changelog/unreleased/README.md.
Per review on caigee-cmd#309:
- Remove the new debug logs that could leak login state: StartLogin no longer
  logs the callback URL and OAuth trace; acceptCallback no longer logs the
  parse error (url.Parse echoes the raw URL carrying the one-shot code);
  redeemAsync success/start logs removed, and its failure log now records only
  account + classified status/code since the full error message can embed the
  upstream payload; ExchangeAuthCode logs status + extracted error code
  instead of the raw payload.
- Remove the dead 'var lastErr' / post-loop 'return credential, lastErr' in
  ExchangeAuthCode — lastErr was never assigned and err is always nil there.
- The device-id normalization commit is split out of this PR; the changelog
  fragment now covers only the login fix.
@favoroo
favoroo force-pushed the feat/trae-callback-checkin branch from ccec128 to 9d13846 Compare October 19, 2026 04:56
@favoroo favoroo changed the title fix(trae): complete browser login on callback and normalize check-in device id fix(trae): redeem auth code on callback and handle CN host fallback Oct 19, 2026
@favoroo

favoroo commented Oct 19, 2026

Copy link
Copy Markdown
Contributor Author

@caigee-cmd 已按 review 调整:

  1. 设备 ID 规范化已拆出:与 main 上 headers.go 的结论(纯数字 id 必须原样发送,aha- 前缀会被 9074 拒绝)确实冲突,该提交已从本 PR 移除,本 PR 现在只保留登录修复。设备 ID 的改动我会另开 PR,并先用真实账号(国内、国际各一个,覆盖纯数字 device id 的新登录)验证签到后再附脱敏结果。
  2. 日志已收敛:删除了会泄露登录态的新增日志(StartLogin 的完整 callback URL + trace、acceptCallback 的 parse 错误——url.Parse 的错误信息会带上含一次性 code 的原始 URL、redeemAsync 的 start/success 日志)。失败日志现在只记录 account、host、status 和提取出的错误码:ExchangeAuthCode 不再输出原始 payload,redeemAsync 失败只记分类后的 status/code(完整 error message 可能嵌入上游 payload)。
  3. lastErr 死代码已清理:连同循环后永不可达的 return credential, lastErr 一并移除。
  4. 已 rebase 到最新 main,go test ./... 全绿。

@caigee-cmd 麻烦再看一下,谢谢!

@caigee-cmd caigee-cmd left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

LGTM. Review follow-ups look good: device-id change split out, sensitive logs trimmed, dead lastErr removed, rebased. Merging.

@caigee-cmd
caigee-cmd merged commit 8ce9551 into caigee-cmd:main Oct 19, 2026
6 checks passed
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.

2 participants