Repository navigation
fix(slack): recover thread anchor on invalid_thread_ts + publish fork slack tarball (ENG-16286) - #65
Conversation
…haning reply (ENG-16286)
When a Slack streaming reply's thread_ts is rejected as invalid_thread_ts /
thread_not_found — the anchoring message was deleted/edited while the agent was
mid-turn, or the anchor was a non-root reply ts — the streaming fallback reused
the rejected anchor. The streaming API strictly rejects it, but the fallback
chat.postMessage silently drops the thread and posts a NEW TOP-LEVEL message,
orphaning the reply to the channel ("threading broken / agent spamming the main
channel", reported by Guido).
Fix: on an invalid-thread finalize error, re-resolve the real thread root via
conversations.history (reusing the existing resolveThreadTsFromHistory) before
falling back — threading correctly when recoverable, and clearing the anchor to
degrade to the channel deterministically when the message is truly gone. Applied
at BOTH stream finalize-error paths (mid-turn append catch + terminal stop
catch) via a shared recoverThreadTsIfInvalid helper.
- streaming.ts: add isInvalidThreadSlackError classifier (mirrors
isBenignSlackFinalizeError); widen SlackStreamSession.threadTs to
string | undefined so the fallback can clear it.
- thread-resolution.ts: export resolveThreadTsFromHistory.
- dispatch.ts: recover the anchor before both fallback paths.
- tests: classifier unit tests, resolver recovery/deleted/error cases, and
dispatch integration tests for append + terminal-stop recovery and the
deleted-message channel-degrade path.
Root cause verified live on guido: gateway log shows
"slack-stream: streaming API call failed: ... invalid_thread_ts ... falling back"
at the exact ts of the orphaned reply (2026-07-20T14:19:54Z).
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…(ENG-16286) The fleet installs @openclaw/slack from public npm (upstream 5.18) — the fork gateway does NOT bundle the slack channel runtime, and the boon release did not publish a slack tarball. So the ENG-16286 invalid_thread_ts thread-anchor recovery fix (in extensions/slack) had no delivery path to the fleet. Mirror the ENG-14431 msteams pattern exactly: build extensions/slack via plugin-npm-runtime-build.mjs + pack under the manifest overlay, and publish openclaw-slack-<version>.tgz (+ .sha256) as a sibling asset on the same v*-boon.N tag. gandalf-manager will install it via `openclaw plugins install npm-pack:<url>` (slack uses openKeyedStore → REQUIRES trustedOfficialInstall==true). - extensions/slack/package.json: pin version to the gateway version in lockstep (2026.6.11-boon.5), same discipline as msteams; the release step guards tag == v<slack version>. - .github/workflows/boon-release.yml: add the slack pack step + upload the slack asset in both the create and clobber arms. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Dependency GuardThis PR changes dependency-related files. Maintainers should confirm these changes are intentional. Changed files:
Maintainer follow-up:
|
|
Claude encountered an error —— View job I'll analyze this and get back to you. |
Dependency graph changes notedThis PR includes dependency graph changes. The dependency guard is informational because the PR author is a repository admin or a member of
Security review is still recommended before merge when the dependency graph change is intentional. |
There was a problem hiding this comment.
cubic analysis
All reported issues were addressed across 8 files
Linked issue analysis
Linked issue: ENG-16286: [Guido] Boon Agent — threading broken + file system issues
| Status | Acceptance criteria | Notes |
|---|---|---|
| ✅ | Recover thread anchor when Slack rejects the anchoring ts (invalid_thread_ts or thread_not_found) instead of reusing the rejected ts | The PR adds an invalid-thread classifier and uses conversations.history to re-resolve the real thread root (or clear the anchor) before fallback posting. Code and tests exercise the recovery paths. |
| ✅ | Ensure buffered streaming text is delivered into the recovered thread (or deterministically falls back to channel when no root is found) rather than being orphaned | Dispatch now invokes recovery on stream finalize errors and routes buffered pendingText through the fallback into the recovered thread or clears the anchor to post to channel. Integration tests verify recovery, threading into recovered-root, and clearing anchor when message is gone. |
| ✅ | Add unit and integration tests covering classifier, resolver, and fallback recovery | New unit tests classify invalid-thread errors and verify history-based root resolution; integration tests simulate append/stop finalize errors and assert delivered replies thread correctly. |
| ✅ | Provide a delivery path so the forked @openclaw/slack plugin carrying the fix can be installed fleet-wide | CI/release workflow now packs and uploads a fork-versioned openclaw-slack-.tgz (with sha256) alongside other release assets; package.json pinned to gateway version. This enables gandalf-manager / fleet installs of the patched plugin. |
Reply with feedback, questions, or to request a fix.
Fix all with cubic | Re-trigger cubic
…art-time path, sticky degrade (cubic review, ENG-16286) Address 4 cubic review findings on PR #65: - P1 (reply-anchor): conversations.history does not return thread replies, so a rejected REPLY ts could not be recovered and the reply fell to the channel. recoverThreadTsIfInvalid now prefers the durable inbound thread root (message.thread_ts / incomingThreadTs — Slack gives us the root on every reply event) and only falls to the history lookup for a top-level anchor. - P1 (start-time): if the initial startSlackStream throws invalid_thread_ts, streamSession is never assigned, so recovery was skipped and the fallback reused the rejected planned anchor (orphaned top-level). Recovery now runs from streamSession?.threadTs ?? plannedThreadTs, covering the no-session path. - P1 (sticky degrade): clearing session.threadTs did not stop replyPlan from recomputing the rejected anchor for LATER payloads in the same turn. Added turn-level threadAnchorDegraded + recoveredThreadAnchor state that resolveDeliveryThreadTs honors over forcedThreadTs/replyPlan, so once degraded every subsequent payload delivers into the recovered root (or channel). - P2 (shrinkwrap): bump extensions/slack/npm-shrinkwrap.json version fields to 2026.6.11-boon.5 to match package.json (was stale at 2026.6.11). Tests: 3 new dispatch integration cases (reply-anchor via inbound root with no history call; start-time startSlackStream rejection; sticky channel degrade across payloads). Full slack suite 1348/1348 green, tsc + oxfmt clean. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…r-of) Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
There was a problem hiding this comment.
All reported issues were addressed across 3 files (changes from recent commits).
Tip: Review your code locally with the cubic CLI to iterate faster.
Fix all with cubic | Re-trigger cubic
…est-types)
The raw `call[0] as {...}` on deliverRepliesMock.mock.calls failed tsgo
(TS2352/TS2493: empty-tuple element type). Use the file's existing
requireMockCall/requireRecord helpers, which are properly typed. Verified with
tsgo:extensions:test (exit 0) + vitest 86/86.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
CI status — needs a secops/admin override (not a code failure)All code-quality checks are green (check-lint, check-test-types, check-prod-types, build-artifacts, every boundary + security-boundary check). Two checks remain red:
Cause: this PR touches 2 dependency-graph files — This needs sign-off from a security approver ( 🤖 Generated with Claude Code |
… anchor (cubic review, ENG-16286) Address cubic P2 on PR #65: the dispatch recovery could reuse a recovered anchor (incomingThreadTs) that was itself deleted, without the existence/error handling the history path has. Rather than a TOCTOU existence pre-check, harden the actual send: postSlackMessageBestEffort now catches invalid_thread_ts / thread_not_found and retries ONCE without thread_ts, so the reply lands in the channel instead of failing. This is the last-resort degrade behind the dispatch thread-anchor recovery and the belt for a recovered-but-deleted anchor — a single chokepoint covering every stale-anchor case (chat.postMessage is usually lenient and drops the thread, but not always, e.g. thread_not_found). New test file send.invalid-thread.test.ts (4 cases: retry-to-channel on invalid_thread_ts + thread_not_found; no retry for unrelated errors; no retry when there was no thread_ts, guarding against a loop). Full slack suite 1352/1352 green; tsgo:extensions:test exit 0; lint + format clean. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
There was a problem hiding this comment.
2 issues found across 2 files (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="extensions/slack/src/send.ts">
<violation number="1" location="extensions/slack/src/send.ts:420">
P2: Invalid-thread recovery can still fail for a configured custom identity when the token lacks `chat:write.customize`, because the channel retry repeats the identity and propagates `missing_scope`. Applying the customize-scope fallback to this retry (or retrying its no-thread payload without identity) would preserve the channel-delivery guarantee.</violation>
<violation number="2" location="extensions/slack/src/send.ts:421">
P2: A reply that was successfully degraded to the channel is still returned and cached as threaded with the rejected anchor. Tracking whether this retry degraded delivery and returning/recording an undefined thread state would prevent later routing from reintroducing the deleted anchor.</violation>
</file>
Tip: Review your code locally with the cubic CLI to iterate faster.
Fix all with cubic | Re-trigger cubic
|
/allow-dependencies-change |
…y (cubic review, ENG-16286) Address two cubic P2s on the send-to-channel retry (PR #65): - Custom-identity + missing scope: the no-thread retry re-applied the custom identity, so a token lacking chat:write.customize threw missing_scope and broke the channel-delivery guarantee. Moved the customize-scope fallback INTO postWithIdentity, so both the primary post and the invalid-thread retry fall back to a no-identity post — the reply lands either way. - Stale anchor cached: a reply degraded to the channel still returned/cached threadTs = opts.threadTs (the rejected anchor) via the `?? opts.threadTs` fallback, letting downstream routing reintroduce the dead thread. The degraded send now marks the response (non-enumerable SLACK_THREAD_DROPPED symbol); both callers read it via wasSlackThreadDropped and report threadTs undefined, ignoring any echoed thread_ts on the channel post. Tests: +2 cases (retry drops identity on missing scope; degraded send reports threadTs undefined even when Slack echoes the anchor) + a threadTs assertion on the existing case. Full slack suite 1354/1354 green; tsgo:extensions:test exit 0; lint + format clean. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
There was a problem hiding this comment.
Approving — reviewed the full diff (11 files, +802) against ENG-16286.
Root cause & fix are sound. invalid_thread_ts/thread_not_found classifier added in streaming.ts + send.ts; recovery wired at all three finalize paths (start-time startSlackStream throw, mid-turn append catch, terminal stop). The subtle bit is handled correctly: for a rejected reply anchor, recovery prefers the inbound message.thread_ts root because conversations.history doesn't return thread replies — falling to history only for a deleted top-level root. Sticky turn-level threadAnchorDegraded/recoveredThreadAnchor correctly stops resolveDeliveryThreadTs/replyPlan from reintroducing the dead anchor on later payloads.
Both cubic P2s are resolved by 74eee51: postWithIdentity now wraps the invalid-thread channel retry so the chat:write.customize fallback applies to it too (P2#1), and the non-enumerable SLACK_THREAD_DROPPED marker makes degraded sends record undefined thread state instead of caching the rejected anchor (P2#2). Belt-and-suspenders with the dispatch-level recovery.
Delivery path mirrors the proven ENG-14431 msteams release pattern exactly — packs openclaw-slack-<version>.tgz(+sha256) as a sibling asset, version locked to the gateway (2026.6.11-boon.5), with a hard tag==v guard that fails the release loudly on mismatch. Comment correctly notes the trustedOfficialInstall==true requirement (openKeyedStore).
Tests present and per the PR body 1345/1345 green + tsc/oxfmt clean: classifier unit, resolver recover/deleted/error, dispatch integration for append + terminal-stop + deleted-message channel-degrade. No secrets in the diff or history (only xoxb-test fixtures). Other pending human reviewers don't block per standing policy.
Ship it.
Bump gateway + @openclaw/slack + @openclaw/msteams to 2026.6.11-boon.6 in lockstep (package.json + npm-shrinkwrap.json roots) and add the CHANGELOG entry. This tag publishes the fork-versioned @openclaw/slack plugin asset for the first time (ENG-16286, #65) alongside the existing gateway + msteams assets. Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
Problem (ENG-16286, P0 — Guido)
A live Slack agent posted its reply as a new top-level message instead of threaded ("threading broken / agent spamming the main channel"). Root-caused from the guido gateway log and reproduced live on a test host:
When the user deletes/edits the message that anchors a thread while the agent is mid-turn, Slack rejects the reply's
thread_tsasinvalid_thread_ts. The fork's slack plugin had no handling for this — the streaming finalize error hit the raw catch and the fallback re-posted with the dead anchor (whichchat.postMessagesilently drops → top-level), or cleared it entirely.invalid_thread_ts/thread_not_foundwere absent fromBENIGN_SLACK_FINALIZE_ERROR_CODES.Fix
streaming.ts— addisInvalidThreadSlackErrorclassifier (mirrorsisBenignSlackFinalizeError+ code Set); widenSlackStreamSession.threadTs→string | undefinedso the fallback can clear a truly-gone anchor.monitor/thread-resolution.ts— export the existingresolveThreadTsFromHistory(re-resolves the real thread root viaconversations.history, orundefinedon deleted/error).monitor/message-handler/dispatch.ts— sharedrecoverThreadTsIfInvalid(session, err)helper applied at both stream finalize-error paths (the mid-turn append catch AND the terminalstopSlackStreamcatch). On invalid-thread it recovers the root (→ threads correctly) or clears the anchor (→ deterministic channel fallback); never reuses the rejected ts.Tests: classifier unit tests, resolver recovery/deleted/error cases, and dispatch integration tests for append + terminal-stop recovery and the deleted-message channel-degrade path.
pnpm vitest run extensions/slack→ 1345/1345 green, tsc + oxfmt clean.Delivery (the second commit)
The fleet installs
@openclaw/slackfrom public npm (upstream 5.18) — the gateway tarball does NOT bundle the slack channel runtime, and the boon release published no slack tarball. So this fix had no delivery path to the fleet. The second commit mirrors the ENG-14431 msteams pattern: build + packextensions/slackand publishopenclaw-slack-<version>.tgz(+.sha256) as a sibling release asset. gandalf-manager will install it viaopenclaw plugins install npm-pack:<url>(slack usesopenKeyedStore→ requirestrustedOfficialInstall==true, so a bare-tarball install would crash-loop — same subtlety as msteams).extensions/slack/package.jsonis now version-locked to the gateway (2026.6.11-boon.5); the release step guardstag == v<slack version>.Rollout (tracked in gandalf-manager)
Cut a new
boon.Ntag to publish the slack asset → gandalf-managerfleet-slack.sh(new, mirrorsfleet-msteams.sh) → canary → guido → fleet. Pre-canary live test on theridho-testinghost (baseline bug already reproduced there).🤖 Generated with Claude Code
Summary by cubic
Fixes Slack threading by recovering the reply anchor on invalid-thread errors and guarantees channel delivery when the anchor is gone, even with custom identities. Also publishes the forked
@openclaw/slacktarball on Boon releases to ship the fix fleet‑wide. Addresses ENG-16286.Bug Fixes
message.thread_tswhen the rejected ts is a reply; else re-resolve viaconversations.history; clear if none; keep the degrade sticky for the whole turn.chat.postMessageinvalid_thread_ts/thread_not_found, retry once withoutthread_ts; ifchat:write.customizeis missing, drop identity on retry; mark degraded replies sothreadTsis not recorded.SlackStreamSession.threadTstostring | undefined; add tests for invalid-thread classification, recovery (including start-time/terminal cases and reply-anchor via inbound root), sticky behavior, and send retry/identity; fix a test type error.Dependencies
openclaw-slack-<version>.tgz(+.sha256) alongside the gateway and@openclaw/msteams.extensions/slack/package.jsonandnpm-shrinkwrap.jsonto the gateway version (2026.6.11-boon.5); release enforcestag == v<version>.Written for commit 74eee51. Summary will update on new commits.