Skip to content

fix(msteams): make thread-vs-top-level replies deterministic (ENG-17134) - #95

Merged
convyusboy merged 1 commit into
boonfrom
ridho/eng-17134-arguijo-make-thread-vs-top-level-reply-deterministic-in-code
Jul 31, 2026
Merged

convyusboy merged 1 commit into
boonfrom
ridho/eng-17134-arguijo-make-thread-vs-top-level-reply-deterministic-in-code

Conversation

@convyusboy

@convyusboy convyusboy commented Jul 31, 2026 •

Copy link
Copy Markdown
Collaborator

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.md personas, 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 (resolveThreadedConversationId in sdk-proactive.ts) — a send that omits this anchor strips any existing suffix and posts at channel root, regardless of the replyStyle config. The SharePoint and OneDrive file-link branches in send.ts called a raw proactive send that never read the resolved replyStyle and never passed the thread anchor, even though resolveMSTeamsSendContext had 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 old messenger.ts check compared conversationType === "channel" case-sensitively while send-context.ts normalized to lowercase, so a ref stored with "Channel" would resolve replyStyle: "thread" and then get no suffix anyway.

Deliberately out of scope, with rationale:

  • No thread-depth threshold. MS Graph exposes no reply-count field and paginates oldest-first capped at 50 with no sort order, so a depth threshold is not implementable on this surface — and is unnecessary once threading is deterministic. This reconciles with ENG-15745's inverse need (starting fresh threads for very deep ones) without adding a depth knob here.
  • No prompt changes — none exist to change.
  • The conversationId/threadId last-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.
  • Slack's adjacent silent top-level exits (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 / cron replyStyle: "top-level" still work correctly for intentional new-conversation posts.

Evidence

  • Root cause and fix verified by direct source inspection (extensions/msteams/src/sdk-proactive.ts, send.ts, messenger.ts, send-context.ts, outbound.ts, channel.ts).
  • New/updated tests: 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.ts and channel.actions.test.ts (presentation-card threadSuppressed/topLevel wiring), 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 clean origin/boon checkout 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.
  • Lint (oxlint) and format (oxfmt) clean.
  • Non-test LOC delta: net -55 across extensions/msteams/src + docs.
  • Not yet run: broad check:changed and live Crabbox Teams proof — this dev environment has no working Crabbox provider (no az CLI/subscription for the azure default, no blacksmith binary for the repo's configured blacksmith-testbox CI-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.

  • Bug Fixes
    • Centralized thread anchor in resolveMSTeamsThreadActivityId and used it for text, media, uploaded-file links, Adaptive Cards, and polls.
    • Removed raw proactive sends that dropped the ;messageid= suffix; doc-link replies no longer jump to channel root.
    • Presentation cards and polls now honor topLevel/threadId: null via replyStyleOverride and map threadSuppressed correctly.
    • Fixed case-sensitive conversationType check; channel detection is normalized.
    • Kept intentional top-level posts working via topLevel: true or cron replyStyle: "top-level".
    • Documented and tested conversation-store behavior: last-seen activityId/threadId wins to avoid pinning to stale threads.

Written for commit 103705d. Summary will update on new commits.

Review in cubic

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

claude Bot commented Jul 31, 2026 •

Copy link
Copy Markdown

Claude encountered an error —— View job


I'll analyze this and get back to you.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cubic analysis

All reported issues were addressed across 14 files

Linked issue analysis

Linked issue: ENG-17134: [Arguijo] Make thread-vs-top-level reply deterministic in code (agent randomly abandons thread for top-level, worse on SharePoint doc links)

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

Comment thread extensions/msteams/src/send.ts Resolved
Comment thread extensions/msteams/src/messenger.ts Resolved

@gandalfboon gandalfboon Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@convyusboy
convyusboy merged commit 024aeb4 into boon Jul 31, 2026
144 of 146 checks passed
@convyusboy
convyusboy deleted the ridho/eng-17134-arguijo-make-thread-vs-top-level-reply-deterministic-in-code branch July 31, 2026 16:20
convyusboy added a commit that referenced this pull request Aug 3, 2026
Version-bump release carrying the 5 commits merged onto boon since boon.12:
#90 (ENG-16868), #92 (ENG-16854), #93, #94 (ENG-15788), #95 (ENG-17134).

Bumps gateway + slack + msteams + diagnostics-prometheus to
2026.6.11-boon.13 in lockstep (9 files). CI: 108 pass / 0 fail / 7 skip.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant