Skip to content

refactor: consolidate exact keyed async queues - #99691

Merged
RomneyDa merged 3 commits into
mainfrom
refactor/keyed-queue-consolidation
Jul 4, 2026
Merged

RomneyDa merged 3 commits into
mainfrom
refactor/keyed-queue-consolidation

Conversation

@RomneyDa

@RomneyDa RomneyDa commented Jul 3, 2026

Copy link
Copy Markdown
Member

Closes #99683

What Problem This Solves

OpenClaw carried repeated per-key promise-tail serializers across core and bundled plugins. Each copy independently implemented FIFO ordering, rejection recovery, unrelated-key parallelism, and final-tail cleanup, creating drift risk around the same concurrency invariant.

Why This Change Was Made

This migrates 23 exact-contract callers to the existing enqueueKeyedTask primitive in openclaw/plugin-sdk/keyed-async-queue. Caller-owned tail maps remain where drain, reset, or test behavior observes them.

Timeout eviction, close cancellation, debounce replacement, single-flight caching, and hybrid owner scheduling remain local; the shared helper gains no new options or policy.

User Impact

No intended user-visible behavior change. Maintainers and plugin developers now have one tested implementation for exact per-key FIFO serialization, with 244 fewer production lines across the migrated slice.

Evidence

  • node scripts/run-vitest.mjs run --maxWorkers=8 <14 explicit files>: 438 tests passed across 13 shards.
  • node scripts/run-vitest.mjs run --maxWorkers=8 <8 explicit files>: 246 tests passed across 7 shards.
  • node scripts/run-vitest.mjs run extensions/imessage/src/monitor/catchup.test.ts: 26 tests passed after the type correction.
  • Blacksmith Testbox-through-Crabbox tbx_01kwn3c71shq3s8nsbd4wkvn71: check:changed passed core/extension typechecks, core/extension lint, repository guards, and runtime import-cycle checks. Actions run: https://github.com/openclaw/openclaw/actions/runs/28686960340
  • .agents/skills/autoreview/scripts/autoreview --mode local --prompt-file /tmp/keyed-queue-review-notes.md --stream-engine-output: clean, no accepted/actionable findings, confidence 0.97.
  • git diff --numstat origin/main...HEAD: 114 additions, 358 deletions, net -244 lines across 23 production files.
  • git diff --check origin/main...HEAD: passed.

@RomneyDa
RomneyDa requested a review from a team as a code owner July 3, 2026 23:12
@openclaw-barnacle openclaw-barnacle Bot added channel: discord Channel integration: discord channel: imessage Channel integration: imessage channel: matrix Channel integration: matrix channel: msteams Channel integration: msteams channel: nostr Channel integration: nostr channel: slack Channel integration: slack channel: telegram Channel integration: telegram channel: whatsapp-web Channel integration: whatsapp-web gateway Gateway runtime extensions: memory-core Extension: memory-core agents Agent runtime and tooling extensions: codex size: M maintainer Maintainer-authored PR labels Jul 3, 2026
@clawsweeper

clawsweeper Bot commented Jul 3, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 4, 2026, 3:06 PM ET / 19:06 UTC.

Summary
The PR replaces repeated exact per-key promise-tail serializers across core and bundled plugins with the existing KeyedAsyncQueue / enqueueKeyedTask helper while retaining specialized queues outside that contract.

PR surface: Source -276, Tests -44. Total -320 across 30 files.

Reproducibility: not applicable. this is an internal refactor rather than a bug report. The reviewable behavior is source-level equivalence with the existing keyed queue contract and the linked maintainer cleanup request.

Review metrics: 2 noteworthy metrics.

  • Queue Callers Migrated: 23 production callers. The migration spans auth refresh, message delivery, config/session persistence, and plugin state paths, so exact-contract fit is the key merge question.
  • Shared Queue Surface Change: 0 new options or package exports. The PR reuses the existing helper instead of expanding the Plugin SDK queue API, which limits but does not eliminate compatibility risk.

Stored data model
Persistent data-model change detected: serialized state: extensions/codex/src/conversation-binding.ts, unknown-data-model-change: extensions/codex/src/app-server/session-binding.ts, unknown-data-model-change: extensions/memory-core/src/short-term-promotion.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #99683
Summary: This PR is the implementation candidate for the linked maintainer cleanup issue about exact keyed async queue consolidation.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

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:

  • Maintainer should review the final head across representative auth, session, gateway, and channel queue migrations.

Risk before merge

  • [P1] A subtle mismatch in the exact queue contract could affect OAuth refresh, session/transcript ordering, gateway reply mirroring, or channel send/persistence ordering even though the helper itself is tested.
  • [P1] The PR intentionally keeps a deprecated Plugin SDK accessor for compatibility; maintainers should confirm the deprecation shape is acceptable before merge.

Maintainer options:

  1. Sample the risky migrations (recommended)
    A maintainer should review representative auth, session, gateway, and channel call sites against the exact queue contract before merging.
  2. Accept the refactor as proven
    Maintainers may decide the focused tests, current CI, and Testbox proof sufficiently cover the broad consolidation risk.
  3. Split any non-exact caller
    If review finds a caller with cancellation, reset, drain, debounce, or owner-specific scheduling semantics, pause this PR and leave that caller local or move it to a narrower follow-up.

Next step before merge

  • [P2] Protected maintainer PR with no narrow repair finding; the remaining action is human review of broad queue-contract equivalence and final-head CI state.

Security
Cleared: The diff does not add dependencies, workflows, package hooks, downloaded artifacts, secret handling, or permission expansion; the auth-related concern is behavioral merge risk, not a new security finding.

Review details

Best possible solution:

Merge after a maintainer confirms each migrated caller only needs keyed FIFO ordering, rejection recovery, unrelated-key parallelism, and final-tail cleanup on the final head.

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

Not applicable: this is an internal refactor rather than a bug report. The reviewable behavior is source-level equivalence with the existing keyed queue contract and the linked maintainer cleanup request.

Is this the best way to solve the issue?

Yes, with maintainer confirmation: the existing Plugin SDK helper is the narrowest shared solution for exact keyed FIFO queues, while specialized cancellation, debounce, single-flight, and drain/reset queues should remain local.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 614e87cce1d4.

Label changes

Label justifications:

  • P3: This is maintainer cleanup with no intended user-visible behavior change, so it is low-priority but still useful to review.
  • merge-risk: 🚨 auth-provider: The diff changes OAuth refresh and Codex binding queue serialization where ordering mistakes could affect provider credentials or auth state.
  • merge-risk: 🚨 session-state: The diff changes ACP/session actor, transcript append, model config, and conversation binding queues where ordering drift could affect session state.
  • merge-risk: 🚨 message-delivery: The diff changes Slack, Telegram, Matrix, Discord, WhatsApp, iMessage, MS Teams, and gateway send/mirror queues where serialization mistakes could affect delivery ordering.
  • 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. Not applicable: The external-contributor proof gate does not apply to this maintainer/member PR; the PR instead provides targeted test, Testbox, CI, and autoreview evidence for the internal refactor.
Evidence reviewed

PR surface:

Source -276, Tests -44. Total -320 across 30 files.

View PR surface stats
Area Files Added Removed Net
Source 26 117 393 -276
Tests 4 19 63 -44
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 30 136 456 -320

What I checked:

  • Repository policy applied: Root and scoped AGENTS.md files were read; the applicable policy treats Plugin SDK, auth/provider routing, session state, and channel delivery as compatibility-sensitive review surfaces, and protected maintainer PRs must stay open for human handling. (AGENTS.md:28, 614e87cce1d4)
  • Live PR state: The live PR is open, mergeable, authored by a repository member, and carries the protected maintainer label plus existing auth-provider, session-state, and message-delivery merge-risk labels. (00abee4f3443)
  • Shared queue contract on main: Current main's helper serializes work per key, catches prior rejection before starting the next task, stores a void tail, deletes only the final matching tail, and exposes the small wrapper used by the PR. (src/plugin-sdk/keyed-async-queue.ts:9, 614e87cce1d4)
  • PR head preserves the SDK surface: The PR head retains getTailMapForTesting() as a deprecated Plugin SDK compatibility accessor and does not add queue options or new package exports. (src/plugin-sdk/keyed-async-queue.ts:38, 00abee4f3443)
  • Changed surface reviewed: The diff changes queue ownership in Codex binding, OAuth refresh, models/config writes, transcript append, gateway send mirroring, channel/plugin persistence, and skill/trajectory runtime helpers, without changing config, schemas, dependencies, workflows, or stored data formats. (00abee4f3443)
  • Codex contract checked: Sibling Codex source shows Thread stores the thread id after thread.started and subsequent run() / runStreamed() calls continue the same thread; this PR only serializes OpenClaw-side bound turns and does not change Codex protocol fields. (sdk/typescript/src/thread.ts:41)

Likely related people:

  • steipete: Peter Steinberger authored the commit that added src/plugin-sdk/keyed-async-queue.ts and its focused tests, which is the central helper this PR consolidates around. (role: introduced shared primitive; confidence: high; commits: 3a08e69a05a5, 045f42f111c2; files: src/plugin-sdk/keyed-async-queue.ts, src/plugin-sdk/keyed-async-queue.test.ts)
  • vincentkoc: Vincent Koc authored the keyed-queue SDK import/export stabilization commit touching src/plugin-sdk/core.ts and bundled plugin queue consumers, which overlaps the public SDK surface affected by this refactor. (role: recent SDK queue surface contributor; confidence: medium; commits: 1354f37c88da, e085fa1a3ffd; files: src/plugin-sdk/core.ts, extensions/matrix/src/matrix/sdk.ts, extensions/zalouser/src/monitor.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.
Review history (2 earlier review cycles)
  • reviewed 2026-07-04T03:44:57.413Z sha 36bcbd9 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-04T18:59:49.817Z sha 00abee4 :: needs maintainer review before merge. :: none

@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. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. labels Jul 3, 2026
@RomneyDa
RomneyDa force-pushed the refactor/keyed-queue-consolidation branch from 7a1f0de to 05a3e7a Compare July 3, 2026 23:25
@RomneyDa
RomneyDa force-pushed the refactor/keyed-queue-consolidation branch from ee9de1d to 36bcbd9 Compare July 4, 2026 03:37
@RomneyDa
RomneyDa force-pushed the refactor/keyed-queue-consolidation branch from 36bcbd9 to 00abee4 Compare July 4, 2026 18:53
@RomneyDa
RomneyDa merged commit c2fc7aa into main Jul 4, 2026
98 checks passed
@RomneyDa
RomneyDa deleted the refactor/keyed-queue-consolidation branch July 4, 2026 23:45
@RomneyDa

RomneyDa commented Jul 4, 2026

Copy link
Copy Markdown
Member Author

have thoroughly reviewed the risk labels and don't think any prod behavior will change with this deduplication.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 5, 2026
* refactor: consolidate keyed async queues

* chore: refresh merge-ref CI

* refactor: encapsulate keyed queue ownership
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: discord Channel integration: discord channel: imessage Channel integration: imessage channel: matrix Channel integration: matrix channel: msteams Channel integration: msteams channel: nostr Channel integration: nostr channel: slack Channel integration: slack channel: telegram Channel integration: telegram channel: whatsapp-web Channel integration: whatsapp-web extensions: codex extensions: memory-core Extension: memory-core gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. 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.

[Feature]: Consolidate exact keyed async queue implementations

1 participant