Repository navigation
fix(msteams): preserve inbound activities before webhook ack - #110357
Conversation
…append Bot Framework webhooks acked before detached processing with no platform retry, silently losing inbound activities on a crash. Dispatchable activities (message + adaptiveCard/action invokes) now persist their raw JSON durably (event_id = activity.id per the @microsoft/teams.api uniqueness contract, lane = conversation.id) before the webhook 200; dispatch runs through the core drain with deferred claims through debounce, merged-flush fan-out adoption, gated-turn settlement, retry/dead-letter classification, and 30d/20k tombstones. Restart replay reconstructs proactive routing context. No inbound replay guard existed; the outbound echo cache is untouched. Twin check: messageUpdate/votes/consent/reactions run dedicated non-agent workflows and are excluded from the journal. Autoreview blocked by codex sandbox network in the build stage; full manual review performed. Part of the #109657 fleet adoption program (wave 2).
…patch Three defects found in landing review: the live turn context could swap a duplicate delivery's mutated activity in place of the journaled payload (dispatch now always uses the journaled activity, live context is transport surface only); the context registry installed entries after the durable append, leaking them when the drain consumed the claim first (install now precedes enqueue, tombstoned duplicates clean up, first delivery's context wins); and a failed next() in the message handler was invoked a second time from the catch fall-through (ran-flag guards it).
Follow-up to the install-before-enqueue race fix: an enqueue rejection bypassed cleanup, so a retry with the same activity id dispatched the failed request's stale context. Uninstall is identity-guarded (only our context is removed, never a concurrent redelivery's fresh install) and covers both the throw and tombstoned-duplicate paths. Regression proves the retry's own context dispatches.
…the settled variant
|
Codex review: needs real behavior proof before merge. Reviewed July 18, 2026, 12:29 AM ET / 04:29 UTC. Summary PR surface: Source +587, Tests +580. Total +1167 across 9 files. Reproducibility: no. high-confidence live reproduction is included. The replay defect is source-reproducible from the new context construction and the established no-context root-thread fallback described in the review discussion. Review metrics: none identified. Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Proof guidance:
Risk before merge
Maintainer options:
Next step before merge
Security Review findings
Review detailsBest possible solution: Preserve Do we have a high-confidence way to reproduce the issue? No high-confidence live reproduction is included. The replay defect is source-reproducible from the new context construction and the established no-context root-thread fallback described in the review discussion. Is this the best way to solve the issue? No; durable admission is the right boundary, but the replay context must preserve the channel-root activity id before this is a complete solution, and live Teams proof must validate the transport behavior. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against cc9c2c7cca7f. Label changesLabel changes:
Label justifications:
Evidence reviewedPR surface: Source +587, Tests +580. Total +1167 across 9 files. View PR surface stats
What I checked:
Likely related people:
What the crustacean ranks mean
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics. How this review workflow works
Review history (3 earlier review cycles)
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2b8cb5c649
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const threadActivityId = | ||
| conversationType.toLowerCase() === "channel" | ||
| ? (extractMSTeamsConversationMessageId(rawConversationId) ?? activity.replyToId) | ||
| : undefined; |
There was a problem hiding this comment.
Preserve channel root thread id during replay
When a replayed channel message is a top-level thread root, conversation.id can be just the base channel id and replyToId is unset; existing no-context sending deliberately falls back to conversationRef.activityId for this case (extensions/msteams/src/messenger.ts), but this replay context always provides a sendActivity and only sets threadActivityId from ;messageid= or replyToId. After a restart, replies for those queued root-channel turns are sent proactively with no thread suffix, so they can land outside the user's thread instead of replying to the recovered activity.
Useful? React with 👍 / 👎.
ReturnType<typeof vi.fn> types the implementation callback void-returning, so every promise-returning accept mock tripped typescript(no-misused-promises) in CI regardless of call-site shape.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f103dcb84e
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const eventId = nonEmptyString(activity.id); | ||
| if (!eventId) { | ||
| throw new MSTeamsIngressPayloadError( | ||
| "invalid-activity", | ||
| "Microsoft Teams dispatchable activity is missing activity.id.", |
There was a problem hiding this comment.
Avoid rejecting idless Teams activities
When a dispatchable Teams/Bot Framework activity arrives without id, this new admission path throws before queue.enqueue, so the message/card-action webhook returns 500 instead of dispatching. The local MSTeamsActivity type and the Microsoft Bot Framework Activity docs both model id as optional (id?: string; see https://learn.microsoft.com/en-us/javascript/api/botframework-schema/activity?view=botbuilder-ts-latest#id), and the old handler still had an activity.id ?? ... fallback when recording the inbound turn; idless deliveries can therefore get stuck in redelivery instead of reaching the agent unless durability uses a fallback key or explicitly passes them through non-durably.
Useful? React with 👍 / 👎.
* fix(msteams): adopt durable ingress drain with ack gated on activity append Bot Framework webhooks acked before detached processing with no platform retry, silently losing inbound activities on a crash. Dispatchable activities (message + adaptiveCard/action invokes) now persist their raw JSON durably (event_id = activity.id per the @microsoft/teams.api uniqueness contract, lane = conversation.id) before the webhook 200; dispatch runs through the core drain with deferred claims through debounce, merged-flush fan-out adoption, gated-turn settlement, retry/dead-letter classification, and 30d/20k tombstones. Restart replay reconstructs proactive routing context. No inbound replay guard existed; the outbound echo cache is untouched. Twin check: messageUpdate/votes/consent/reactions run dedicated non-agent workflows and are excluded from the journal. Autoreview blocked by codex sandbox network in the build stage; full manual review performed. Part of the #109657 fleet adoption program (wave 2). * fix(msteams): close live-context races and double next() in drain dispatch Three defects found in landing review: the live turn context could swap a duplicate delivery's mutated activity in place of the journaled payload (dispatch now always uses the journaled activity, live context is transport surface only); the context registry installed entries after the durable append, leaking them when the drain consumed the claim first (install now precedes enqueue, tombstoned duplicates clean up, first delivery's context wins); and a failed next() in the message handler was invoked a second time from the catch fall-through (ran-flag guards it). * fix(msteams): uninstall a failed append's live context before retry Follow-up to the install-before-enqueue race fix: an enqueue rejection bypassed cleanup, so a retry with the same activity id dispatched the failed request's stale context. Uninstall is identity-guarded (only our context is removed, never a concurrent redelivery's fresh install) and covers both the throw and tombstoned-duplicate paths. Regression proves the retry's own context dispatches. * test(msteams): track the buffered dispatcher seam after main retired the settled variant * test(msteams): resolve dispatch union before catch for promise lint * test(msteams): explicit promise-returning mock for the promise-misuse lint * test(msteams): type the ingress accept mock promise-returning ReturnType<typeof vi.fn> types the implementation callback void-returning, so every promise-returning accept mock tripped typescript(no-misused-promises) in CI regardless of call-site shape. * test(msteams): restore compact async mock now that its type permits promises * test(msteams): extract gated-accept helper to stay under max-lines
…w#110357) * fix(msteams): adopt durable ingress drain with ack gated on activity append Bot Framework webhooks acked before detached processing with no platform retry, silently losing inbound activities on a crash. Dispatchable activities (message + adaptiveCard/action invokes) now persist their raw JSON durably (event_id = activity.id per the @microsoft/teams.api uniqueness contract, lane = conversation.id) before the webhook 200; dispatch runs through the core drain with deferred claims through debounce, merged-flush fan-out adoption, gated-turn settlement, retry/dead-letter classification, and 30d/20k tombstones. Restart replay reconstructs proactive routing context. No inbound replay guard existed; the outbound echo cache is untouched. Twin check: messageUpdate/votes/consent/reactions run dedicated non-agent workflows and are excluded from the journal. Autoreview blocked by codex sandbox network in the build stage; full manual review performed. Part of the openclaw#109657 fleet adoption program (wave 2). * fix(msteams): close live-context races and double next() in drain dispatch Three defects found in landing review: the live turn context could swap a duplicate delivery's mutated activity in place of the journaled payload (dispatch now always uses the journaled activity, live context is transport surface only); the context registry installed entries after the durable append, leaking them when the drain consumed the claim first (install now precedes enqueue, tombstoned duplicates clean up, first delivery's context wins); and a failed next() in the message handler was invoked a second time from the catch fall-through (ran-flag guards it). * fix(msteams): uninstall a failed append's live context before retry Follow-up to the install-before-enqueue race fix: an enqueue rejection bypassed cleanup, so a retry with the same activity id dispatched the failed request's stale context. Uninstall is identity-guarded (only our context is removed, never a concurrent redelivery's fresh install) and covers both the throw and tombstoned-duplicate paths. Regression proves the retry's own context dispatches. * test(msteams): track the buffered dispatcher seam after main retired the settled variant * test(msteams): resolve dispatch union before catch for promise lint * test(msteams): explicit promise-returning mock for the promise-misuse lint * test(msteams): type the ingress accept mock promise-returning ReturnType<typeof vi.fn> types the implementation callback void-returning, so every promise-returning accept mock tripped typescript(no-misused-promises) in CI regardless of call-site shape. * test(msteams): restore compact async mock now that its type permits promises * test(msteams): extract gated-accept helper to stay under max-lines
Google Chat webhook acked with HTTP 200 before dispatching the event via runDetachedWebhookWork, with no journal anywhere: a gateway crash between the ack and dispatch permanently lost the user message, and Google does not retry webhooks. MESSAGE events now persist durably in the shared-state channel ingress queue (event_id = message resource name, lane = space) before the 200 is sent; admission failure answers 500 instead of a false ack. The monitor drains through the core channel ingress drain with turn-adoption lifecycle wired into inbound.run, replaying journaled events on startup and tombstoning them only after adoption. CARD_CLICKED approvals and space lifecycle events run dedicated non-agent workflows and keep the detached path, matching the msteams openclaw#110357 journal boundary. Mirrors the sms openclaw#109866 spool shape.
Matrix advances the /sync token before inbound events finish dispatching (matrix-js-sdk doSync sets the token first, then the plugin's SQLite sync store persists it), while room messages were dispatched into a memory-only detached queue for the full agent-turn duration. A gateway crash or restart in that window permanently lost the user message: the next /sync told the homeserver the batch was consumed. Journal every dispatchable inbound event into the shared channel ingress queue (channel_ingress_events, no schema change) synchronously inside the sync event listener — before the debounced token persist can land — and dispatch through the core durable ingress drain with per-room lanes, complete-at-adoption via the canonical turnAdoptionLifecycle reply-options seam, bounded retry/dead-letter, and restart replay. The existing persistent inbound deduper keeps redelivered events exactly-once. Events without an event id keep the previous live-dispatch path. Mirrors the durable-ingress fleet adoption (openclaw#109657): telegram openclaw#108924, discord openclaw#110274, whatsapp openclaw#110418, mattermost openclaw#110386, msteams openclaw#110357. Co-Authored-By: Claude <[email protected]>
Related: #109657
AI-assisted implementation; maintainer-reviewed and validated.
What Problem This Solves
Fixes an issue where Microsoft Teams users could silently lose inbound agent activities when the process stopped after Bot Framework received a webhook but before detached processing adopted the turn. The webhook returned success without durable admission, so Bot Framework had no reason to retry; severity was HIGH because the loss was silent.
Why This Change Was Made
Microsoft Teams now adopts the shared durable channel-ingress drain. Dispatchable activities use
activity.idas the event ID, matching the@microsoft/teams.apicontract that it uniquely identifies an activity on the channel, andconversation.idas the serialization lane. The webhook acknowledgement waits for durable append, while downstream work uses deferred claims and merged-debounce fan-out adoption following the proven Signal pattern.The adapter journals message turns and adaptive-card agent turns only.
messageUpdate, poll votes, file consent, reactions, and other dedicated non-agent workflows remain outside the ingress journal.Landing review also fixed live-context payload substitution, an install/append race and leak, duplicate
next()invocation, stale context after failed append, and the test seam renamed whenmainretired the settled dispatcher.User Impact
Accepted Microsoft Teams agent activities survive process interruption and replay after restart instead of disappearing after an early webhook acknowledgement. Conversation ordering remains serialized, debounced turns settle every constituent claim, and non-agent Teams workflows retain their existing behavior.
Evidence
msteams-ingress, message-handler ingress lifecycle, monitor lifecycle, and adaptive-card handling.node scripts/check-deadcode-exports.mjsandnode scripts/check-deadcode-unused-files.mjsboth reported zero entries;git diff --checkpassed.