Skip to content

refactor(plugins): root-owned conversation-binding pending requests - #118075

Merged
steipete merged 1 commit into
mainfrom
refactor/conversation-binding-root-owned
Aug 2, 2026
Merged

steipete merged 1 commit into
mainfrom
refactor/conversation-binding-root-owned

Conversation

@steipete

@steipete steipete commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

src/plugins/conversation-binding.ts held its pending-approval requests in a process-global Map guarded by a Symbol.for global-registry slot — the last survivor of the shared-globals pattern the plugin lifecycle series (#117372, #117587, #117749) removed elsewhere. The Symbol indirection existed to survive a split-module emission bug that no longer exists, and the map had no lifecycle owner: nothing cleared it on gateway shutdown.

Why This Change Was Made

This is the pattern pilot for the remaining ambient-state sites. The Symbol originated in 65594f972c2c after a real external-Codex/lazy-Telegram split-module duplication failure. That risk is gone in the supported graph: tsdown.config.ts builds core, SDK subpaths, and bundled plugins in one unified emission specifically so singletons emit once. Verified against built output — a single dist/conversation-binding-*.js chunk imported by both SDK entrypoints, and the retired Symbol string appears nowhere in dist.

State analysis: pending approvals are cross-request, gateway-lifetime state (one request writes; a later channel callback reads and synchronously deletes). Not plugin contribution data (registry bundle), not request-local (ALS scope). The right owner is a lifecycle-owned module slot: deep SDK call paths keep ambient access, and the gateway root clears the slot during terminal shutdown (src/gateway/server-close.ts). The rent note at the slot documents the contract.

Also removed: the obsolete Symbol reset in tests, a synthetic cache-busted pending-request test that only proved the retired mechanism, and the unused requestedAt field (no TTL, no reader).

User Impact

None visible. Pending conversation-binding approvals behave identically; gateway shutdown now deterministically drops any orphaned pending requests instead of leaking them process-wide.

Evidence

  • 304 tests: 71 focused binding + gateway-close, 233 consumer suites (interactive, Discord, Telegram, Slack); post-rebase re-run 125/125 across the directly touched files
  • Both core tsgo lanes; targeted oxlint; import-cycle + madge 0 cycles; deadcode/unused-export audits 0 findings; full build clean; explicit vi.mock sweep
  • Built-output verification: one conversation-binding chunk in dist, Symbol string absent
  • Structured autoreview: clean
  • Numstat: 41 additions / 44 deletions overall; production +6/−7 (net −1 prod LOC)

🤖 Generated with Claude Code

@steipete
steipete marked this pull request as ready for review August 2, 2026 17:13
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: S maintainer Maintainer-authored PR labels Aug 2, 2026
@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. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Aug 2, 2026
@clawsweeper

clawsweeper Bot commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed August 2, 2026, 1:22 PM ET / 17:22 UTC.

ClawSweeper review

What this changes

This PR makes pending plugin conversation-binding approvals module-owned, clears them during gateway shutdown, and removes tests and fields tied to the retired process-global Symbol map.

Merge readiness

⚠️ Ready for maintainer review - 5 items remain

Keep this PR open for explicit maintainer handling: it has the protected maintainer label and is a current plugin/gateway lifecycle refactor. The code change is coherent and no discrete patch defect was found, but the remaining exact-head CI checks and the intended single-emission runtime invariant should be confirmed before merge.

Priority: P2
Reviewed head: 357947d931842e2727d703b7aaa4f85cd31f99d0
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch is focused, source-consistent, and backed by targeted lifecycle coverage, with remaining merge readiness dependent on exact-head CI and emitted-module confirmation.
Proof confidence 🌊 off-meta tidepool Not applicable: This protected maintainer-owned internal lifecycle refactor is exempt from the external-contributor proof gate; the merge decision should still use exact-head build output and a redacted shutdown transcript as stronger operational evidence.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This protected maintainer-owned internal lifecycle refactor is exempt from the external-contributor proof gate; the merge decision should still use exact-head build output and a redacted shutdown transcript as stronger operational evidence.
Evidence reviewed 7 items Current state owner: Current main stores pending requests in a process-global Symbol map, so the proposed replacement targets a real ambient-state owner boundary rather than a speculative cleanup.
Proposed lifecycle ownership: The branch replaces the Symbol-backed map with a module slot and exposes one clear function; approval creation and resolution continue to use the same map within that module.
Gateway terminal ordering: The branch clears pending approvals in the close handler's final cleanup, after the shutdown body has drained and torn down gateway work and immediately before clearing the active plugin registry.
Findings None None.
Security None None.

How this fits together

Plugin conversation binding creates an approval request during a command or interaction, then a later Telegram, Discord, or Slack callback resolves it. The request state must survive that cross-request interval but must not survive gateway shutdown or a subsequent gateway lifecycle.

flowchart LR
  A[Plugin requests conversation binding] --> B[Pending approval state]
  C[Telegram Discord or Slack callback] --> D[Resolve approval]
  B --> D
  E[Gateway shutdown] --> F[Clear pending approvals]
  F --> G[Fresh next gateway lifecycle]
Loading

Decision needed

Question Recommendation
Should this protected plugin/gateway ownership refactor merge once its remaining exact-head checks and emitted-module proof confirm the single-instance assumption? Merge after exact-head confirmation: Confirm the build artifact has one shared conversation-binding module and all required checks pass, then merge the bounded lifecycle refactor.

Why: The maintainer label requires explicit human handling, and the design intentionally removes the prior cross-module fallback rather than preserving it as compatibility scaffolding.

Before merge

  • Add real behavior proof - Not applicable: This protected maintainer-owned internal lifecycle refactor is exempt from the external-contributor proof gate; the merge decision should still use exact-head build output and a redacted shutdown transcript as stronger operational evidence.
  • Resolve merge risk (P1) - The safety of replacing the Symbol-backed map depends on the unified build continuing to emit one shared conversation-binding module for core and plugin-SDK consumers; the PR removes the duplicate-module regression test, so exact-head built-output proof is the key remaining guard.
  • Resolve merge risk (P1) - Several exact-head CI jobs were still in progress in the supplied status snapshot, so merge readiness is not yet established.
  • Complete next step (P2) - This is already a focused implementation PR; the remaining action is protected-label maintainer review and exact-head merge validation, not an automated repair.
Agent review details

Security

None.

PR surface

Source -2, Tests -1. Total -3 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 3 9 11 -2
Tests 2 32 33 -1
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 41 44 -3

Review metrics

None.

Merge-risk options

Maintainer options:

  1. Prove the emitted singleton before merge (recommended)
    Use exact-head build output and a shutdown transcript to verify callback consumers share the map and unresolved approvals expire when the gateway closes.
  2. Pause if packaging is not singular
    Do not merge this refactor if supported core and SDK entrypoints can still instantiate separate conversation-binding modules.

Technical review

Best possible solution:

Land the lifecycle-owned module slot only after exact-head build/runtime evidence confirms core and plugin-SDK callback paths share one emitted instance and gateway shutdown turns a pending approval into the existing expired outcome.

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

Not applicable: this PR is an internal ownership refactor, not a reported user-facing defect. Source inspection establishes the relevant state flow from request creation through channel callbacks and gateway shutdown.

Is this the best way to solve the issue?

Yes, conditionally: putting gateway-lifetime pending requests in a lifecycle-cleared module slot is the narrower canonical owner boundary, provided the unified output truly gives all supported consumers the same module instance.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 492b8841c837.

Labels

Label changes:

  • add P2: This is a bounded lifecycle refactor with no established user-visible regression, but it affects gateway restart behavior.
  • add merge-risk: 🚨 availability: The PR changes final gateway cleanup and can affect callback behavior during shutdown or restart if the module-instance invariant is wrong.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This protected maintainer-owned internal lifecycle refactor is exempt from the external-contributor proof gate; the merge decision should still use exact-head build output and a redacted shutdown transcript as stronger operational evidence.

Label justifications:

  • P2: This is a bounded lifecycle refactor with no established user-visible regression, but it affects gateway restart behavior.
  • merge-risk: 🚨 availability: The PR changes final gateway cleanup and can affect callback behavior during shutdown or restart if the module-instance invariant is wrong.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This protected maintainer-owned internal lifecycle refactor is exempt from the external-contributor proof gate; the merge decision should still use exact-head build output and a redacted shutdown transcript as stronger operational evidence.

Evidence

What I checked:

  • Current state owner: Current main stores pending requests in a process-global Symbol map, so the proposed replacement targets a real ambient-state owner boundary rather than a speculative cleanup. (src/plugins/conversation-binding.ts:118, 4c6e1f0d4cc1)
  • Proposed lifecycle ownership: The branch replaces the Symbol-backed map with a module slot and exposes one clear function; approval creation and resolution continue to use the same map within that module. (src/plugins/conversation-binding.ts:117, 357947d93184)
  • Gateway terminal ordering: The branch clears pending approvals in the close handler's final cleanup, after the shutdown body has drained and torn down gateway work and immediately before clearing the active plugin registry. (src/gateway/server-close.ts:1057, 357947d93184)
  • Shared callback surface: Telegram, Discord, and Slack callback handlers resolve approvals through the plugin SDK runtime surface; this makes a single emitted module instance the relevant invariant. (extensions/telegram/src/bot-handlers.callback-interactions.runtime.ts:262, 492b8841c837)
  • Build-topology basis: The build configuration assembles core, plugin-SDK, and bundled-plugin entries into one unified distribution entry set, supporting the branch's single-emission design assumption; this should remain covered by exact-head build proof. (tsdown.config.ts:485, 492b8841c837)
  • Feature provenance: The current pending-request Symbol map dates to the conversation-binding work introduced in commit 4c6e1f0; the branch's lifecycle slot and gateway-close cleanup are introduced by this PR commit. (src/plugins/conversation-binding.ts:117, 357947d93184)

Likely related people:

  • steipete: Introduced the proposed module-owned state and gateway cleanup, and has the strongest long-running contribution history across the central conversation-binding and close-handler files. (role: recent area contributor; confidence: high; commits: 357947d93184; files: src/plugins/conversation-binding.ts, src/gateway/server-close.ts)
  • Shakker: Introduced the current pending-request map in the recent conversation-binding implementation that this refactor replaces. (role: current behavior introducer; confidence: high; commits: 4c6e1f0d4cc1; files: src/plugins/conversation-binding.ts)
  • Harold Hunt: The historical global-state design traces back to the earlier interactive callback-state work, providing relevant context for why duplicate module instances were originally handled through a global Symbol. (role: feature-history contributor; confidence: medium; commits: 65594f972c2c; files: src/plugins/conversation-binding.ts)

Rank-up moves

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

  • Confirm the remaining required checks on the current head.
  • Retain or attach a redacted build/runtime transcript showing one shared emitted module and the shutdown-to-expired transition.

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

steipete commented Aug 2, 2026

Copy link
Copy Markdown
Contributor Author

Exact-head operational proof for the two remaining review items (head 357947d931842e2727d703b7aaa4f85cd31f99d0):

Single-emission invariant (exact-head build output). pnpm build at this head emits one implementation chunk, dist/conversation-binding-BbaiDojm.js; both SDK entrypoints (dist/plugin-sdk/conversation-runtime.js, dist/plugin-sdk/conversation-binding-runtime.js) import that same chunk exactly once. The retired Symbol.for registry string appears nowhere in dist/. The other conversation-binding-* chunks are distinct source modules (context, data, input, runtime wrapper), not duplicates of the pending-request module.

Shutdown transcript (dist-driven, ephemeral gateway, isolated OPENCLAW_STATE_DIR, loopback port 19257, redacted):

[gateway] ready
[heartbeat] started
[gateway] agent runtime plugins pre-warmed in 99ms
[admission] closed: restart drain
[gateway] received SIGTERM; shutting down
[shutdown] completed cleanly in 109ms

GET /health returned 200 before SIGTERM; the process exited cleanly on the signal, running the terminal close path that clears the pending-approval slot immediately before the active plugin registry is cleared.

Exact-head CI: green (all checks on 357947d9318).

@steipete
steipete merged commit 023ea46 into main Aug 2, 2026
180 of 196 checks passed
@steipete
steipete deleted the refactor/conversation-binding-root-owned branch August 2, 2026 18:10
@steipete

steipete commented Aug 2, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S 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.

1 participant