Skip to content

fix(slack): recover thread anchor on invalid_thread_ts + publish fork slack tarball (ENG-16286) - #65

Merged
convyusboy merged 7 commits into
boonfrom
ridho/eng-16286-guido-boon-agent-threading-broken-file-system-issues
Jul 22, 2026
Merged

convyusboy merged 7 commits into
boonfrom
ridho/eng-16286-guido-boon-agent-threading-broken-file-system-issues

Conversation

@convyusboy

@convyusboy convyusboy commented Jul 22, 2026 •

Copy link
Copy Markdown
Collaborator

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:

slack-stream: streaming API call failed: An API error occurred: invalid_thread_ts; ... falling back
→ delivered reply to channel:C...   (orphaned top-level, ~100–300ms later)

When the user deletes/edits the message that anchors a thread while the agent is mid-turn, Slack rejects the reply's thread_ts as invalid_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 (which chat.postMessage silently drops → top-level), or cleared it entirely. invalid_thread_ts/thread_not_found were absent from BENIGN_SLACK_FINALIZE_ERROR_CODES.

Fix

  1. streaming.ts — add isInvalidThreadSlackError classifier (mirrors isBenignSlackFinalizeError + code Set); widen SlackStreamSession.threadTs → string | undefined so the fallback can clear a truly-gone anchor.
  2. monitor/thread-resolution.ts — export the existing resolveThreadTsFromHistory (re-resolves the real thread root via conversations.history, or undefined on deleted/error).
  3. monitor/message-handler/dispatch.ts — shared recoverThreadTsIfInvalid(session, err) helper applied at both stream finalize-error paths (the mid-turn append catch AND the terminal stopSlackStream catch). 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/slack from 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 + pack extensions/slack and publish openclaw-slack-<version>.tgz (+.sha256) as a sibling release asset. gandalf-manager will install it via openclaw plugins install npm-pack:<url> (slack uses openKeyedStore → requires trustedOfficialInstall==true, so a bare-tarball install would crash-loop — same subtlety as msteams). extensions/slack/package.json is now version-locked to the gateway (2026.6.11-boon.5); the release step guards tag == v<slack version>.

Rollout (tracked in gandalf-manager)

Cut a new boon.N tag to publish the slack asset → gandalf-manager fleet-slack.sh (new, mirrors fleet-msteams.sh) → canary → guido → fleet. Pre-canary live test on the ridho-testing host (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/slack tarball on Boon releases to ship the fix fleet‑wide. Addresses ENG-16286.

  • Bug Fixes

    • Recover on invalid-thread: prefer inbound message.thread_ts when the rejected ts is a reply; else re-resolve via conversations.history; clear if none; keep the degrade sticky for the whole turn.
    • Run recovery on all paths (start-time rejection, mid-turn append, terminal stop) and deliver buffered text via fallback so nothing is lost.
    • Harden send: on chat.postMessage invalid_thread_ts/thread_not_found, retry once without thread_ts; if chat:write.customize is missing, drop identity on retry; mark degraded replies so threadTs is not recorded.
    • Widen SlackStreamSession.threadTs to string | 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

    • Release workflow builds and uploads openclaw-slack-<version>.tgz (+.sha256) alongside the gateway and @openclaw/msteams.
    • Pin extensions/slack/package.json and npm-shrinkwrap.json to the gateway version (2026.6.11-boon.5); release enforces tag == v<version>.

Written for commit 74eee51. Summary will update on new commits.

Review in cubic

convyusboy and others added 2 commits July 21, 2026 17:08
…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]>
@github-actions

github-actions Bot commented Jul 22, 2026 •

Copy link
Copy Markdown

Dependency Guard

This PR changes dependency-related files. Maintainers should confirm these changes are intentional.

Changed files:

  • extensions/slack/npm-shrinkwrap.json
  • extensions/slack/package.json

Maintainer follow-up:

  • Review whether the dependency changes are intentional.
  • Inspect resolved package deltas when lockfile, shrinkwrap, or workspace dependency policy changes are present.
  • Treat package-lock.json and npm-shrinkwrap.json diffs as security-review surfaces.
  • Run pnpm deps:changes:report -- --base-ref origin/main --markdown /tmp/dependency-changes.md --json /tmp/dependency-changes.json locally for detailed release-style evidence.

@claude

claude Bot commented Jul 22, 2026 •

Copy link
Copy Markdown

Claude encountered an error —— View job


I'll analyze this and get back to you.

@github-actions

github-actions Bot commented Jul 22, 2026 •

Copy link
Copy Markdown

Dependency graph changes noted

This PR includes dependency graph changes. The dependency guard is informational because the PR author is a repository admin or a member of @openclaw/openclaw-secops.

  • Current SHA: 74eee519c6f3b83975b5e8fe7f7a0a30ca413dbf
  • Trusted actor: @convyusboy
  • Trusted role: pull request author; repository admin

Security review is still recommended before merge when the dependency graph change is intentional.

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

Comment thread extensions/slack/src/streaming.ts Resolved
Comment thread extensions/slack/package.json Resolved
convyusboy and others added 2 commits July 22, 2026 15:08
…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]>

@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 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]>
@convyusboy

Copy link
Copy Markdown
Collaborator Author

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:

  • dependency-guard — fails with "Dependency graph changes require removal or a current admin or secops override."
  • security-fast — trips on the same dependency-file change signal.

Cause: this PR touches 2 dependency-graph files — extensions/slack/package.json and extensions/slack/npm-shrinkwrap.json. Both edits are version-string-only (2026.6.11 → 2026.6.11-boon.5 to lockstep the plugin with the gateway tag; the shrinkwrap bump was itself requested in review). No dependency was added, removed, or upgraded — the guard flags any change to these files and requires a secops/admin override.

This needs sign-off from a security approver (openclaw-secops team / an admin) to clear both checks — it can't be self-resolved from the PR branch. Requesting the override when someone from secops has a moment.

🤖 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]>

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

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

Comment thread extensions/slack/src/send.ts Resolved
Comment thread extensions/slack/src/send.ts Resolved
@convyusboy

Copy link
Copy Markdown
Collaborator Author

/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]>
@convyusboy

Copy link
Copy Markdown
Collaborator Author

security-fast is a pre-existing, repo-wide dependency-audit failure — not a regression from this PR

security-fast fails at its "Audit production dependencies" step (pnpm audit --audit-level=high), which scans the entire production dependency graph — independent of this PR's diff. It reports 9 advisories that already exist on boon (the same set behind GitHub's "vulnerabilities on the default branch" banner):

This PR does not introduce or touch any of these packages. The only dependency-file change here is a two-line version-string bump in extensions/slack/{package.json,npm-shrinkwrap.json} (2026.6.11 → 2026.6.11-boon.5); none of the 9 advisory packages appear anywhere in the diff. dependency-guard (the check that does gate this PR's dep-file change) is green via the admin override.

Remediating these advisories means bumping the affected transitive deps at the root lockfile — a separate dependency-hygiene change that isn't in scope for the ENG-16286 threading fix, and that presumably reds security-fast on other open PRs too. Recommend proceeding on this PR and tracking the CVE bumps separately.

🤖 Generated with Claude Code

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

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.

@convyusboy
convyusboy merged commit a64758d into boon Jul 22, 2026
147 of 151 checks passed
@convyusboy
convyusboy deleted the ridho/eng-16286-guido-boon-agent-threading-broken-file-system-issues branch July 22, 2026 15:24
convyusboy added a commit that referenced this pull request Jul 23, 2026
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant