fix(msteams): reset sessions on app removal lifecycle#100371
fix(msteams): reset sessions on app removal lifecycle#100371jimmypuckett wants to merge 8 commits into
Conversation
|
Codex review: needs changes before merge. Reviewed July 10, 2026, 2:55 PM ET / 18:55 UTC. Summary PR surface: Source +423, Tests +575. Total +998 across 8 files. Reproducibility: yes. Create a matching Teams session entry with Review metrics: 1 noteworthy metric.
Stored data model Root-cause cluster Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Risk before merge
Maintainer options:
Copy recommended automerge instructionNext step before merge
Maintainer decision needed
Security Review findings
Review detailsBest possible solution: Rotate every matching session regardless of its existing timestamp, retain the compare-and-swap protection, add provider-bound zero-timestamp regression coverage, and explicitly approve the non-destructive transcript-retention boundary. Do we have a high-confidence way to reproduce the issue? Yes. Create a matching Teams session entry with Is this the best way to solve the issue? No, not yet. Route-derived atomic replacement is the right solution shape and is stronger than the competing stale-only implementation, but it must also rotate zero-timestamp provider-bound entries. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 7af7e41eedf4. Label changesLabel changes:
Label justifications:
Evidence reviewedPR surface: Source +423, Tests +575. Total +998 across 8 files. View PR surface stats
Security concerns:
Acceptance criteria:
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 (6 earlier review cycles)
|
|
I pushed a follow-up that tightens the implementation and updates the proof packet. What changed since the first draft:
Live app-management removal proof: Live So this PR intentionally fixes the observable Teams app lifecycle boundaries and changed-conversation-id boundary. It does not claim to fix Teams local Validation: @clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
Reviewed at Confirmed the gap on Two non-blocking notes:
One process point for maintainers: #100350 targets the same two lifecycle events with a mark-stale-only, personal-DM-only approach and a hardcoded |
…x/msteams-lifecycle-session-reset-99054
…x/msteams-lifecycle-session-reset-99054
…ycle-session-reset-99054
…ycle-session-reset-99054
…ycle-session-reset-99054
…ycle-session-reset-99054 # Conflicts: # extensions/msteams/src/monitor-handler/message-handler.ts
|
Maintainer note: these existing PRs were opened from the Spinen organization fork, and I learned that GitHub's normal "allow edits from maintainers" flow may not work reliably for org-owned forks. For future OpenClaw PRs, I'll open from my personal fork so maintainer edits work normally. For this existing batch, I want to make collaboration as easy as possible. I've invited @steipete as a temporary Write collaborator on My goal is to make these branches easy to finish, not to create extra process. |
Closes #99054
What Problem This Solves
Fixes an issue where Microsoft Teams users who remove a personal app/bot and later add it again can continue the same OpenClaw server-side DM session, allowing the bot to use prior conversation context after an app lifecycle boundary.
This targets Teams app-management lifecycle signals that the bot can actually observe. Live capture showed Teams' local "Remove chat history" action can arrive later as an ordinary message in the same personal
conversation.id, with noinstallationUpdate,conversationUpdate,membersAdded, ormembersRemovedactivity. This PR does not claim to detect that fully local clear-chat action when Teams gives the bot no lifecycle or conversation-boundary signal.Why This Change Was Made
Teams now routes
installationUpdateremoval activities and botmembersRemovedconversation updates into a lifecycle handler. On a removal boundary, the handler removes the cached Teams conversation reference, rotates the matching OpenClaw session entry to a new session id withupdatedAt: 0, and clears provider-owned route/delivery/origin metadata so the next inbound message cannot resume the removed chat transcript.The handler also treats a personal
installationUpdate action=addas a reinstall boundary only when an existing route-matched Teams DM session is already active. That catches tenants or flows where the re-add signal is visible but the prior remove signal was missed, without resetting first-time installs. Finally, inbound personal DMs check for a stored same-user/same-bot conversation reference with a different Teamsconversation.id; when Teams exposes that boundary, OpenClaw removes the previous reference and rotates the DM session.User Impact
After a true Teams app removal and re-add, the next inbound message starts from a fresh OpenClaw session instead of silently resuming prior DM or channel context. Operators also avoid retaining a cached proactive-send reference for the removed Teams conversation.
For Teams clear-chat/reopen flows, the patch protects the observable case where Teams gives the bot a new personal conversation id. If Teams reuses the same server-side conversation id and sends no lifecycle event, there is no bot-visible signal in the captured payloads; that remains a Teams platform limitation rather than a claim made by this PR.
Existing welcome-card behavior, normal messages, reactions, and unrelated lifecycle events are unchanged.
Evidence
installationUpdate action=remove.msteams lifecycle remove handled,reason=installation-remove,conversationType=personal,conversationRemoved=true,sessionsReset=1.updatedAt: 0and no Teams route/delivery/origin metadata.Remove chat historyfollow-up after deploying this branch:Remove chat history, opened the app/chat again, and sent a verification prompt.installationUpdate add, lifecycle/remove activity, or DM conversation-boundary handler log appeared.installationUpdate/removeinstallationUpdate/remove-upgradeinstallationUpdate/addwith no active sessioninstallationUpdate/addwhen an existing session is activeinstallationUpdate/addmembersRemovedmembersRemovedinstallationUpdateandmembersRemovedactivities to registered lifecycle handlers.pnpm test extensions/msteams/src/monitor-handler/lifecycle-handler.test.ts- 11 tests passed.pnpm test extensions/msteams/src/monitor-handler/message-handler.authz.test.ts- 18 tests passed.pnpm test extensions/msteams- 71 files passed, 1007 tests passed.pnpm run lint:extensions:bundled- passed.pnpm format:check extensions/msteams/src/monitor-handler/lifecycle-handler.ts extensions/msteams/src/monitor-handler/lifecycle-handler.test.ts extensions/msteams/src/monitor-handler/message-handler.ts- passed.git diff --check- passed.