Repository navigation
fix(im): treat QQ error bodies on 2xx responses as send failures - #1866
Conversation
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.
|
I'll fix CI failures and address comments from users with write access that start with 'Devin'.
|
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
Devin Review found 1 finding. It is left for you to triage below.
| 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) { |
There was a problem hiding this comment.
🟡 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.
Was this helpful? React with 👍 or 👎 to provide feedback.
Fei2411
left a comment
There was a problem hiding this comment.
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/codeon any status now throws;0is success; 2xx business refusals arepermanent, 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:
bizCodeis the nonzero one, so a 2xxerr_code: 40034090falls back to plain text (covered by the updated test). trace_idin the message is useful for #1850.
Needs fixing
- 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.1failed inswitch-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.jsandim-qq.test.js. It merges with this PR without conflicts, andim-qq+im+switch-keeps-inputtests pass on the combined tree (99/99). Either order works; land this one first (smaller, independent). - #1201 and #1167 also touch
qq.jsbut already conflict withdev.
|
Thanks. I added the |
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 hadcode. The QQ API guide says failures carryerr_code(codeis legacy) and that 201/202 return an error body. So a refused passive reply (for example40034005回复消息msg_id已过期) that came back as a 2xx with onlyerr_codecounted as delivered. Nothing was logged, the status didn't change and there was no Try again.err_codeorcodeis 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: 0is a success. Before this change,code: 0threw.304023/304024(accepted, waiting for audit) count as sent and are not retried, so there are no duplicates.trace_id(from the body or theX-Tps-trace-IDheader) for reporting.304027, because304023is 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(inds-bot/): 3096 pass, 0 fail, 4 skipped. The new tests fail ondev(5 failures, "Missing expected rejection") and pass with the fix.node scripts/build-client.mjs --checknpm run lintChecklist / 检查
src/client/changed →npm run buildran andclient.jsis committed. (src/client/not changed)Co-authored-by. / 没有把 AI 工具写成作者或Co-authored-by。Implemented in session Fix QQ replies lost after reply window
Review with Devin · Open in Devin Desktop