Skip to content

refactor(channels): own thread binding cleanup in managers - #124221

Merged
steipete merged 2 commits into
mainfrom
test/remove-thread-binding-resets
Aug 15, 2026
Merged

steipete merged 2 commits into
mainfrom
test/remove-thread-binding-resets

Conversation

@steipete

@steipete steipete commented Aug 15, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Telegram and Matrix thread-binding tests relied on aggregate reset functions that stopped every manager and cleared global maps. Telegram’s production stop() removed the adapter/manager but left live account bindings behind, so the test reset—not the lifecycle owner—was responsible for invalidation. Core contract tests also loaded a Telegram test-only sidecar solely to call that reset.

Why This Change Was Made

The currently registered manager generation now owns live binding cleanup in stop(). Persisted rows are intentionally untouched and reload on restart; non-persisted bindings disappear. The authoritative-manager check prevents a stale retained manager from clearing a replacement generation.

Tests retain and stop the managers they create. Telegram restart cases now stop and recreate the manager, including persisted unbinds, metadata, stale ACP cleanup, read failures, and lifecycle updates. Matrix tests use the existing stop() owner. The core registry contract retains Matrix/Telegram managers, loads Telegram through its real channel-plugin-api, and deletes Telegram’s obsolete session-binding-contract-api.ts sidecar.

User Impact

Account shutdown no longer leaves stale live Telegram binding rows in process memory. Persisted binding behavior is unchanged and remains covered across restart. Matrix keeps its existing lifecycle behavior with a stronger authoritative-generation guard.

Evidence

  • Telegram owner suite, Matrix owner suite, and registry-backed session-binding contract — 32 tests passed
  • The same three routed shards with --isolate=false — 32 passed
  • The Telegram transient-cleanup regression failed against the prior implementation because the stopped manager's live binding remained
  • The Matrix stale-generation regression failed against the prior implementation because a retained manager cleared the replacement generation's binding
  • Telegram's registry-backed contract now loads channel-plugin-api.js through the standard bundled-plugin public facade
  • node scripts/check-changed.mjs -- <changed files> — passed via the documented local fallback; core/extension type checks, lint, dead exports, runtime sidecars, plugin boundaries, auth guards, native schema guard, and import cycles were green
  • pnpm build — passed, including bundled artifact generation after deleting the Telegram sidecar
  • git diff --check — passed
  • Structured autoreview after addressing the exact-head ClawSweeper findings — clean

Production delta: -10 net lines. Test/test-support delta: +70 net lines. Total delta: +60 lines; the test-support growth replaces reset APIs with explicit manager lifecycle ownership and adds pre-fix-failing lifecycle proof. No SQLite schema, protocol, docs, or changelog change is required.

@clawsweeper

clawsweeper Bot commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@steipete
steipete marked this pull request as ready for review August 15, 2026 18:11
@openclaw-barnacle openclaw-barnacle Bot added channel: matrix Channel integration: matrix channel: telegram Channel integration: telegram size: M maintainer Maintainer-authored PR labels Aug 15, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 15, 2026
@clawsweeper

clawsweeper Bot commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

Codex review: found issues before merge. Reviewed August 15, 2026, 2:17 PM ET / 18:17 UTC.

ClawSweeper review

What this changes

This PR makes Telegram and Matrix managers clear their own live thread bindings on stop, replaces aggregate test resets with explicit manager teardown, and removes Telegram’s obsolete test sidecar.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep this protected maintainer PR open. The lifecycle repair is coherent, but its new Telegram contract load bypasses the standard public facade and the tests do not directly prove the live-binding cleanup it changes.

Priority: P2
Reviewed head: a713e1b0ada2d5271ea6e84cba39b4607a3fa0a9

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The lifecycle repair is sound by source, but a public-facade correction and direct regression proof remain before it is quality-ready.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored internal lifecycle refactor is exempt from the external contributor real-behavior-proof gate; focused owner-boundary regression coverage remains needed.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored internal lifecycle refactor is exempt from the external contributor real-behavior-proof gate; focused owner-boundary regression coverage remains needed.
Evidence reviewed 6 items Current-main defect: Current main removes the Telegram manager on stop but leaves its account’s live binding map unchanged.
Owner-boundary repair: The PR clears bindings only after confirming the stopping manager remains authoritative, without deleting persisted rows.
Public-facade contract: The repository public-surface loader provides the supported bundled-plugin facade boundary, including artifact normalization and root validation.
Findings 1 actionable finding [P2] Load Telegram through the public bundled-plugin facade
Security None None.

How this fits together

Telegram and Matrix account managers maintain in-memory conversation-to-session bindings while accounts run. Stopping an authoritative manager should discard only live state, while persisted rows are reloaded on the next manager startup.

flowchart LR
  A[Channel account starts] --> B[Thread-binding manager]
  B --> C[Live binding map]
  B --> D[Persisted binding store]
  E[Account stop] --> F[Authoritative manager check]
  F --> C
  D --> G[Bindings reload on restart]
Loading

Before merge

  • Load Telegram through the public bundled-plugin facade (P2) - This new contract path uses the local runtime-artifact resolver instead of the standard public-surface loader. Use loadBundledPluginFacade for channel-plugin-api.js so the contract test exercises the supported facade boundary and its validation.
  • Resolve merge risk (P1) - The changed live session-state invariant lacks a pre-fix-failing regression: current converted restart tests still pass when the prior implementation retains in-memory bindings.

Findings

  • [P2] Load Telegram through the public bundled-plugin facade — src/channels/plugins/contracts/test-helpers/registry-session-binding.ts:241-243
Agent review details

Security

None.

PR surface

Source +8, Tests -5. Total +3 across 8 files.

View PR surface stats
Area Files Added Removed Net
Source 6 61 53 +8
Tests 2 60 65 -5
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 8 121 118 +3

Review metrics

Metric Value Why it matters
Production vs test delta production -10; tests/test-support +13 The patch is net-negative in production while test-support replaces aggregate resets with explicit manager ownership.

Merge-risk options

Maintainer options:

  1. Prove manager-owned cleanup before merge (recommended)
    Switch the Telegram contract load to the public facade and add direct lifecycle coverage for transient removal, persisted reload, and stale-manager safety.

Technical review

Best possible solution:

Use the standard bundled public facade for Telegram and add focused tests proving transient bindings disappear on stop, persisted bindings reload, and a stale manager cannot clear a replacement.

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

Yes, from source: on current main, bind a non-persistent Telegram conversation and stop its authoritative manager; the manager is removed but the live binding remains. This read-only review did not execute that scenario.

Is this the best way to solve the issue?

No: manager-owned cleanup is the right design, but the new core contract load must use the public facade and the changed live-state behavior needs direct regression proof.

Full review comments:

  • [P2] Load Telegram through the public bundled-plugin facade — src/channels/plugins/contracts/test-helpers/registry-session-binding.ts:241-243
    This new contract path uses the local runtime-artifact resolver instead of the standard public-surface loader. Use loadBundledPluginFacade for channel-plugin-api.js so the contract test exercises the supported facade boundary and its validation.
    Confidence: 0.9

Overall correctness: patch is incorrect
Overall confidence: 0.9

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 8f59226bc93a.

Labels

Label changes:

  • add P2: This is a bounded channel lifecycle repair with a concrete contract-boundary defect and unproven session-state invariant.
  • add merge-risk: 🚨 session-state: The PR changes how live conversation-to-session bindings are cleared and restored around account stop and restart.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: This maintainer-authored internal lifecycle refactor is exempt from the external contributor real-behavior-proof gate; focused owner-boundary regression coverage remains needed.

Label justifications:

  • P2: This is a bounded channel lifecycle repair with a concrete contract-boundary defect and unproven session-state invariant.
  • merge-risk: 🚨 session-state: The PR changes how live conversation-to-session bindings are cleared and restored around account stop and restart.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: This maintainer-authored internal lifecycle refactor is exempt from the external contributor real-behavior-proof gate; focused owner-boundary regression coverage remains needed.

Evidence

What I checked:

Likely related people:

  • steipete: Commit 3d643f7 introduced the current thread-binding and contract-helper surfaces, and this PR continues the same lifecycle work. (role: initial implementation author and recent lifecycle contributor; confidence: high; commits: 3d643f7b7b60, a713e1b0ada2; files: extensions/telegram/src/thread-bindings.ts, extensions/matrix/src/matrix/thread-bindings.ts, src/channels/plugins/contracts/test-helpers/registry-session-binding.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Load Telegram’s channel API with the standard bundled public facade.
  • Add a pre-fix-failing test for transient binding removal on stop and stale-generation safety.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
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.

Workflow

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

@steipete

Copy link
Copy Markdown
Contributor Author

Land-ready proof for 68c278371868fa0d4fa50c9ae95d4811ec5932c0:

  • Applied both items from the latest ClawSweeper review: Telegram now loads channel-plugin-api.js through loadBundledPluginFacade, and direct Telegram/Matrix manager-lifecycle regressions cover transient cleanup plus stale-generation safety.
  • The Telegram transient-cleanup regression failed against the prior implementation because the stopped manager's binding remained.
  • The Matrix stale-generation regression failed against the prior implementation because the retained old manager cleared the replacement binding.
  • node scripts/run-vitest.mjs src/channels/plugins/contracts/session-binding.registry-backed.contract.test.ts extensions/telegram/src/thread-bindings.test.ts extensions/matrix/src/matrix/thread-bindings.test.ts — 32 passed.
  • The same three routed shards with --isolate=false — 32 passed.
  • node scripts/check-changed.mjs -- <changed files> — passed via the documented local fallback after no remote provider was ready.
  • pnpm build — passed.
  • git diff --check — passed.
  • Fresh structured autoreview after the review fixes — clean.
  • Exact-head hosted CI — green: https://github.com/openclaw/openclaw/actions/runs/31901303287
  • OPENCLAW_TESTBOX=1 scripts/pr prepare-run 124221 — complete. The native wrapper accepted exact hosted CI in hosted_exact_or_recent_parent mode; no separate remote lease or Testbox run was used.
  • Native review artifacts validated with READY FOR /prepare-pr and zero findings.

The latest ClawSweeper comment reviewed the prior head and listed exactly the two items above: #124221 (comment). Both rank-up moves are applied; the post-review commit contains only those requested proof/boundary corrections.

Known proof gaps: none for this internal manager-lifecycle refactor. No SQLite schema, protocol, docs, changelog, or live-channel behavior changed.

@steipete
steipete merged commit 1db88fe into main Aug 15, 2026
220 checks passed
@steipete
steipete deleted the test/remove-thread-binding-resets branch August 15, 2026 18:35
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 16, 2026
…124221)

* refactor(channels): own thread binding cleanup in managers

* test(channels): prove thread binding lifecycle cleanup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: matrix Channel integration: matrix channel: telegram Channel integration: telegram maintainer Maintainer-authored PR merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: M status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant