Skip to content

fix(msteams): reset isolated DM context after app removal - #168797

Open
jimmypuckett wants to merge 1 commit into
openclaw:mainfrom
jimmypuckett:codex/msteams-account-aware-removal-99054
Open

jimmypuckett wants to merge 1 commit into
openclaw:mainfrom
jimmypuckett:codex/msteams-account-aware-removal-99054

Conversation

@jimmypuckett

@jimmypuckett jimmypuckett commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Related: #99054. Follows the closed Teams lifecycle proposals #100371 and #104690.

This is the smaller, account-aware follow-up to those attempts. It uses the existing session lifecycle API and replaces the previous proposal for a new public reset capability. The prior PRs remain available for their discussions and historical proof; their published branches are unchanged.

What Problem This Solves

Fixes retained pre-removal context when a Microsoft Teams bot/app is uninstalled from an isolated personal chat and later reinstalled.

User Impact

The removed installation’s isolated DM starts a fresh session after reinstall. Historical transcript content is archived through the existing owner. Shared main/per-peer sessions, sessions shared by bot accounts, and model-locked sessions remain intact and are logged. Retiring an entry also clears its session preferences. Ordinary upgrades, install-add events, other members leaving, and Teams local Remove chat history keep their existing behavior. There is no new configuration or public SDK API.

Why This Change Was Made

Removal events enter Teams durable ingress. Cleanup routes the stored DM owner with the bot’s account, then uses the existing session lifecycle API to archive and delete the active entry. Failure retains the conversation reference for retry; failed durable admission rejects the webhook request. The implementation stays within the Teams plugin.

Evidence

  • Historical live Teams signal evidence: uninstall/reinstall and local clear-history capture. This exercises the earlier implementation, not this head's archival/deletion path.
  • Historical canonical-owner and authority tests: exact-head redacted packet at fc3e2b425251. The earlier reset contract differs from this head's deletion contract, so its authority proof is historical only.
  • Three new routing/admission regression cases fail against pinned unpatched upstream 76a282c7a1c6ca958517ce15f13e17371c14be11.
  • 71 focused tests passed, covering real SQLite session/conversation storage, account and agent isolation, transcript archival, retry failure, restart/redelivery, webhook lifecycle, and adaptive-card behavior (31.54 seconds locally).
  • After extracting transport coverage and correcting its replay context fixture, all 28 cases in the affected test files passed with one worker in 46.78 seconds: node scripts/run-vitest.mjs extensions/msteams/src/monitor-handler/lifecycle-handler.test.ts extensions/msteams/src/msteams-ingress.test.ts extensions/msteams/src/monitor.removal.test.ts --maxWorkers=1.
  • The full packaged build passed, including external plugins and SDK declarations/exports. Production and test type checks passed.
  • Whole-tree checks remain red on unchanged upstream unused exports and an unchanged Crabbox file exceeding its line limit. All candidate unused-export findings reproduce in the exact upstream snapshot; reported source files match upstream byte for byte.
  • Authored Teams lint, script lint, formatting, storage/media/loader guards, and import-cycle checks passed.
  • Independent Codex review returned one P2 concern about completion of removal ingress. It was ruled out: the existing ingress monitor automatically adopts successful non-deferred returns. The strengthened real-queue restart/redelivery regression passed without an explicit adoption callback (1 test; 9.29-second shard). No accepted/actionable findings remain. The canonical ingress owner completes successful non-deferred returns; no explicit reply-lane adoption is required.
  • Live Teams validation has not been repeated for this implementation. Historical live results belong to the earlier published version; hosted CI duration is unmeasured. The serial boundary tests use real session/queue storage because routing, archival, rollback, and durable replay are the contracts under test.
  • Proof was collected on pinned upstream 76a282c7a1c6ca958517ce15f13e17371c14be11. Upstream advanced afterward without changing any authored path; the published patch tree matches the reviewed and tested candidate exactly. Full monorepo pnpm check/pnpm test and fresh live Teams proof were not run. Broad plugin lint and the changed-file gate were run and retain the inherited failures described above.

Current review gaps at 5ebed9858af6203c31400509362fce56524fabcb: fresh authenticated Teams uninstall/reinstall and readable archived-history proof; delayed retired/reassigned-account rejection; the unrelated unbound-sibling routing finding; and latest-stable upgrade/preferences proof. The prior maintainer preference-preservation direction still needs resolution because this implementation deletes the active entry and its preferences. Historical proof does not clear these current-head blockers.

Route durable removal events through account-aware stored DM ownership and the existing session lifecycle API. Archive retired transcripts; preserve shared and model-locked sessions.

Related: openclaw#99054
Follow-up to openclaw#100371 and openclaw#104690.
@clawsweeper

clawsweeper Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation channel: msteams Channel integration: msteams labels Oct 11, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 11, 2026
@clawsweeper

clawsweeper Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

This PR durably processes Teams app removals and archives isolated personal sessions through the existing session deletion API.

Example: Uninstall the office bot after storing OLD_OFFICE_HISTORY in agent:office:msteams:office:direct:aad-dm-owner.

  • Before: Reinstalling the bot reuses the active session and its prior context.
  • After: The proposed cleanup archives the transcript and deletes the active entry, including its preferences, while retaining the research bot’s session.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The focused owner-based implementation has meaningful storage coverage, but remains incorrect for an unbound sibling configuration and is not ready under the required behavior and compatibility gates.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🦐 gold shrimp (3/6) Security review found an item that needs attention.

Product

Kind: Bug fix · Worth it: Needs a maintainer decision · Fix scope: Partial
User problem: A reinstalled Teams bot can recall conversation context from its removed personal installation.
Reason: The scoped reset has clear value, but deliberately clearing preferences departs from recorded direction; shared and locked sessions remain outside the reset.

Merge readiness

⛔ Blocked before merge - 6 items remain

This PR addresses an unresolved Teams lifecycle bug and merits continued review; the existing routing finding and preference-policy disagreement remain unresolved.

Priority: P2
Reviewed head: 5ebed9858af6203c31400509362fce56524fabcb
Owner decision: Required. See Decision needed.

Decision needed

  • Question: May app removal clear isolated DM preferences, departing from the prior preference-preservation direction?
  • Recommendation: Preserve preferences: Follow the recorded direction with a canonical lifecycle transition that clears conversation context while retaining approved session preferences.
  • Why: The prior review requested preservation, while this new deletion-based implementation deliberately clears preferences and has no recorded approval for that departure.

Before merge

  • Add real behavior proof - Authority-chain proof required: exercise authenticated Teams removal through durable ingress and canonical archival/deletion, showing owning-bot success and rejection before persistent effects for another bot and retired or reassigned account authority. Current-head evidence consists of real-storage tests; inspected screenshots document the original report, and historical live logs exercise different implementations. Provide fresh uninstall/reinstall logs or a recording showing fresh context, no old-marker recall, and readable archived history; redact credentials, IPs, phone numbers, and non-public endpoints. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Avoid resolving unrelated unbound accounts during removal (P2) - With multiple explicitly owned agents, a valid office binding, and a configured research account without a matching binding or default owner, this loop calls resolveAgentRoute for research and throws AgentSelectionRequiredError. The office removal then fails before deleting its isolated session or conversation reference, so retry keeps encountering the unrelated routing error and reinstall can retain old context. Determine sharing only from routes that actually resolve, using the current full account policy, and add this configuration to the regression coverage. This is the previously reported finding and remains unfixed.
  • Resolve security concern: Delayed account authority is not established - The handler checks account configuration before awaited storage work, while deletion validates session and database identity rather than bot-account authority. Show that another bot and a retired or reassigned runtime cannot archive or delete the protected session, including retirement during the awaited cleanup path.
  • Resolve merge risk - Before merge, establish that account retirement or reassignment during delayed cleanup prevents the old bot runtime from archiving or deleting protected session state.
  • Resolve maintainer decision - Resolve the maintainer decision shown above before merge.
  • Add data-model compatibility proof - The review found that existing stored data may not work after upgrade. Show that existing data still loads and works with this change.

Findings

  • [P2] Avoid resolving unrelated unbound accounts during removal — extensions/msteams/src/monitor-handler/lifecycle-handler.ts:64-66
  • [medium] Delayed account authority is not established — extensions/msteams/src/monitor-handler/lifecycle-handler.ts:90

Tests

  • Missing end-to-end proof: Supply fresh authenticated uninstall/reinstall evidence through this head’s archival/deletion path, including readable archived history; reported baseline-failing routing/admission regressions support the patch but do not prove that shipped flow.
Agent review details

How this fits together

Authenticated Teams activities enter account-scoped durable ingress; the lifecycle handler resolves the stored DM owner and requests persistent session cleanup from the canonical session owner.

flowchart TD
  A[Teams removal activity] --> B[Authenticated SDK route]
  B --> C[Durable ingress queue]
  C --> D[Teams lifecycle handler]
  D --> E[Stored conversation and account route]
  E --> F[Canonical session lifecycle]
  F --> G[Archived transcript and retired entry]
Loading

Technical review

Best possible solution:

Reset isolated Teams context through the canonical lifecycle owner, preserve the agreed preferences and readable archives, and keep unrelated accounts from blocking cleanup.

Do we have a high-confidence way to reproduce the issue?

Current main has no removal cleanup path, and the linked report’s authenticated capture establishes that true Teams app uninstall emits removal activities; no target code was executed during this review.

Is this the best way to solve the issue?

Reusing durable ingress and the canonical lifecycle owner is sound, but deletion changes preference retention and the sharing check must tolerate unrelated unbound accounts.

Full review comments:

  • [P2] Avoid resolving unrelated unbound accounts during removal — extensions/msteams/src/monitor-handler/lifecycle-handler.ts:64-66
    With multiple explicitly owned agents, a valid office binding, and a configured research account without a matching binding or default owner, this loop calls resolveAgentRoute for research and throws AgentSelectionRequiredError. The office removal then fails before deleting its isolated session or conversation reference, so retry keeps encountering the unrelated routing error and reinstall can retain old context. Determine sharing only from routes that actually resolve, using the current full account policy, and add this configuration to the regression coverage. This is the previously reported finding and remains unfixed.
    Confidence: 0.98

Overall correctness: patch is incorrect
Overall confidence: 0.96

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 3f8eb34c538e.

Merge-risk options

Maintainer options:

  1. Establish current account authority at deletion (recommended)
    Exercise delayed removal through the real owners, retire or reassign the bot account before persistent cleanup, and ensure protected state remains intact; repair the effect-boundary check if it fails.
  2. Pause persistent cleanup
    Keep the PR open while the account-authority contract is resolved rather than landing an unproven deletion path.

Provenance checked

Testing

Proof path: in-process harness.

Security

Needs attention: Persistent cleanup still needs account-authority verification at the final effect.

Evidence

Security concerns:

  • [medium] Delayed account authority is not established — extensions/msteams/src/monitor-handler/lifecycle-handler.ts:90
    The handler checks account configuration before awaited storage work, while deletion validates session and database identity rather than bot-account authority. Show that another bot and a retired or reassigned runtime cannot archive or delete the protected session, including retirement during the awaited cleanup path.
    Confidence: 0.92

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit c163daa adds extensions/msteams/src/msteams-ingress.ts:162 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: c163daa4ed02; files: extensions/msteams/src/msteams-ingress.ts)

PR surface

Source +126, Tests +547, Docs +12. Total +685 across 10 files. Added test files: 2.

View PR surface stats
Area Files Added Removed Net
Source 5 128 2 +126
Tests 4 549 2 +547
Docs 1 12 0 +12
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 10 689 4 +685

Review metrics

Metric Value Why it matters
Production versus test growth Production +128/-2; tests and test support +549/-2 Most growth exercises real session storage, archival, account isolation, and durable replay; these distinct persistence contracts justify stronger boundary coverage.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #99054
Summary: This PR is the active candidate for the canonical Teams uninstall context-retention report; earlier proposals were closed without merging.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: The change addresses retained context after Teams app removal with a limited channel and session-scope blast radius.
  • merge-risk: 🚨 session-state: Removal deletes persisted session entries and preferences, and the sibling-routing defect can leave old context active.
  • merge-risk: 🚨 security-boundary: Durable removal authorizes persistent cleanup across bot-account and session boundaries; delayed retirement or reassignment rejection remains unproven.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Show this implementation handling authenticated Teams uninstall/reinstall with fresh context and readable archived history.
  • Add final-effect proof that another bot and retired or reassigned account authority cannot archive or delete the protected session.
  • Upgrade from v2026.10.1 and verify existing sessions, preferences, and sibling-account data follow the agreed policy.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only; repair and merge need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

History

Review history (2 earlier review cycles)
  • reviewed 2026-10-11T01:35:19.265Z sha 5ebed98 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-11T01:45:46.003Z sha 5ebed98 :: needs real behavior proof before merge. :: [P2] Avoid resolving unrelated unbound accounts during removal

Reviewed October 10, 2026, 10:09 PM ET / October 11, 2026, 02:09 UTC (Revision 3).

@jimmypuckett
jimmypuckett marked this pull request as ready for review October 11, 2026 01:39
@jimmypuckett

Copy link
Copy Markdown
Contributor Author

Proof continuity for reviewed head 5ebed9858af6203c31400509362fce56524fabcb:

I retrieved the evidence from the closed proposals and have linked the specific proof packets below. This separates historical Teams observations from validation of this smaller implementation.

Historical live Teams proof: #100371 uninstall/reinstall capture records a synthetic marker before app-management uninstall, installationUpdate action=remove, removal-handler execution, a changed session identity, and no marker recall after reinstall. The same capture records that Teams local Remove chat history emitted no lifecycle event and reused the prior session. This establishes the observed Teams signal and scope limitation. It exercised the earlier session-rotation implementation, so it does not establish this head's canonical archival/deletion or account-authority behavior.

Historical owner/authority proof: #104690 exact-head packet identifies fc3e2b425251d8fc7504488eff3842a1817a1cbe, links the real-store and final-effect tests, and includes redacted terminal results for removal/reinstall, transcript transition, unauthorized callers, revoked/replaced runtimes, and revocation during owner reset. Those tests cover the older lifecycle-reset contract; they cannot be transferred to this head's existing deleteSessionEntry path as fresh security proof.

Current implementation evidence: The real-storage removal regression exercises actual activity-handler dispatch, account-aware routing and SQLite session/conversation storage. It asserts removal of the owning active entry and old active transcript, creation of an archived artifact, preservation of sibling/default context, and harmless duplicate removal after a fresh session is allocated. Additional cases cover another bot's recipient, shared/locked sessions, and deletion failure retaining the reference for retry. The durable restart/redelivery test verifies persisted removal replay completes without an explicit adoption callback and deduplicates redelivery.

Previously collected proof for this exact source tree: 71 focused tests passed; all 28 affected-file cases passed serially in 46.78 seconds; the packaged build and production/test type checks passed. Reproduction command:

node scripts/run-vitest.mjs extensions/msteams/src/monitor-handler/lifecycle-handler.test.ts extensions/msteams/src/msteams-ingress.test.ts extensions/msteams/src/monitor.removal.test.ts --maxWorkers=1

Still outstanding: Fresh authenticated uninstall/reinstall proof on this head, readable archived-history verification, delayed retired/reassigned-account rejection, the unrelated unbound-sibling routing finding, and latest-stable upgrade/preferences proof remain open. The prior maintainer direction explicitly asked to preserve preferences; this smaller deletion approach currently clears them, as documented. That difference still needs resolution with the owner. The earlier packets do not clear these blockers, and this comment does not claim new live proof or a repaired patch.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: msteams Channel integration: msteams docs Improvements or additions to documentation merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: L status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant