Skip to content

diag(slack): log thread-resolution decision on tool sends (ENG-16509) - #88

Merged
convyusboy merged 1 commit into
boonfrom
ridho/eng-16509-pss-slack-agent-tool-posted-message-landed-top-level-instead
Jul 30, 2026
Merged

convyusboy merged 1 commit into
boonfrom
ridho/eng-16509-pss-slack-agent-tool-posted-message-landed-top-level-instead

Conversation

@convyusboy

@convyusboy convyusboy commented Jul 29, 2026 •

Copy link
Copy Markdown
Collaborator

What

Adds a DEBUG (logVerbose) trace of the thread-resolution decision to the Slack agent message-send tool path (action-runtime.ts sendMessage / uploadFile). The trace records topLevel, threadIdNull, explicitThreadTs, currentThreadTs, currentChannelId/currentMessagingTarget, replyToMode, hasReplied, sameChannelThreadRequired, targetsMatch, and resolved (TOP-LEVEL when the thread anchor was suppressed). Message content is never logged.

No behavior change — resolveThreadTsFromContext's inputs/outputs are byte-identical; the params were only extracted into named locals so they can be logged.

Why (ENG-16509)

On the PSS host, one agent-turn Slack message (the "weld & handling takeoff" summary) posted top-level instead of in the active thread, while its siblings from the same turn (the .xlsx upload + the "Delivered…" note) threaded correctly.

This is a distinct class from ENG-16286 (invalid_thread_ts, fixed in #65):

  • 0 invalid_thread_ts, 0 reply_broadcast, no "streaming … falling back", no top-level "delivered reply to channel" in the PSS logs.
  • The send.ts invalid-thread degrade never fired.

The threading context is built once per turn and shared across every tool call, so currentThreadTs was set for the whole turn (siblings threaded). A single divergent send can therefore only go top-level via one of two silent, previously-unlogged branches in resolveThreadTsFromContext:

  1. the agent passed topLevel:true / threadId:null on that send, or
  2. slackContextTargetsMatch(to, context) returned false for that send's channel-target format.

Existing logs can't disambiguate — the entire decision path emits nothing. This PR closes that observability gap so a verbose repro pins cause 1 vs 2, which then selects the real fix (agent/tool-schema guidance for cause 1; target-match normalization and/or extending the ENG-16286 thread-anchor recovery to the tool-send path for cause 2).

Testing

  • extensions/slack/src/action-runtime.test.ts: 68 passed (5 new — assert the log distinguishes cause 1 from cause 2, plus normal-thread and uploadFile cases).
  • Full slack extension suite: 104 files / 1354 tests passed.
  • tsc -p extensions/slack/tsconfig.json --noEmit: clean.
  • oxlint on both files: clean.

Follow-ups (not in this PR)

  • Deliver to a repro host (fork gateway build roll) and reproduce at debug file log level.
  • Land the real fix per the repro verdict.

🤖 Generated with Claude Code


Summary by cubic

Add DEBUG logging for Slack tool sends to trace thread-resolution decisions and diagnose ENG-16509 where a tool-posted message landed top-level instead of in-thread. No behavior change.

  • New Features
    • Emit a logVerbose "thread-resolve" line from sendMessage and uploadFile, capturing key inputs and the resolved anchor (uses TOP-LEVEL when suppressed). Message content is never logged.
    • Distinguishes agent opt-out (topLevel:true / threadId:null) from channel-target mismatch, aligning with the Linear issue’s needs.
    • resolveThreadTsFromContext behavior is unchanged; parameters were surfaced only for logging.
    • Tests: add coverage for normal threading, explicit top-level suppression, target mismatch, and uploadFile cases.

Written for commit 9eb9de2. Summary will update on new commits.

Review in cubic

A PSS agent-turn Slack message posted top-level instead of in-thread while
its siblings from the same turn threaded correctly. It went through the agent
message-send TOOL path (action-runtime.ts sendMessage/uploadFile), whose
thread auto-inject decision (resolveThreadTsFromContext) is completely silent
— no INFO/DEBUG record says WHY one send dropped its thread anchor. This is a
distinct class from ENG-16286 (invalid_thread_ts): that fingerprint is absent
in the PSS logs, and the send.ts invalid-thread degrade never fired.

The context is built once per turn and shared across tool calls, so
currentThreadTs was set for the whole turn (siblings threaded). A single
divergent send can therefore only go top-level via one of two silent branches:
(1) the agent passed topLevel:true / threadId:null, or (2)
slackContextTargetsMatch returned false for that send's channel-target format.
Existing logs can't disambiguate.

Add logSlackThreadResolution — a logVerbose (DEBUG-level, matching send.ts
convention) trace emitted from sendMessage and uploadFile capturing topLevel,
threadIdNull, explicitThreadTs, currentThreadTs, replyToMode, targetsMatch, and
the resolved value (TOP-LEVEL when suppressed). Message content is never
logged. No behavior change — the resolver inputs/outputs are identical.

A verbose repro can now pin cause 1 vs 2 to pick the real fix.

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

claude Bot commented Jul 29, 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

No issues found across 2 files

Linked issue analysis

Linked issue: ENG-16509: [PSS] Slack: agent tool-posted message landed top-level instead of in-thread (distinct from ENG-16286 invalid_thread_ts)

Status Acceptance criteria Notes
✅ Emit a DEBUG/verbose trace on Slack tool sends (sendMessage and uploadFile) that records the thread-resolution decision and key inputs (topLevel, threadIdNull, explicitThreadTs, currentThreadTs, currentChannelId/currentMessagingTarget, replyToMode, hasReplied, sameChannelThreadRequired, targetsMatch, and the resolved value). A new helper logSlackThreadResolution builds a verbose string containing the listed fields and is invoked from both sendMessage and uploadFile branches.
✅ Log uses 'TOP-LEVEL' (or equivalent) when the anchor is suppressed and records whether suppression was due to explicit opt-out (topLevel/threadId:null) vs target mismatch (targetsMatch=false). The resolver log includes resolved= with resolved defaulting to 'TOP-LEVEL'; tests assert resolved=TOP-LEVEL and check topLevel/threadIdNull or targetsMatch flags for the two causes.
✅ Do not log message content (only diagnostic/context fields). The logging helper accepts only action/to/explicitThreadTs/topLevel/threadIdNull/context/resolvedThreadTs and constructs a diagnostic string; no message content parameter is included or interpolated.
✅ Add tests that validate the verbose log distinguishes cause 1 (explicit topLevel/threadTs null) from cause 2 (targetsMatch=false) and covers uploadFile sends. action-runtime.test.ts adds a block 'thread-resolution DEBUG logging (ENG-16509)' with tests that assert presence of expected log fragments for normal threading, topLevel/threadTs-null suppression, targetsMatch=false, and uploadFile.
✅ No behavioral change to thread resolution (logging only) — resolveThreadTsFromContext remains functionally unchanged. The PR extracts and names locals purely for logging and passes the same inputs to resolveThreadTsFromContext; test run and CI notes indicate no regressions (tsc and oxlint clean).

Re-trigger cubic

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

Approve — clean, well-scoped diagnostic.

  • Traces to ENG-16509; problem statement crisply distinguishes it from ENG-16286 (#65).
  • No behavior change confirmed: resolveThreadTsFromContext inputs/outputs are byte-identical; params were only hoisted into named locals. The extra slackContextTargetsMatch() call in the log builder is a pure predicate (verified — no side effects), so it's safe.
  • No content/PII/secrets logged — only decision-context booleans + thread anchors.
  • Tests: 5 new cases assert cause-1 (topLevel/threadId:null) vs cause-2 (targetsMatch=false) disambiguation + the uploadFile path; logVerbose mocked via importOriginal cleanly.
  • logVerbose matches the send.ts DEBUG convention; no duplication.

Ship it.

@convyusboy
convyusboy merged commit b0ca93e into boon Jul 30, 2026
140 of 141 checks passed
@convyusboy
convyusboy deleted the ridho/eng-16509-pss-slack-agent-tool-posted-message-landed-top-level-instead branch July 30, 2026 07:26
convyusboy added a commit that referenced this pull request Jul 30, 2026
Version-bump release carrying the 3 commits merged onto boon since boon.11:

- #86: edge/WAF HTML 429 now classifies as transient timeout (not model
  rate_limit), so a Cloudflare-relayed 429 no longer surfaces a false
  'all models rate-limited'; the client-side ride-out retry still absorbs it.
- #88: DEBUG-level trace of the Slack thread-resolution decision on the agent
  message-send tool path (sendMessage/uploadFile); observability only, no
  behavior change, message content never logged.
- #89: sentry-monitor classifies gateway-relayed upstream (Bedrock) 5xx vs
  gateway-origin 5xx via classify5xxSource(), tagging error_class + http_status
  on the model_call_ended capture so the Rohan alert can split/rate-gate them.

Bumps the gateway + @openclaw/slack + @openclaw/msteams to 2026.6.11-boon.12 in
lockstep (7 files: 3 package.json, 3 npm-shrinkwrap.json, CHANGELOG.md). Tagging
v2026.6.11-boon.12 after merge triggers boon-release.yml to publish the 6 assets.
convyusboy added a commit that referenced this pull request Jul 31, 2026
…ease asset (ENG-15788) (#94)

* release: 2026.6.11-boon.12

Version-bump release carrying the 3 commits merged onto boon since boon.11:

- #86: edge/WAF HTML 429 now classifies as transient timeout (not model
  rate_limit), so a Cloudflare-relayed 429 no longer surfaces a false
  'all models rate-limited'; the client-side ride-out retry still absorbs it.
- #88: DEBUG-level trace of the Slack thread-resolution decision on the agent
  message-send tool path (sendMessage/uploadFile); observability only, no
  behavior change, message content never logged.
- #89: sentry-monitor classifies gateway-relayed upstream (Bedrock) 5xx vs
  gateway-origin 5xx via classify5xxSource(), tagging error_class + http_status
  on the model_call_ended capture so the Rohan alert can split/rate-gate them.

Bumps the gateway + @openclaw/slack + @openclaw/msteams to 2026.6.11-boon.12 in
lockstep (7 files: 3 package.json, 3 npm-shrinkwrap.json, CHANGELOG.md). Tagging
v2026.6.11-boon.12 after merge triggers boon-release.yml to publish the 6 assets.

* feat(release): publish @openclaw/diagnostics-prometheus as a fork release asset (ENG-15788)

The diagnostics-prometheus plugin's dist is excluded from the published gateway
package (`!dist/extensions/diagnostics-prometheus/**`), so a fleet host has no
way to run the Prometheus exporter unless the plugin is installed separately —
and gandalf-manager's Alloy scrape (job boon-agent-openclaw, ENG-15788 step 2)
has nothing to read until it is. There was no release tarball for it.

- Pin extensions/diagnostics-prometheus/package.json + npm-shrinkwrap.json to
  2026.6.11-boon.12 in lockstep with the gateway (same contract as slack/msteams
  — the pack step asserts TAG == v<version>).
- Add a 'Pack diagnostics-prometheus plugin tarball + compute sha256' step to
  boon-release.yml mirroring the slack/msteams steps (runtime-build + manifest
  overlay pack), and wire the new asset + its .sha256 into the Publish step (both
  create and upload --clobber arms) so it ships on the same v*-boon.N tag.

Asset contract:
  openclaw-diagnostics-prometheus-<version>.tgz + .tgz.sha256

Unlike slack/msteams this plugin does NOT use openKeyedStore (no trust-gate), so
a bare install wouldn't crash-loop — but the npm-pack: trusted path is used for
install-shape consistency across the fork's plugins. Version must advance in
lockstep on every future release, same as slack/msteams. actionlint clean; YAML
valid. Pack machinery validated by CI on the release run (no node_modules in this
worktree to pack locally).
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