Repository navigation
fix(channels): record failed long-connection events and catch up missed group @ messages - #1400
Conversation
…ed group @ messages A Feishu long-connection event that threw before or while it was accepted went back to the SDK and vanished: the SDK logger was a no-op and nothing was stored. History resync only ran when the connection state changed, so a lost @ message in a bound group was never answered. - receiveLongConnection records a failure as a failed inbox row (error code, identifiers only, its own failed:<event_id> key so a redelivery or catch-up still goes through), sets the connector's last_error, logs the event type and code, and catches up the event's chat. - The SDK logger passes warnings and errors to the log as redacted text; objects and debug output (event bodies, socket URL) are dropped. - Bound groups sync their recent history every minute, at once after the event loop was blocked for 5 s or more, and again 30 s later. Chat jobs re-read from just before the end they covered; threads with a message in the last 15 minutes are re-read whole. - History sync hands each message to a recovery hook in the page's transaction. A person's @ of the bot with no inbox row, 30 s to 5 minutes old, is queued as if it had arrived live (processing indicator, one turn, idempotent on the message's inbox key) and the reply says it was recovered late; one up to an hour old is only recorded (channel_message_missed). - Completed sync ranges that overlap merge into one row and spent cursors are removed, so the periodic catch-up adds no rows per run. Fixes agent-CI-Infra#1399
|
Reviewed head What I verified against the source:
Non-blocking notes (nothing to change before merge):
Enqueued into the merge queue with |
| m.reply_target?revalidateReplyTarget(this.store,chat.id,m.reply_target,{projects:[bindingScope(binding.id)],fence:m.fence}):undefined)}); | ||
| const replyTarget=result.reply_target?revalidateReplyTarget(this.store,chat.id,result.reply_target,{projects:[bindingScope(binding.id)],fence:result.fence}):undefined; | ||
| // A message recovered after its live event was lost (#1399) is answered late: the answer says so. | ||
| const late=e.recovered?recoveredNote:undefined; |
There was a problem hiding this comment.
suggestion — the “recovered late” note is lost when the missed message is merged into a turn that is already running.
recover merges a fresh missed message into the active turn (this.turnMessages.merge(...), src/channels/service.ts:307), which sets its inbox row to merged and hands it to the model only as a generic incoming_during_turn entry (src/channels/turn-messages.ts:161-168). Nothing marks that entry as recovered: describe() has no recovered/late field, and the merged message never becomes a turn source, so late here is computed only from the answered turn’s own source event and the final answer carries neither the recoveredNote footer nor the text prefix.
That contradicts the PR body (“merged into a running turn when there is one. The answer starts with … a note that the message was recovered late”) and docs/design/assistants-and-channels.md (“5 分钟内的按实时路径入队 … 最终回复带补收说明”), and it is exactly the #1399 shape: the live event was lost while a long turn was running, so the recovered message is the one that gets merged.
Options: (a) keep the promise — expose the flag on merged inputs (e.g. a recovered: true field in describe() and/or appending recoveredNote when the turn consumed a recovered input); (b) narrow the claim in the PR body and the design doc to “when the recovered message starts its own turn”. (a) preserves the promised UX; (b) is cheapest but leaves the person unaware their message was answered late.
Current coverage: test/st/src/channels/channel-missed-events.test.mjs case 3 only exercises the no-running-turn path, so neither behaviour is pinned today.
Review — record failed long-connection events and catch up missed group @ messagesReviewed head Claims checked against the diff
Verification I ran in this workspace at PR head ( Findings: one suggestion (F1, inline) — the “recovered late” note is dropped when the recovered message is merged into a turn that is already running, which is the shape of the #1399 incident and contradicts the PR body and the design doc. No must-fix, no security or data-loss issue found. Non-blocking observations (not findings): a lost @ that is the first reply of a thread, or that lands in a thread with no message in the last 15 minutes, is never recovered — the accepted cost of the 15-minute thread filter; and each active thread is re-read from the start every minute, bounded by the existing 10-jobs-per-tick sync budget. Recommendation: merge once F1 is either implemented (mark merged recovered inputs as recovered / add the note to a turn that consumed one) or the PR body and design sentence are narrowed to “when the recovered message starts its own turn”. Reviewed commit: c25bfbb |
0fc5e3a
Fixes #1399
Problem
A group message that @-mentioned the bot could be lost over the Feishu long connection without a trace. An exception from
receiveLongConnection→accept→normalizewent back to the SDK, whose logger was a no-op, and nothing was stored. History resync only ran when the connection state changed, so while the socket stayedconnected(as it did through the 24.7 s stall in production) the lost message was never caught up or answered.Change
Failures leave a trace (
src/channels/service.ts,src/channels/connections.ts)receiveLongConnectioncatches a throw from anywhere before or duringacceptand writes afailedinbox row with the error code. The payload holds only the event type, event id, message id and chat id, no message text. The row uses its ownfailed:<event_id>key, so a redelivery of the same event or a catch-up of the same message still goes through. It also sets the connector'slast_error, logs one line with the event type, code and ids, catches up the event's chat when that chat is known, and rethrows, so the SDK still answers Feishu with 500.warn/errorto the log as text only: errors by their message, other objects as[object], with every credential the deployment knows redacted (publicText+configuredRedactor).debug/info/tracestay silent. At debug level the SDK prints whole events and the socket URL.Missed messages are caught up (
service.ts,ledger.ts,history-sync.ts)ChannelService.syncTick(the existing 1 s timer) callscatchUpfor bound groups every 60 s and right after a tick runs ≥ 5 s late (a blocked event loop). After a stall it runs again 30 s later, once messages sent during the stall are old enough to count as missed.ChannelLedger.catchUpre-runs only finished jobs. The chat job re-reads fromcovered_until - 60(incremental). Thread jobs re-read in full, but only for threads with a message in the last 15 minutes, because threads have no time bounds. Running,blockedandpausedjobs are left alone.ChannelHistorySyncpasses every page message to a recovery hook inside the page transaction. A message counts as missed when it is from a person in a bound group, @-mentions the bot, is 30 s to 1 h old, and has nomessage:<id>inbox row:event_idrecovered:<id>,recovered: true), with the processing indicator, merged into a running turn when there is one. The answer starts with (or, for a rich card, has as its footer) a note that the message was recovered late.completed/channel_message_missedonly. It is in the ledger already, and nothing is answered.message:<id>key: whichever of the live event and a sync comes first wins, and repeated syncs do nothing.channel_sync_ranges(read on everyledger.queryviadiagnostics).Docs:
docs/features/assistants-and-channels.md(behavior),docs/design/assistants-and-channels.md(mechanism).Tests
New
test/st/src/channels/channel-missed-events.test.mjs:EventDispatcherwrites the failed row (code, ids, no text), setslast_error, logs the line; a repeat failure keeps one row; the redelivery after the fix is accepted, not deduplicated;warn/errorlines carry no request config or app secret; debug/info/trace print nothing;channel_message_missedbut not answered; > 1 h and < 30 s messages are not taken as missed;test/st/src/channels/channel-ledger.test.mjs: the two "nothing committed before ACK" tests now expect the failed trace row and still assert that no accepted row or ledger message is committed.Verification
Head
c25bfbb0(based onorigin/main2f2195a6), Node v22.19.0:npm ci(cd runner && npm ci)npm run checknpm testTMPDIR=$PWD/.tmp/s node --test test/ut/manager/runner-transport.test.mjsEADDRINUSEbecause the Unix socket path under the deep worktree exceeds 108 bytesnode test/framework/test-sets.mjs test/st/src/harness/codex-harness.test.mjsAll channel sets passed in the full run, including
channel-missed-eventsandchannel-ledger.