Skip to content

fix(im): treat QQ error bodies on 2xx responses as send failures - #1866

Merged
Fei2411 merged 1 commit into
devfrom
fix/1850-qq-reply-window
Nov 20, 2026
Merged

Fei2411 merged 1 commit into
devfrom
fix/1850-qq-reply-window

Conversation

@Fei2411

@Fei2411 Fei2411 commented Nov 19, 2026 •

Copy link
Copy Markdown
Owner

Issue

Refs #1850. This is a likely cause of the silent loss there, but it isn't confirmed against the reporter's actual QQ response yet (asked on the issue), so this PR does not auto-close it.

Agent: Devin (Cognition)

What changed / 改了什么

Bug: the QQ adapter's api() treated any 2xx response as sent unless the body had code. The QQ API guide says failures carry err_code (code is legacy) and that 201/202 return an error body. So a refused passive reply (for example 40034005 回复消息msg_id已过期) that came back as a 2xx with only err_code counted as delivered. Nothing was logged, the status didn't change and there was no Try again.

  • A nonzero err_code or code is now an error on any status. A business refusal on a 2xx response is permanent, so it goes through the existing retained-failure path (diagnostics warning, IM status error, Try again).
  • code: 0 / err_code: 0 is a success. Before this change, code: 0 threw.
  • 304023 / 304024 (accepted, waiting for audit) count as sent and are not retried, so there are no duplicates.
  • Errors include trace_id (from the body or the X-Tps-trace-ID header) for reporting.
  • Tests: 200 and 202 refusals with either field, zero codes, audits and the markdown fallback. The expiry test now uses 304027, because 304023 is the audit code.

No active-send (no msg_id) fallback: the IM design (docs/plans/2026-11-04-im.md) is passive-only.

Changelog

QQ replies the platform refuses inside a successful HTTP response now show as failed sends with Try again, instead of disappearing silently.

How I checked it / 怎么验证的

  • npm test (in ds-bot/): 3096 pass, 0 fail, 4 skipped. The new tests fail on dev (5 failures, "Missing expected rejection") and pass with the fix.
  • node scripts/build-client.mjs --check
  • npm run lint
  • Smoke test: all 52 steps passed
  • Screenshot attached, for interface changes (no interface change)

Checklist / 检查

  • One issue, one subject. / 只做一件事。
  • src/client/ changed → npm run build ran and client.js is committed. (src/client/ not changed)
  • No keys, tokens or personal data, also in screenshots. / 没有密钥、token 或个人信息,截图里也没有。
  • No AI tool as author or Co-authored-by. / 没有把 AI 工具写成作者或 Co-authored-by。

Product Engineer opened this PR for Lulu
Implemented in session Fix QQ replies lost after reply window
Review with Devin · Open in Devin Desktop


QQ documents err_code as the business result even for 2xx responses. Recognize nonzero current and legacy codes so rejected passive replies reach retained delivery errors, diagnostics and connection status instead of appearing sent. Accept zero codes and pending audits without retrying, and preserve trace IDs for reports.
@devin-ai-integration

Copy link
Copy Markdown
Contributor

I'll fix CI failures and address comments from users with write access that start with 'Devin'.

  • Disable automatic comment, CI, and merge conflict monitoring

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-19T17:03:57.557527Z ae4d2b2 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Devin Review found 1 finding. It is left for you to triage below.

View findings in Devin Review · Follow Devin's work

Devin Review

const bizCode = [json.err_code, json.code].find(code => code !== undefined && Number(code) !== 0)
// Awaiting audit is accepted, not a refusal; retrying could duplicate delivery.
if ([304023, 304024].includes(Number(bizCode))) return json
if (!response.ok || bizCode !== undefined) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Duplicate chunks on QQ reply retry

When api rejects a later chunk with a 2xx err_code refusal, the queue retains the entire reply. Try again replays it from the start, so QQ recipients can receive chunks they already got.

Devin left this for you to triage: This is older than the PR: a 4xx refusal on a later chunk already keeps the whole reply, and Try again resends chunks that were delivered. The PR only adds 2xx refusals to that path. Fixing it means tracking per-chunk progress in the shared IM queue, which is beyond this fix; I recommend a separate issue.

Learn more

The IM bridge queues a bot's full reply as one job in sendTo. The QQ send loop splits it into separate posts and advances msg_seq per post. A 2xx refusal with only err_code previously did not trigger a replay. Now drain retains the whole job when a later post fails. Try again enqueues that same job, and the QQ send loop starts at the first chunk with new sequence numbers.

Example: QQ delivers the first part of a 2,200-character reply, then returns 202 with err_code: 40034005 for the second part because the reply window expired. After the recipient sends a fresh message, using Try again delivers both parts instead of only the missing second part.

Recommended fix: Keep the next unsent chunk index with the queued job. Advance it only after QQ accepts each chunk, including pending-audit responses. Add a regression test that delivers one chunk, rejects the next with a 2xx err_code, and verifies that Try again posts only the remaining chunk.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

@Fei2411 Fei2411 left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Code Reaper review (comments only) — for Product Engineer

Verdict: ready for lulu once the Agent line is added; code is good.

Code (api() in qq.js)

  • Nonzero err_code/code on any status now throws; 0 is success; 2xx business refusals are permanent, so they reach the retained-failure path (warning, IM status error, Try again). Matches the QQ API guide.
  • 304023/304024 (pending audit) return as sent — right call, retrying would duplicate.
  • 5xx with a business code still retries (not permanent unless the reason matches the regex) — fine.
  • The markdown fallback still works: bizCode is the nonzero one, so a 2xx err_code: 40034090 falls back to plain text (covered by the updated test).
  • trace_id in the message is useful for #1850.

Needs fixing

  1. PR body is missing the Agent: Devin (Cognition) line that AGENTS.md requires for agent-opened PRs (no Devin labels exist, so labels aren't needed).

CI

  • windows-latest · Node 24 · DSH 0.2.2-rc.1 failed in switch-keeps-input.test.js ("a marked earlier part hands its kept input on after a restart"), which doesn't touch IM. It passes locally with this branch; looks like a timing flake — re-run the job.

Devin Review finding (duplicate chunks on Try again): agree it predates this PR (4xx refusals on a later chunk already replay the whole reply). Worth a separate issue; not a blocker here.

Overlaps

  • #1862 (inbound images/files) also edits qq.js and im-qq.test.js. It merges with this PR without conflicts, and im-qq + im + switch-keeps-input tests pass on the combined tree (99/99). Either order works; land this one first (smaller, independent).
  • #1201 and #1167 also touch qq.js but already conflict with dev.

@Fei2411

Fei2411 commented Nov 19, 2026

Copy link
Copy Markdown
Owner Author

Thanks. I added the Agent: Devin (Cognition) line to the PR body. There's no Devin agent/* or model/* label, so I added none. The Windows rerun of switch-keeps-input is queued for when the macOS/iOS jobs in this run finish.

@Fei2411
Fei2411 merged commit 70ba281 into dev Nov 20, 2026
29 of 31 checks passed
@Fei2411
Fei2411 deleted the fix/1850-qq-reply-window branch November 20, 2026 12:39
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.

1 participant