Repository navigation
fix(msteams): make thread-vs-top-level replies deterministic (ENG-17134) - #95
Conversation
Teams threading is only the `;messageid=<root>` suffix on the conversation id. SharePoint/OneDrive file-link sends, Adaptive Cards, and polls bypassed the resolved replyStyle via a raw proactive send that never passed the thread anchor, so any reply carrying a doc link or card landed at channel root regardless of config. Centralizes thread-root resolution into resolveMSTeamsThreadActivityId (sdk-proactive.ts), consumed by every proactive send path, and fixes a real case-sensitivity bug where the old check compared conversationType with a raw === "channel" while send-context.ts normalized to lowercase. Co-Authored-By: Claude Opus 5 <[email protected]>
|
Claude encountered an error —— View job I'll analyze this and get back to you. |
There was a problem hiding this comment.
cubic analysis
All reported issues were addressed across 14 files
Linked issue analysis
| Status | Acceptance criteria | Notes |
|---|---|---|
| ✅ | Threading decision is deterministic (same ref + replyStyle → same threading decision, independent of payload or context-window pressure) | Thread-anchor resolution was centralized in resolveMSTeamsThreadActivityId and used by all proactive send paths; decision is based only on stored ref + replyStyle, not payload or context pressure. |
| ✅ | SharePoint / OneDrive document-link sends post in-thread (do not drop thread suffix) | File-link branches no longer bypass the thread-anchor; uploaded-file link sends are forwarded through sendMSTeamsMessages with the resolved thread anchor instead of a raw proactive send that would strip the suffix. |
| ✅ | Adaptive Cards / presentation cards and polls honor same threading decision as text sends (cards/polls thread with text) | Presentation/card and poll sends were changed to accept and forward replyStyle/threadActivityId so they thread identically to text sends; tests assert replyStyleOverride and threadActivityId are forwarded and that thread-suppressed mapping is applied. |
| ✅ | Explicit top-level initiation still works (topLevel: true / replyStyle: top-level) | Per-send top-level override (topLevel / threadId:null) is converted to replyStyleOverride and honored; top-level sends omit the thread suffix intentionally. |
| Per-host / custom instruction override is respected (replyStyle overrides are honored) | The PR preserves and forwards replyStyle / replyStyleOverride from the send-context into all proactive paths so operator or per-send overrides continue to take effect. However, there is no single unit test explicitly named for per-host/custom instruction semantics in this diff; the plumbing to carry overrides is present and tested indirectly via replyStyleOverride tests. |
Reply with feedback, questions, or to request a fix.
Fix all with cubic | Re-trigger cubic
There was a problem hiding this comment.
Approved. Root cause is correct and the fix is clean.
Diagnosis is right. Teams threading is only the ;messageid=<root> suffix, and resolveThreadedConversationId strips it when the anchor is absent — so any send path that skipped the anchor silently posted at channel root. The SharePoint/OneDrive/card/poll branches went out via a raw proactive send that never carried the thread anchor even though resolveMSTeamsSendContext had already resolved it. That's exactly why "produced a doc link" and "abandoned the thread" were the same event. Correctly refutes the original context-window-exhaustion diagnosis.
Architecture: strong. Centralizing the decision into one resolveMSTeamsThreadActivityId (ref + replyStyle → anchor) consumed by every proactive shape is the right move — it makes "forgot to pass the anchor" structurally impossible rather than whack-a-mole per call site. The dedup of the three copy-pasted topLevel→replyStyleOverride blocks into resolveMSTeamsActionReplyStyleOverride, and folding the SharePoint/OneDrive branches into a single upload path, both reduce debt. Net -55 non-test LOC.
Tests: thorough. The suffix append/strip mechanism is locked, the resolver table covers channel/groupChat/personal/casing/missing-type, and the file-link tests assert the raw proactive send is NOT used (the actual bug shape). The case-sensitivity fix ("Channel" vs normalized "channel") is a real latent bug caught along the way and is regression-tested.
cubic's two P2s were addressed correctly: poll replyStyleOverride would be dead surface until the core poll contract carries threading intent (real follow-up, not this PR); the depth-threshold ask is genuinely out of scope (Graph exposes no reply-count and paginates oldest-first capped at 50 — not implementable on this surface) and belongs to ENG-15745. Both deferrals are documented in code + inline.
One honest gap, correctly flagged by the author: no live Crabbox Teams proof — dev env has no working provider (no az/blacksmith). Landing on unit tests + autoreview. Given the change is a deterministic string-suffix routing decision fully exercised by the resolver + send-path tests, that's an acceptable proof level for merge; a smoke check on a real Teams channel after deploy would close it out.
Traces cleanly to ENG-17134, all 4 hard ACs met, CI green, signed. Ship it.
What Problem This Solves
The Boon agent non-deterministically replies to MS Teams thread messages with new top-level channel messages instead of staying in-thread, reported more frequently when the agent produces SharePoint document links. This makes threaded conversations hard to follow.
Why This Change Was Made
The reported diagnosis attributed this to a base-instruction stop-gap tied to context-window exhaustion. That does not hold up against the code: no such instruction exists anywhere in this fork's system-prompt builder, in the fleet's shipped
AGENTS.md/SOUL.mdpersonas, or in the config templates that generate agent configuration — verified by direct inspection of all three.The real cause is fully deterministic. MS Teams threading is only the
;messageid=<root>suffix on the conversation id (resolveThreadedConversationIdinsdk-proactive.ts) — a send that omits this anchor strips any existing suffix and posts at channel root, regardless of thereplyStyleconfig. The SharePoint and OneDrive file-link branches insend.tscalled a raw proactive send that never read the resolvedreplyStyleand never passed the thread anchor, even thoughresolveMSTeamsSendContexthad already resolved it correctly two lines earlier. That is exactly why "the agent produced a doc link" and "the agent abandoned the thread" were the same observed event — same branch. Adaptive Cards and polls had the identical bug.This PR centralizes thread-root resolution into one function,
resolveMSTeamsThreadActivityId(sdk-proactive.ts), consumed by every proactive send path (text, media, uploaded-file link, card, poll), so the threading decision can no longer depend on payload shape or be silently dropped by a bypass branch. It also fixes a real case-sensitivity bug uncovered along the way: the oldmessenger.tscheck comparedconversationType === "channel"case-sensitively whilesend-context.tsnormalized to lowercase, so a ref stored with"Channel"would resolvereplyStyle: "thread"and then get no suffix anyway.Deliberately out of scope, with rationale:
conversationId/threadIdlast-seen-wins behavior in the conversation store is intentionally left as-is — preserving it would pin later replies to a stale thread after a legitimate top-level post. Documented inline and locked with a regression test.action-runtime.ts) are a related but distinct bug class, tracked under ENG-16509.User Impact
MS Teams replies — including ones carrying SharePoint/OneDrive document links, Adaptive Cards, and polls — now stay in the same thread they were replying to, deterministically, independent of context-window pressure or payload shape.
topLevel: true/ cronreplyStyle: "top-level"still work correctly for intentional new-conversation posts.Evidence
extensions/msteams/src/sdk-proactive.ts,send.ts,messenger.ts,send-context.ts,outbound.ts,channel.ts).sdk-proactive.test.ts(thread-anchor resolution table + suffix append/strip mechanism lock),send.test.ts(SharePoint/OneDrive threading, top-level override, card/poll thread-root forwarding, no-double-wrap on send failure),outbound.test.tsandchannel.actions.test.ts(presentation-cardthreadSuppressed/topLevelwiring),conversation-store.shared.test.ts(last-seen-wins invariant lock).node scripts/run-vitest.mjs extensions/msteams: 1028/1029 passed. The one failure (exposes pinnedMessageId in the tool schema) is pre-existing and unrelated — confirmed failing identically on a cleanorigin/booncheckout before this change.$autoreview(Claude engine — Codex CLI unavailable in this environment): clean, 0 accepted/actionable findings, correctness confidence 0.85. Independently verified the mechanism, the case-sensitivity fix, and confirmed sibling call sites (reply-dispatcher.ts,feedback-reflection.ts) correctly remain untouched.pnpm build: clean, no[INEFFECTIVE_DYNAMIC_IMPORT]warnings.oxlint) and format (oxfmt) clean.extensions/msteams/src+docs.check:changedand live Crabbox Teams proof — this dev environment has no working Crabbox provider (noazCLI/subscription for theazuredefault, noblacksmithbinary for the repo's configuredblacksmith-testboxCI-proof provider). Flagging as an explicit proof gap per user direction to land on unit tests + autoreview only.Linear: https://linear.app/getboon/issue/ENG-17134/arguijo-make-thread-vs-top-level-reply-deterministic-in-code-agent
Summary by cubic
Make MS Teams thread vs top-level replies deterministic across all send paths. Replies now stay in-thread (including SharePoint/OneDrive links, Adaptive Cards, and polls) unless you explicitly request a top-level post. Addresses Linear ENG-17134.
resolveMSTeamsThreadActivityIdand used it for text, media, uploaded-file links, Adaptive Cards, and polls.;messageid=suffix; doc-link replies no longer jump to channel root.topLevel/threadId: nullviareplyStyleOverrideand mapthreadSuppressedcorrectly.conversationTypecheck; channel detection is normalized.topLevel: trueor cronreplyStyle: "top-level".activityId/threadIdwins to avoid pinning to stale threads.Written for commit 103705d. Summary will update on new commits.