Skip to content

feat(cron): post top-level channel messages from scheduled jobs (ENG-14117) - #45

Merged
convyusboy merged 8 commits into
boonfrom
ridho/ENG-14117/cron-top-level-delivery
Jul 14, 2026
Merged

convyusboy merged 8 commits into
boonfrom
ridho/ENG-14117/cron-top-level-delivery

Conversation

@convyusboy

@convyusboy convyusboy commented Jul 14, 2026 •

Copy link
Copy Markdown
Collaborator

What Problem This Solves

ENG-14117 (P0): on channels that thread agent replies — the customer surface is Microsoft Teams, channels.msteams.replyStyle:"thread" — a scheduled/cron job's completion output threads under the session's last message. Channel timelines never get a clean top-level post, so members miss scheduled reports (arguijo's Daily Bid Tab Scan, Civil Timecard Audit, etc.).

PR #38 added a per-send topLevel param to the message tool, which covers agent-initiated on-request sends (AC #1). It does not cover the cron/scheduled delivery path (AC #2), which routes through sendDurableMessageBatch and only ever resolves reply style from config. This PR closes that gap.

Why This Change Was Made

A global replyStyle:"top-level" flip would break the "conversations stay threaded" half of the contract, so the fix has to be per-send. This threads a portable top-level intent from the cron job config all the way to the Teams adapter:

delivery.replyStyle: "top-level"   (cron job config)
  -> threadSuppressed: true         (portable, channel-neutral core outbound field)
  -> replyStyleOverride: "top-level" (MS Teams adapter maps it)
  -> fresh channel-root Teams message
  • Adds CronDelivery.replyStyle ("thread" | "top-level") plus --reply-style / --clear-reply-style on cron add/edit, config normalize/merge, delivery plan/preview, and the gateway RPC schema.
  • Adds a portable threadSuppressed field to core ChannelOutboundContext / DeliverOutboundPayloadsParams; only the MS Teams adapter interprets it (core stays channel-agnostic). Presentation cards intentionally ignore it (documented limitation, same as PR feat(msteams): add topLevel parameter for per-send reply style override (ENG-14117) #38).
  • Maps replyStyle:"top-level" -> threadSuppressed at both cron send sites: isolated jobs (delivery-dispatch) and main/current-session jobs (delivery.ts via CronAnnounceTarget, set in server-cron).

It is the scheduled-delivery counterpart of PR #38's per-send topLevel param, built on the same override plumbing.

Stacked on #38 (base ridho/ENG-14117/msteams-top-level-override) for a clean single-commit diff; retarget to boon after #38 merges.

User Impact

Operators set --reply-style top-level on a scheduled job (or delivery.replyStyle in config) and its runs post a fresh top-level channel message the whole channel sees, while conversational replies still thread. Omitting it preserves current behavior, so existing jobs are unaffected. Additive optional config — no migration.

Evidence

  • TDD throughout (adapter mapping, cron mapping helper, CLI parse, normalize round-trip, protocol validator).
  • $autoreview (high) caught and fixed 2 real issues before commit: the gateway RPC schema used additionalProperties:false and would have rejected replyStyle at the boundary; and the main/current-session announce path (server-cron -> deliverCronAnnouncePayload) was initially unwired so top-level only worked for isolated jobs.
  • Green: core + extensions prod types, core + extensions test types, pnpm build (no INEFFECTIVE_DYNAMIC_IMPORT), and behavior tests across msteams / cron / CLI / gateway-protocol (134 passing across the touched suites).

Out of scope (follow-ups, not in this PR)

  • AC #3b — boon-core sync-config/agent-setup fleet default for the trial (different repo; mirrors ENG-13324's Teams replyStyle default work).
  • AC feat(sentry-monitor): bundle Sentry error monitoring into the fork #4 — live arguijo cron verification via SSM/Crabbox on boon-agent10-pilot: run a cron with --reply-style top-level, confirm a new root Teams message (no replyToId), and confirm a follow-up still threads.
  • Ticket metadata still says "Slack" though the real surface is Teams — worth re-scoping.

🤖 Generated with Claude Code


Summary by cubic

Adds a per‑job reply style for cron announces so scheduled jobs can post top‑level messages on Microsoft Teams or force threading. Defaults stay unchanged; opt in with --reply-style or clear it. Addresses ENG-14117.

  • New Features

    • Added delivery.replyStyle ("thread" | "top-level") for cron announces; set via --reply-style / --clear-reply-style on cron add/cron edit (protocol + cron-tool schemas accept; normalization supports set/clear).
    • Core outbound now carries tri‑state threadSuppressed; MS Teams maps true → "top-level" and false → "thread"; presentation cards ignore it; applied on both cron paths (isolated and main/current‑session).
    • Delivery preview surfaces "top-level" for announce plans when set, and omits it for mode:"none".
  • Bug Fixes

    • Persist threadSuppressed in the durable delivery queue and recovery so top‑level intent survives crash replay on the main/current‑session path.
    • Reject --reply-style when combined with --webhook, and on main/system‑event jobs that build no delivery object.
    • Keep replyStyle cleared when mode:webhook so it never threads in that mode.

Written for commit bc22792. Summary will update on new commits.

Review in cubic

convyusboy and others added 4 commits July 6, 2026 21:25
…ply style override (ENG-14117)

Implements the last-mile wiring for MS Teams replyStyleOverride mechanism,
exposing it to agents via a topLevel parameter on the message tool.

Changes:
- Add replyStyleOverride parameter through send context chain:
  - sendMessageMSTeams accepts replyStyleOverride
  - resolveMSTeamsSendContext passes it through
  - resolveMSTeamsProactiveReplyStyle honors override with early return

- Add topLevel boolean parameter to message tool schema for send and upload-file actions
  - Mirrors Slack's topLevel API for cross-platform consistency
  - Supports bidirectional override (force top-level OR force threading)
  - Accepts threadId: null as equivalent to topLevel: true

- Handle topLevel in action handlers:
  - upload-file: read topLevel param, convert to replyStyleOverride, pass to sendMessageMSTeams
  - send (non-presentation): explicit handler to support topLevel before outbound fallthrough
  - send (presentation): no change, presentation cards don't support override

- Add tests for replyStyleOverride mechanism:
  - Test top-level override on thread-default channel
  - Test thread override on top-level config
  - Test undefined override (no behavior change)

This allows scheduled cron jobs to post top-level channel messages while
interactive conversations stay threaded, without changing global config.

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
…resentation limitation

- Fix return type of createMSTeamsTopLevelActionSchema to Record<string, TSchema>
- Add explicit type for schema array: ChannelMessageToolSchemaContribution[]
- Add satisfies ChannelMessageActionName[] to actions arrays for type safety
- Import TSchema and ChannelMessageToolSchemaContribution from channel-contract
- Document that topLevel parameter only works for non-presentation sends

Fixes TypeScript compilation errors in check-prod-types and check-test-types.
Addresses review comment about presentation card limitation by documenting it.

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
…14117)

Scheduled cron announce output threaded under the session's last message on
channels that thread agent replies (MS Teams), so channel timelines missed
scheduled reports. Add a per-job delivery.replyStyle override so a scheduled
job can post a fresh top-level channel message while conversational replies
keep the channel/global threading default.

- Add CronDelivery.replyStyle ("thread" | "top-level") + --reply-style /
  --clear-reply-style CLI flags on cron add/edit, config normalize/merge,
  delivery plan/preview, and the gateway RPC schema.
- Add a portable threadSuppressed intent to core ChannelOutboundContext /
  DeliverOutboundPayloadsParams; the MS Teams adapter maps it to a per-send
  replyStyle:"top-level" override. Presentation cards intentionally ignore it.
- Map replyStyle:"top-level" -> threadSuppressed at both cron send sites:
  isolated jobs (delivery-dispatch) and main/current jobs (delivery.ts via
  CronAnnounceTarget set in server-cron).

Scheduled-delivery counterpart of the message tool's per-send topLevel param.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

@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.

All reported issues were addressed across 26 files

Tip: instead of fixing issues one by one fix them all with cubic

Re-trigger cubic

Comment thread src/infra/outbound/deliver.ts Resolved
Comment thread src/cron/service/jobs.ts Resolved
Comment thread src/cli/cron-cli/register.cron-add.ts Resolved
Comment thread src/cron/delivery.ts Resolved
Comment thread src/cron/types.ts Resolved
Comment thread src/cron/delivery-preview.ts Resolved
convyusboy and others added 2 commits July 14, 2026 13:13
- Persist tri-state reply-style intent end to end. threadSuppressed is now
  true (top-level) / false (force thread) / undefined (channel default); the
  MS Teams adapter maps false to replyStyleOverride:"thread" so --reply-style
  thread forces threading even when the channel default is top-level.
- mergeCronDelivery: keep replyStyle cleared when the resulting mode is webhook,
  even if the same patch sets both mode and replyStyle.
- cron add: reject --reply-style on main/system-event jobs that build no
  delivery object (mirrors --account/--thread-id).
- delivery preview: only show the top-level suffix for announce plans.
- cron agent tool schema + help: expose delivery.replyStyle so scheduling
  agents can discover it.
- types: trim CronReplyStyle JSDoc to the module comment limit.
- tests: dispatchCronDelivery regression (top-level/thread/unset -> durable
  threadSuppressed), bidirectional MS Teams adapter mapping, and CLI guards.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…very (ENG-14117)

The main/current-session cron announce path enqueues durably (no skipQueue), so
a crash between enqueue and send would replay the top-level cron delivery as a
normal threaded send. Persist threadSuppressed in the queued delivery entry and
pass it from buildRecoveryDeliverParams so recovery preserves the original
top-level intent. Covered by the recovery replay test.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

@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.

All reported issues were addressed across 16 files (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Fix all with cubic | Re-trigger cubic

Comment thread src/agents/tools/cron-tool.ts Resolved
Comment thread src/cron/delivery-preview.ts Resolved
convyusboy and others added 2 commits July 14, 2026 13:45
…ENG-14117)

- cron-tool.schema.test: add replyStyle to the exact job.delivery key list that
  now fails after exposing the field on the agent tool schema.
- Regenerate Codex prompt snapshots to include the new delivery.replyStyle
  schema field (char/token counts + JSON only; no unrelated drift).
- delivery-preview: add regression cases — announce+top-level keeps the
  "top-level" suffix; none+top-level omits it.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@convyusboy

Copy link
Copy Markdown
Collaborator Author

/cr

@claude

claude Bot commented Jul 14, 2026

Copy link
Copy Markdown

Claude Code is working…

I'll analyze this and get back to you.

View job run

Base automatically changed from ridho/ENG-14117/msteams-top-level-override to boon July 14, 2026 08:28

@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.

Reviewed the full diff (43 files, +953/-55), CI, signatures, and base.

Approving. This is clean, well-scoped work and the plumbing is right.

What I checked:

  • Design is sound. Per-send threadSuppressed tri-state (true/false/undefined) kept portable in core ChannelOutboundContext; only the MS Teams adapter interprets it. Core stays channel-agnostic — exactly the right seam. Bidirectional (--reply-style thread forces threading even when the channel default is top-level) is a nice touch.
  • Both cron send sites are wired — isolated (delivery-dispatch) and main/current (server-cron → deliverCronAnnouncePayload). The server-cron gap you caught in $autoreview was the real trap; glad it's covered.
  • Crash-safety is handled. threadSuppressed persists through the durable queue (delivery-queue-storage) and buildRecoveryDeliverParams, with a recovery-replay test asserting it survives. This was the highest-risk corner and it's proven, not hand-waved.
  • Edge cases guarded: webhook mode clears replyStyle (both in mergeCronDelivery when mode+replyStyle patched together, and in the CLI conflict check); main/system-event jobs reject --reply-style; mode:none omits the preview suffix; presentation cards documented as ignoring it.
  • TDD throughout — adapter mapping (bidirectional + undefined), CLI parse/normalize round-trip, protocol validator (rejects unknown styles + accepts null-clear), delivery preview, dispatch regression. Codex prompt snapshots regenerated to match the new schema field.
  • CI green (full matrix + CodeQL + cubic), commits verified-signed, cubic's reported issues all addressed, base is boon.

One non-blocking nit: the branch still shows the three merged #38 commits (bb1fc6e, 7442440, 0c6cf3d) as ahead of boon — #38 merged at 08:28 today under a squashed SHA, so this branch wasn't rebased after. The net diff is correct and the PR description's "stacked on #38, retarget after merge" note is now stale. A rebase on boon would give a clean delta and dodge any stale-merge risk, but it's cosmetic — not gating.

Ship it.

@convyusboy
convyusboy merged commit 4256258 into boon Jul 14, 2026
146 checks passed
@convyusboy
convyusboy deleted the ridho/ENG-14117/cron-top-level-delivery branch July 14, 2026 08:34
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