Skip to content

fix: seed Slack thread context after reset#97100

Merged
bek91 merged 8 commits into
mainfrom
fix/slack-thread-seeding
Jun 28, 2026
Merged

fix: seed Slack thread context after reset#97100
bek91 merged 8 commits into
mainfrom
fix/slack-thread-seeding

Conversation

@bek91

@bek91 bek91 commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes #97073.

Slack replies in an existing thread after a session reset could start a new OpenClaw session without re-seeding Slack thread context. The Slack prepare path treated any existing thread session row as an existing turn, while session initialization could later roll that same row to a new sessionId under the reset policy. With channels.slack.thread.initialHistoryLimit=10 and thread.inheritParent=true, that meant the model could receive the new reply and route metadata, but not the prior Slack replies that the operator expected on the first turn of the reset session.

Why This Change Was Made

This change makes Slack prepare ask the session-store runtime whether the existing thread row should be considered fresh under the effective reset policy before deciding to suppress initial thread context. If the row exists but is stale, Slack prepare forces the initial Slack thread-history fetch and keeps the current fresh-existing-thread skip intact.

The session freshness helper centralizes the reset-policy comparison for plugin callers and preserves OpenClaw's provider-owned implicit-reset behavior, so provider-backed sessions are not unexpectedly treated as stale unless reset policy is explicitly configured.

User Impact

After a Slack thread session rolls past a daily or idle reset boundary, the next reply in that same Slack thread now starts the new OpenClaw session with the configured initial thread context. Fresh existing Slack threads still avoid repeated history injection, and initialHistoryLimit=0 still disables the Slack history fetch.

Evidence

  • pnpm format -- src/plugin-sdk/session-store-runtime.ts src/plugin-sdk/session-store-runtime.test.ts extensions/slack/src/monitor/message-handler/prepare.test.ts
  • node --max-old-space-size=8192 --import tsx scripts/generate-plugin-sdk-api-baseline.ts --write
  • pnpm format:check -- src/plugin-sdk/session-store-runtime.ts src/plugin-sdk/session-store-runtime.test.ts extensions/slack/src/monitor/config.runtime.ts extensions/slack/src/monitor/message-handler/prepare-thread-context.ts extensions/slack/src/monitor/message-handler/prepare.ts extensions/slack/src/monitor/message-handler/prepare.test.ts scripts/lib/plugin-sdk-doc-metadata.ts
  • node --max-old-space-size=8192 --import tsx scripts/generate-plugin-sdk-api-baseline.ts --check
  • node --max-old-space-size=8192 scripts/plugin-sdk-surface-report.mjs --check
  • node scripts/check-plugin-sdk-subpath-exports.mjs
  • node scripts/run-vitest.mjs src/plugin-sdk/session-store-runtime.test.ts extensions/slack/src/monitor/message-handler/prepare.test.ts extensions/slack/src/monitor/message-handler/prepare-thread-context.test.ts src/plugin-sdk/api-baseline.test.ts src/plugins/contracts/plugin-sdk-subpaths.test.ts
  • pnpm build
  • git diff --check
  • codex review --base origin/main clean after the provider-owned session fix
  • .agents/skills/autoreview/scripts/autoreview --mode local clean

Not run: full pnpm check and full test suite; this was validated with focused Slack/session-store/API-surface coverage plus build.

AI Assistance

Implemented with Codex assistance. I reviewed the generated changes, ran the validation above, and addressed the initial review finding about provider-owned implicit-reset semantics before opening this draft PR.

Screenshots: not applicable; this is Slack/session-context runtime behavior.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation channel: slack Channel integration: slack scripts Repository scripts size: L maintainer Maintainer-authored PR labels Jun 26, 2026
@clawsweeper

clawsweeper Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed June 28, 2026, 2:31 AM ET / 06:31 UTC.

Summary
The PR adds a reset-freshness resolver for session entries, wires Slack prepare through the host channel runtime to reseed bounded thread history after stale thread-session rollover, and adds focused Slack/session tests plus SDK testing docs updates.

PR surface: Source +186, Tests +538, Docs 0, Generated 0, Other +3. Total +727 across 21 files.

Reproducibility: yes. Current main is source-reproducible by creating an existing Slack thread row that is stale under the reset policy, then preparing a reply in that thread: Slack's timestamp gate skips history while session initialization would roll the row to a fresh session.

Review metrics: 2 noteworthy metrics.

  • Runtime/session surfaces: 1 helper added, 1 host runtime method added, 1 Slack decision changed. The change crosses the Slack prepare path and core session freshness boundary, which is why compatibility and session-state review matter before merge.
  • Focused reset coverage: 4 Slack thread cases added, 8 session freshness cases added. The new coverage checks the risky stale/fresh/provider-owned/zero-history branches that decide whether history is reseeded.

Stored data model
Persistent data-model change detected: serialized state: src/config/sessions/cli-session-binding.ts, serialized state: src/config/sessions/entry-freshness.test.ts, serialized state: src/config/sessions/entry-freshness.ts, unknown-data-model-change: src/config/sessions/cli-session-binding.ts, unknown-data-model-change: src/config/sessions/entry-freshness.test.ts, unknown-data-model-change: src/config/sessions/entry-freshness.ts. Confirm migration or upgrade compatibility proof before merge.

Merge readiness
Overall: 🐚 platinum hermit
Proof: 🦞 diamond lobster
Patch quality: 🐚 platinum hermit
Result: ready for maintainer review.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • none.

Risk before merge

  • [P1] Merging changes the first post-reset Slack thread prompt for existing users by treating stale thread rows as first turns for bounded Slack API context, so maintainers should explicitly accept that compatibility behavior.
  • [P1] The PR intentionally solves only bounded native Slack thread-history reseeding; broader reset-family continuity and carryover summaries remain separate product work.

Maintainer options:

  1. Accept Scoped Slack Reseeding (recommended)
    Maintainers can accept the intentional behavior change that stale Slack thread rows reseed bounded native thread context while fresh rows, direct-monitor fallback, and initialHistoryLimit: 0 stay guarded.
  2. Ask For A Typed Runtime Contract
    If maintainers want this helper to become a formal channel runtime surface, require a typed contract update before merge instead of relying on the current internal runtime slot.
  3. Pause For Broader Continuity Design
    If bounded Slack history is not the desired product answer, pause this PR and route the work to the broader reset-family history/carryover PRs instead.

Next step before merge

  • No automated repair lane is queued because the previous concrete blocker is fixed on the latest head; the remaining action is maintainer review of the protected session-state compatibility change and normal merge gates.

Security
Cleared: The diff does not change workflows, dependencies, lockfiles, secret handling, or external code execution paths; the Slack context expansion reuses existing native thread-history filtering.

Review details

Best possible solution:

Land the narrow reset-aware Slack reseeding fix after maintainer acceptance, while leaving broader rollover continuity to the separate family-history or carryover work.

Do we have a high-confidence way to reproduce the issue?

Yes. Current main is source-reproducible by creating an existing Slack thread row that is stale under the reset policy, then preparing a reply in that thread: Slack's timestamp gate skips history while session initialization would roll the row to a fresh session.

Is this the best way to solve the issue?

Yes. The latest head is the best narrow fix for this bug: it aligns Slack's initial thread-history gate with the same reset freshness semantics as session initialization, preserves the direct-monitor/fresh/zero-history cases, and avoids replaying archived transcripts.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 119dc4bd821e.

Label changes

Label changes:

  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): Live Slack/API proof in the PR discussion demonstrates the central stale-thread reseeding path, and the later production follow-up only restores direct-monitor fallback while focused tests cover that caller shape.
  • remove rating: 🧂 unranked krab: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: This is a normal-priority Slack/session-context bug fix with concrete user impact but no core outage, security emergency, or release-blocker signal.
  • merge-risk: 🚨 compatibility: Existing Slack users can see different first-turn prompt context after a daily or idle session rollover because stale rows now reseed bounded native thread history.
  • merge-risk: 🚨 session-state: The PR changes how Slack prepare interprets persisted thread session freshness before session initialization rotates or reuses state.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): Live Slack/API proof in the PR discussion demonstrates the central stale-thread reseeding path, and the later production follow-up only restores direct-monitor fallback while focused tests cover that caller shape.
  • proof: sufficient: Contributor real behavior proof is sufficient. Live Slack/API proof in the PR discussion demonstrates the central stale-thread reseeding path, and the later production follow-up only restores direct-monitor fallback while focused tests cover that caller shape.
Evidence reviewed

PR surface:

Source +186, Tests +538, Docs 0, Generated 0, Other +3. Total +727 across 21 files.

View PR surface stats
Area Files Added Removed Net
Source 12 272 86 +186
Tests 6 541 3 +538
Docs 1 5 5 0
Config 0 0 0 0
Generated 1 2 2 0
Other 1 3 0 +3
Total 21 823 96 +727

What I checked:

Likely related people:

  • sourman: PR metadata for fix(slack): reduce token bloat by skipping thread context on existing sessions #32133 shows sourman authored the merged Slack bloat-guard change that skipped thread context on existing sessions, the Slack-side gate this PR adjusts. (role: introduced related Slack history optimization; confidence: high; commits: 201aee6c7c58, 2438fde6d9ba; files: src/slack/monitor/message-handler/prepare.ts, src/slack/monitor/message-handler/prepare.test.ts, extensions/slack/src/monitor/message-handler/prepare-thread-context.ts)
  • steipete: steipete merged PR 32133 and authored the daily reset policy history that defines the stale-session rollover behavior involved here. (role: merger and adjacent session lifecycle contributor; confidence: high; commits: 2438fde6d9ba, 367826f6e4e9; files: src/slack/monitor/message-handler/prepare.test.ts, src/auto-reply/reply/session.ts)
  • vincentkoc: Vincent Koc isolated reset-policy helpers used by the freshness path and recently merged adjacent current-main session/runtime changes. (role: adjacent reset-policy contributor and merger; confidence: medium; commits: c70be4b4afd0, 5ccfc97b31e3; files: src/config/sessions/reset-policy.ts, src/config/sessions/reset.ts, extensions/slack/src/monitor/message-handler/prepare-thread-context.ts)
  • Ayaan Zaidi: Ayaan Zaidi recently changed reply session initialization serialization on the same session initialization path that evaluates freshness and rolls stale entries. (role: recent session initialization contributor; confidence: medium; commits: d2da8c79d9b8; files: src/auto-reply/reply/session.ts, src/auto-reply/reply/session.test.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. labels Jun 26, 2026
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Jun 26, 2026
@openclaw-mantis

openclaw-mantis Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Mantis Slack Desktop Smoke QA

Summary: Mantis ran Slack QA scenario 'slack-thread-reset-history' inside a Crabbox Linux VNC desktop, opened Slack Web in the visible browser, and captured screenshot/video evidence.

Slack desktop/VNC browser

Slack Web desktop screenshot from the Mantis VM

Slack motion preview

Animated Slack desktop preview

Motion-trimmed clips:

Full videos:

Raw QA files: https://artifacts.openclaw.ai/mantis/slack-desktop-smoke/pr-97100/run-28272220693-1/index.json

@harjothkhara

Copy link
Copy Markdown
Contributor

Non-maintainer review note after checking the Mantis artifact: the posted Slack smoke failure does not appear to reach the PR's Slack reset scenario. The run fails during remote hydration before the gateway/QA path starts, with pnpm install --frozen-lockfile --prefer-offline aborting through Corepack on Node v22.22.1:

TypeError [ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING]: A dynamic import callback was not specified.

The artifact report shows crabbox.remote_run failed and the command log stops at that pnpm/Corepack error, with no slack-qa report/output from the slack-thread-reset-history scenario. So I would treat the current Mantis result as infrastructure-blocked proof rather than evidence against the resolveSessionEntryFreshness / Slack thread-history change. The branch still needs a successful real Slack run or a rerun using a prehydrated/fixed remote environment before the behavior proof gap is closed.

@clawsweeper clawsweeper Bot added the merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. label Jun 26, 2026
@clawsweeper clawsweeper Bot added the merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. label Jun 26, 2026
@bek91
bek91 force-pushed the fix/slack-thread-seeding branch from 00f41c7 to 50e70ec Compare June 27, 2026 00:34
@clawsweeper clawsweeper Bot removed the merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. label Jun 27, 2026
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Jun 28, 2026
@bek91

bek91 commented Jun 28, 2026

Copy link
Copy Markdown
Contributor Author

Live Slack proof for stale thread reseeding

I reran a live Slack proof against the current PR head a7643c4306b1c66fc3d914955b37c0e4b82bc0dc.

Proof shape: real Slack thread/API + PR prepare-path proof. This did not require a model turn; it verifies the exact pre-agent context path that decides whether a stale Slack thread session should reseed prior thread history.

Slack evidence:

  • Workspace/team: T09FU0EKW01
  • Channel: #pr-testing (C0BD43A9YEB)
  • Human root message ts: 1782625496.004519
  • Human prior thread reply ts: 1782625507.945129
  • Human current bot-mentioned follow-up ts: 1782625521.637899

OpenClaw setup:

  • Created an isolated local session store for the proof run.
  • Seeded the matching thread session as stale: agent:main:slack:channel:c0bd43a9yeb:thread:1782625496.004519
  • Ran the PR Slack prepareSlackMessage path against the real current Slack thread reply.

Checks:

  • PASS prepared
  • PASS sessionKeyMatchesThread
  • PASS staleThreadMarkedFirstTurn
  • PASS threadStarterIncluded
  • PASS priorContextIncluded
  • PASS rootContextIncluded
  • PASS currentMessageExcludedFromThreadHistory
  • PASS currentMessageIsBodyForAgent

Result: PASS. The prepared agent context included the real prior Slack thread context after the stale reset condition, while excluding the current message from the reseeded thread history and preserving it as the current user input.

Scope note: this is intentionally narrower than a full Socket Mode gateway/model reply proof. It exercises real Slack history plus the changed OpenClaw prepare/context path, which is the regression surface for #97073.

Screenshot note: the attached screenshot is visual context for the Slack thread used in this run. The assertion list above is the actual proof signal for ClawSweeper/review.

Screenshot 2026-06-28 at 1 53 02 AM

@bek91

bek91 commented Jun 28, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jun 28, 2026
@bek91

bek91 commented Jun 28, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Jun 28, 2026
@bek91
bek91 merged commit 9c95abd into main Jun 28, 2026
113 of 117 checks passed
@bek91
bek91 deleted the fix/slack-thread-seeding branch June 28, 2026 06:36
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jun 29, 2026
QiuYuang pushed a commit to QiuYuang/openclaw that referenced this pull request Jul 1, 2026
chenyangjun-xy pushed a commit to chenyangjun-xy/openclaw that referenced this pull request Jul 1, 2026
chenyangjun-xy pushed a commit to chenyangjun-xy/openclaw that referenced this pull request Jul 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling channel: slack Channel integration: slack docs Improvements or additions to documentation maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. scripts Repository scripts size: L status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Slack thread replies after daily reset should seed thread history

2 participants