Skip to content

[Fix] Cache selected channel registry lookups - #80333

Merged
steipete merged 2 commits into
openclaw:mainfrom
samzong:fix/channel-registry-hotpath
May 11, 2026
Merged

steipete merged 2 commits into
openclaw:mainfrom
samzong:fix/channel-registry-hotpath

Conversation

@samzong

@samzong samzong commented May 10, 2026

Copy link
Copy Markdown
Contributor

Summary

Describe the problem and fix in 2-5 bullets:

If this PR fixes a plugin beta-release blocker, title it fix(<plugin-id>): beta blocker - <summary> and link the matching Beta blocker: <plugin-name> - <summary> issue labeled beta-blocker. Contributors cannot label PRs, so the title is the PR-side signal for maintainers and automation.

  • Problem: channel registry helpers rebuilt id/alias lookups with repeated scans, and version-only caches could go stale when a pinned empty channel registry fell back to a changed active registry.
  • Why it matters: inbound channel and native-command routing can call these helpers on hot paths, so stale or repeated lookup work affects message handling correctness and cost.
  • What changed: shared registered-channel lookup maps now cache by the selected registry snapshot, public channel registry/version helpers use the same selected snapshot semantics, and regression tests cover pinned-empty fallback swaps.
  • What did NOT change (scope boundary): no channel plugin loading policy, config contract, docs, or user-facing defaults changed.
  • AI-assisted: implemented and verified with Codex.

Change Type (select all)

  • Bug fix
  • Feature
  • Refactor required for the fix
  • Docs
  • Security hardening
  • Chore/infra

Scope (select all touched areas)

  • Gateway / orchestration
  • Skills / tool execution
  • Auth / tokens
  • Memory / storage
  • Integrations
  • API / contracts
  • UI / DX
  • CI/CD / infra

Linked Issue/PR

  • Closes #N/A
  • Related #N/A
  • This PR fixes a bug or regression

Real behavior proof (required for external PRs)

External contributors must show after-fix evidence from a real OpenClaw setup. Unit tests, mocks, lint, typechecks, snapshots, and CI are supplemental only. Screenshots are encouraged even for CLI, console, text, or log changes; terminal screenshots and copied live output count. Be mindful of private information like IP addresses, API keys, phone numbers, non-public endpoints, or other private details when providing evidence.

  • Behavior or issue addressed: pinned-empty channel registry fallback could leave native command surface routing cached for the previous active registry.
  • Real environment tested: local OpenClaw worktree on Darwin 25.4.0 arm64, Node v24.14.0, pnpm 10.33.2.
  • Exact steps or command run after this patch: node --import tsx --eval '<pinned-empty native command surface probe>'.
  • Evidence after fix (screenshot, recording, terminal capture, console output, redacted runtime log, linked artifact, or copied live output):
{"phase":"discord","discord":true,"slack":false}
{"phase":"slack","discord":false,"slack":true}
  • Observed result after fix: after swapping the active fallback registry from Discord to Slack, Discord is no longer treated as native and Slack is treated as native.
  • What was not tested: full live channel gateway traffic; this patch was validated with deterministic registry/runtime probes and targeted tests.
  • Before evidence (optional but encouraged): before the final cache-key fix, the same probe returned {"phase":"slack","discord":true,"slack":false} after switching to Slack.

Root Cause (if applicable)

For bug fixes or regressions, explain why this happened, not just what changed. Otherwise write N/A. If the cause is unclear, write Unknown.

  • Root cause: channel lookup and command routing caches used version keys that did not consistently represent the registry actually selected by pinned-empty fallback logic.
  • Missing detection / guardrail: tests covered pinned registries and active registries separately, but not the pinned-empty fallback active-registry swap path across dock commands and text-command gating.
  • Contributing context (if known): registered channel id/alias lookup helpers were duplicated across registry modules, which made it easier for cache semantics to drift.

Regression Test Plan (if applicable)

For bug fixes or regressions, name the smallest reliable test coverage that should catch this. Otherwise write N/A.

  • Coverage level that should have caught this:
    • Unit test
    • Seam / integration test
    • End-to-end test
    • Existing coverage already sufficient
  • Target test or file: src/channels/registry.helpers.test.ts, src/plugins/runtime.channel-pin.test.ts, src/auto-reply/commands-registry.test.ts.
  • Scenario the test should lock in: pinned empty channel registry falls back to the active registry, then active registry swaps from one native channel to another.
  • Why this is the smallest reliable guardrail: it exercises the runtime registry state, registered channel lookup cache, dock command cache, and native text-command gating without requiring live channel credentials.
  • Existing test that already covers this (if any): new tests added in this PR cover the missing cases.
  • If no new test is added, why not: N/A.

User-visible / Behavior Changes

Channel alias and native command routing now refresh correctly when a pinned empty channel registry falls back to a changed active registry. No config, CLI, docs, or defaults changed.

Diagram (if applicable)

Before:
[pinned empty channel registry] -> [active discord registry] -> [cache key uses pinned version]
[active slack registry] -> [same pinned cache key] -> [stale discord native surface]

After:
[pinned empty channel registry] -> [selected active discord registry/version] -> [discord native surface]
[active slack registry] -> [selected active slack registry/version] -> [slack native surface]

Security Impact (required)

  • New permissions/capabilities? (Yes/No): No
  • Secrets/tokens handling changed? (Yes/No): No
  • New/changed network calls? (Yes/No): No
  • Command/tool execution surface changed? (Yes/No): No
  • Data access scope changed? (Yes/No): No
  • If any Yes, explain risk + mitigation: N/A

Repro + Verification

Environment

  • OS: Darwin 25.4.0 arm64
  • Runtime/container: Node v24.14.0, pnpm 10.33.2
  • Model/provider: N/A
  • Integration/channel (if any): synthetic Discord and Slack channel plugin registries
  • Relevant config (redacted): N/A

Steps

  1. Start with an empty channel registry, pin it, then set the active registry to a Discord native-command channel.
  2. Query native command surface handling for Discord and Slack.
  3. Swap the active registry to a Slack native-command channel and query again.

Expected

  • Discord is native in the Discord phase and not native in the Slack phase.
  • Slack is not native in the Discord phase and native in the Slack phase.

Actual

  • Matches expected after this patch.

Evidence

Attach at least one:

  • Failing test/log before + passing after
  • Trace/log snippets
  • Screenshot/recording
  • Perf numbers (if relevant)

Human Verification (required)

What you personally verified (not just CI), and how:

  • Verified scenarios: pinned-empty fallback registry swap for registered channel normalization, dock command generation, native text-command gating, and public channel registry/version helpers.
  • Edge cases checked: selected registry grows in place, pinned non-empty registry remains preferred, pinned-empty active fallback refreshes after registry swap.
  • What you did not verify: live channel gateway traffic with real Discord or Slack credentials.

Review Conversations

  • I replied to or resolved every bot review conversation I addressed in this PR.
  • I left unresolved only the conversations that still need reviewer or maintainer judgment.

No bot review conversations exist yet for this PR.

Compatibility / Migration

  • Backward compatible? (Yes/No): Yes
  • Config/env changes? (Yes/No): No
  • Migration needed? (Yes/No): No
  • If yes, exact upgrade steps: N/A

Risks and Mitigations

  • Risk: public channel registry helper semantics now match selected fallback behavior, which could change callers that expected pinned-empty registries to stay selected.
    • Mitigation: existing pinned non-empty behavior is preserved, and new tests cover pinned-empty fallback plus public helper version refresh.

@openclaw-barnacle openclaw-barnacle Bot added size: M proof: supplied External PR includes structured after-fix real behavior proof. labels May 10, 2026
@clawsweeper

clawsweeper Bot commented May 10, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

Summary
The PR makes channel registry/version helpers use one selected channel-registry snapshot, adds a shared registered-channel lookup cache, and adds regression tests for pinned-empty fallback registry swaps.

Reproducibility: yes. Source inspection of current main shows the selected registry can fall back from an empty pinned registry to the active registry while the version helper still uses the pinned version; the PR body also includes before/after live probe output for the Discord-to-Slack swap path.

Real behavior proof
Sufficient (live_output): The PR body includes copied after-fix live output from a local OpenClaw runtime probe showing Discord native in the first phase and Slack native after the fallback registry swap.

Next step before merge
No ClawSweeper repair is needed because the PR already contains the focused implementation and I found no discrete actionable defect.

Security
Cleared: The diff changes in-process registry cache helpers, tests, and changelog only; it adds no dependencies, workflows, network calls, permissions, or secret handling.

Review details

Best possible solution:

Merge this focused selected-registry snapshot fix after normal CI and mergeability handling, keeping the regression tests and avoiding broader channel loading or config-policy changes.

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

Yes. Source inspection of current main shows the selected registry can fall back from an empty pinned registry to the active registry while the version helper still uses the pinned version; the PR body also includes before/after live probe output for the Discord-to-Slack swap path.

Is this the best way to solve the issue?

Yes. Centralizing selected-registry snapshot semantics and reusing that snapshot for lookup caches is the narrowest maintainable fix for this stale-cache path.

What I checked:

  • Current-main selected registry/version mismatch: Current main can select the active registry when the pinned channel registry is empty, but getActivePluginChannelRegistryVersionFromState still keys by the pinned channel registry whenever one exists. (src/plugins/runtime-channel-state.ts:20, da7cc2b11c76)
  • Current-main public helper mismatch: getActivePluginChannelRegistry returns the pinned registry when present, and getActivePluginChannelRegistryVersion returns the pinned channel version, so public runtime callers can disagree with the lower-level fallback selection. (src/plugins/runtime.ts:309, da7cc2b11c76)
  • Affected cache consumer: Chat command generation caches on getActivePluginChannelRegistryVersionFromState only, which is stale when an empty pinned registry falls back to a swapped active registry without changing the pinned version. (src/auto-reply/commands-registry.data.ts:43, da7cc2b11c76)
  • Affected native-command consumer: Native text-command gating caches by the selected registry object plus getActivePluginChannelRegistryVersion, so the public helper mismatch affects native command surface refresh behavior. (src/auto-reply/commands-text-routing.ts:18, da7cc2b11c76)
  • PR implementation evidence: The PR patch adds getActivePluginChannelRegistrySnapshotFromState, uses it from public registry helpers, and builds registered-channel lookup maps against the same selected registry/version snapshot. (src/plugins/runtime-channel-state.ts:20, aac3457dc716)
  • Regression coverage evidence: The PR adds tests for pinned-empty fallback active-registry swaps across dock commands, text-command gating, registered-channel normalization, public version refresh, and in-place channel growth. (src/auto-reply/commands-registry.test.ts:474, aac3457dc716)

Likely related people:

  • vincentkoc: Recent path history includes runtime channel registry state and cache work on the central files affected by this PR. (role: recent runtime registry contributor; confidence: high; commits: 0c4a19d060e7, 97b60b992ca8, 9656ae649cd9; files: src/plugins/runtime-channel-state.ts, src/channels/registry.ts, src/auto-reply/commands-registry.data.ts)
  • steipete: Recent history shows adjacent channel registry export trimming, command routing, runtime/bootstrap, and changelog work on the affected boundary. (role: adjacent channel and auto-reply contributor; confidence: medium; commits: b0899f34f66d, 636478c622ec, 82e8518bd7b5; files: src/channels/registry.ts, src/auto-reply/commands-registry.data.ts, src/auto-reply/commands-text-routing.ts)

Remaining risk / open question:

  • I did not run tests because this was a read-only checkout review; maintainer CI still needs to validate the latest head before merge.

Codex review notes: model gpt-5.5, reasoning high; reviewed against da7cc2b11c76.

@samzong
samzong force-pushed the fix/channel-registry-hotpath branch from af6e116 to d522510 Compare May 10, 2026 16:20
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 10, 2026
@samzong
samzong force-pushed the fix/channel-registry-hotpath branch from d522510 to 3fce95b Compare May 10, 2026 16:51
@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 10, 2026
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 10, 2026
@steipete
steipete force-pushed the fix/channel-registry-hotpath branch from 3fce95b to bd8f670 Compare May 11, 2026 12:26
@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 11, 2026
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 11, 2026
@steipete
steipete force-pushed the fix/channel-registry-hotpath branch from bd8f670 to 77a4626 Compare May 11, 2026 12:34
@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 11, 2026
@steipete
steipete force-pushed the fix/channel-registry-hotpath branch from 77a4626 to fd05c4c Compare May 11, 2026 12:38
@openclaw-barnacle openclaw-barnacle Bot added the gateway Gateway runtime label May 11, 2026
@steipete
steipete force-pushed the fix/channel-registry-hotpath branch from 1e95a86 to 95c8567 Compare May 11, 2026 12:52
@openclaw-barnacle openclaw-barnacle Bot removed the gateway Gateway runtime label May 11, 2026
@steipete
steipete merged commit 36aea97 into openclaw:main May 11, 2026
111 of 113 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Landed via rebase onto main in 36aea97. Thanks @samzong.

Proof:

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 24, 2026
jameslcowan pushed a commit to jameslcowan/openclaw that referenced this pull request Jun 2, 2026
sablehead pushed a commit to sablehead/openclaw that referenced this pull request Jun 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

proof: supplied External PR includes structured after-fix real behavior proof. size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants