Skip to content

fix: canonicalize single-flight promise caching - #118245

Merged
steipete merged 3 commits into
mainfrom
cleanup/single-flight-adoption
Aug 2, 2026
Merged

steipete merged 3 commits into
mainfrom
cleanup/single-flight-adoption

Conversation

@steipete

@steipete steipete commented Aug 2, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

OpenClaw had many keyed single-flight maps that repeated the same create/store/settle/delete lifecycle. The canonical getOrCreatePromise helper only supported sticky promises, so callers hand-rolled cleanup and two durable caches retained rejected promises indefinitely.

In particular, one failed CLI channel sender load poisoned both a keyed sender cache and a nested sticky lazy-runtime cache until restart. Local audio inspection likewise retained rejected probe promises until its test-only cache clear.

Why This Change Was Made

This widens getOrCreatePromise with two explicit, identity-safe lifecycle policies while preserving sticky behavior for every existing caller:

  • cacheRejections: false retains successful values but evicts the exact rejected promise.
  • evictOnSettled: true models maps that own only in-flight work.

The CLI sender now has one keyed cache instead of two nested sticky caches. Ten clean keyed hand-rolls use the canonical helper, delivery-queue media GC uses the existing single-slot lazy loader, and three TUI refresh loops share one coalesce-plus-rerun owner.

Two surveyed sites were deliberately left alone after direct inspection: iOS approval push pending state is a cleanup projection rather than a single-flight cache, and media cleanup starts synchronously while the lazy loader starts on a microtask. Canonicalizing either would change behavior.

User Impact

A transient channel sender load failure or rejected local-audio inspection can recover on the next request instead of requiring an OpenClaw restart. Successful cache behavior, cooldowns, LRU limits, status projections, and existing single-flight semantics remain unchanged.

Production code is net 10 lines smaller. Tests add 125 lines of regression and lifecycle coverage.

Evidence

  • node scripts/run-vitest.mjs src/shared/lazy-promise.test.ts src/cli/deps.test.ts src/media-understanding/local-audio.test.ts
    • 3 shards passed; 22 tests passed.
  • node scripts/run-vitest.mjs src/gateway/server-methods/skills.clawhub.test.ts src/gateway/node-pairing-ssh-verify.test.ts src/media/playback-transcode.test.ts src/gateway/user-profiles-http.test.ts src/gateway/dashboard-session-title.test.ts src/gateway/mcp-app-reconstruction.test.ts src/infra/outbound/delivery-queue-migration.test.ts src/gateway/control-ui.http.test.ts src/gateway/server.sessions.reset-cleanup.test.ts src/node-host/local-id.test.ts src/gateway/server-maintenance.test.ts
    • 4 shards passed; 309 tests passed.
  • node scripts/run-vitest.mjs src/tui/tui-plugin-approvals.test.ts src/tui/tui-task-suggestions.test.ts src/tui/tui-session-actions.test.ts
    • 1 shard passed; 101 tests passed after the final CI type-contract adjustment.
  • node scripts/check-changed.mjs
    • Correctly delegated the heavy plan, but no remote provider was ready; Blacksmith doctor failed and managed cloud brokers were unavailable. No forbidden local fallback was run.
  • Targeted oxfmt on all 24 touched files: passed.
  • git diff --check: passed.
  • .agents/skills/autoreview/scripts/autoreview --mode uncommitted --stream-engine-output: clean before commit and clean again after the CI fix, with no accepted/actionable findings.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime cli CLI command changes agents Agent runtime and tooling size: L maintainer Maintainer-authored PR labels Aug 2, 2026
@steipete
steipete marked this pull request as ready for review August 2, 2026 22:14
@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. labels Aug 2, 2026
@clawsweeper clawsweeper Bot added the P2 Normal backlog priority with limited blast radius. label 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, 6:35 PM ET / 22:35 UTC.

ClawSweeper review

What this changes

This PR adds explicit retry-on-rejection and evict-on-settlement policies to OpenClaw’s keyed promise cache, then replaces repeated single-flight lifecycle code across CLI, Gateway, media, node-host, and TUI refresh flows.

Merge readiness

⛔ Blocked until real behavior proof from a real setup is added - 4 items remain

Keep this PR open. The patch is a coherent owner-boundary consolidation: the keyed helper now provides identity-safe rejection and settled-work eviction, and the changed callers preserve their prior sticky or in-flight semantics. No discrete correctness regression was established from the current diff, but the PR still lacks after-fix runtime evidence showing that a transient failure actually recovers on the next request; its protected maintainer label also requires human handling rather than automated cleanup.

Priority: P2
Reviewed head: 6c9ef997b933bc524df3234a3f5b1694bd0961c3

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The implementation and targeted regression coverage look coherent, but missing real after-fix recovery evidence remains a merge gate.
Proof confidence 🦪 silver shellfish (2/6) Needs real behavior proof before merge: The PR body reports focused tests and static checks, but it does not include after-fix runtime output demonstrating a real transient failure followed by recovery; add a redacted terminal transcript, live output, recording, or runtime log before merge. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Needs proof Needs real behavior proof before merge: The PR body reports focused tests and static checks, but it does not include after-fix runtime output demonstrating a real transient failure followed by recovery; add a redacted terminal transcript, live output, recording, or runtime log before merge. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed 5 items Shared helper contract: The proposed helper retains the existing cached-promise fast path, records the newly created promise before attaching lifecycle cleanup, and deletes only when the map still holds that exact promise; this preserves replacement safety while adding explicit cache policies.
Regression coverage: The branch adds helper-level tests for sticky rejection caching, retryable rejection eviction, settled in-flight eviction, and identity-safe replacement handling, plus focused retry tests for CLI sender loading and local-audio inspection.
Caller lifecycle comparison: The inspected Gateway and CLI callers replace their local identity-checked cleanup with the helper’s corresponding policy: retryable caching for the CLI sender and settled-work eviction for deduplicated Gateway operations.
Findings None None.
Security None None.

How this fits together

OpenClaw uses promise caches to collapse concurrent work such as loading a channel sender, generating a session title, probing media, or refreshing TUI state. Callers supply a key and loader; the shared helper returns one in-flight promise and now controls whether failures or settled work remain cached.

flowchart LR
  A[CLI, Gateway, media, and TUI requests] --> B[Keyed promise cache]
  B --> C{Cached work exists?}
  C -- yes --> D[Reuse the same promise]
  C -- no --> E[Create and store loader promise]
  E --> F{Lifecycle policy}
  F --> G[Keep successful cached value]
  F --> H[Evict rejected or settled work]
  D --> I[Caller receives result or error]
  G --> I
  H --> I
Loading

Before merge

  • Add real behavior proof - Needs real behavior proof before merge: The PR body reports focused tests and static checks, but it does not include after-fix runtime output demonstrating a real transient failure followed by recovery; add a redacted terminal transcript, live output, recording, or runtime log before merge. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Resolve merge risk (P1) - The PR body provides focused tests and static validation, but no redacted after-fix terminal, runtime, or live-output proof that a failed sender or audio probe retries successfully without restarting OpenClaw.
  • Resolve merge risk (P1) - GitHub reports the branch as behind its base; although it is currently mergeable, final review should refresh the exact head against current main before landing.
  • Complete next step (P2) - No mechanical repair is identified; the remaining blocker is contributor-provided real behavior proof followed by protected-label maintainer review of the refreshed head.
Agent review details

Security

None.

PR surface

Source -10, Tests +125. Total +115 across 24 files.

View PR surface stats
Area Files Added Removed Net
Source 21 280 290 -10
Tests 3 125 0 +125
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 24 405 290 +115

Review metrics

None.

Stored data model

Persistent data-model change detected: migration/backfill/repair: src/infra/outbound/delivery-queue-migration.ts, persistent cache schema: src/media/playback-transcode.ts, persistent cache schema: src/shared/lazy-promise.test.ts, persistent cache schema: src/shared/lazy-promise.ts, serialized state: src/gateway/dashboard-session-title.ts, serialized state: src/gateway/session-reset-service.ts, and 2 more. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Add a redacted terminal or runtime transcript that causes one representative loader to fail once and then demonstrates the next request succeeds without restart; then rebase or refresh the exact merge head and land only if the focused recovery behavior remains intact.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Add a redacted terminal or runtime transcript that causes one representative loader to fail once and then demonstrates the next request succeeds without restart; then rebase or refresh the exact merge head and land only if the focused recovery behavior remains intact.

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

Yes, source-reproducible: the added CLI and local-audio tests model one rejected load followed by a successful retry, and the changed cache policies directly govern that sequence. This read-only review did not execute the branch’s tests or a live runtime.

Is this the best way to solve the issue?

Yes, subject to proof: centralizing identity-safe rejection and settled-work eviction in the existing shared helper is more maintainable than preserving repeated caller-local cleanup, and the inspected callers map to the helper’s two stated policies.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 474c4e671e9f.

Labels

Label justifications:

  • P2: This repairs transient recovery in several runtime paths, but current source and focused tests do not establish an urgent user-facing regression or release blocker.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The PR body reports focused tests and static checks, but it does not include after-fix runtime output demonstrating a real transient failure followed by recovery; add a redacted terminal transcript, live output, recording, or runtime log before merge. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Evidence

What I checked:

  • Shared helper contract: The proposed helper retains the existing cached-promise fast path, records the newly created promise before attaching lifecycle cleanup, and deletes only when the map still holds that exact promise; this preserves replacement safety while adding explicit cache policies. (src/shared/lazy-promise.ts:18, 6c9ef997b933)
  • Regression coverage: The branch adds helper-level tests for sticky rejection caching, retryable rejection eviction, settled in-flight eviction, and identity-safe replacement handling, plus focused retry tests for CLI sender loading and local-audio inspection. (src/shared/lazy-promise.test.ts:10, 6c9ef997b933)
  • Caller lifecycle comparison: The inspected Gateway and CLI callers replace their local identity-checked cleanup with the helper’s corresponding policy: retryable caching for the CLI sender and settled-work eviction for deduplicated Gateway operations. (src/cli/deps.ts:60, 6c9ef997b933)
  • Feature provenance: The current keyed helper lines trace to the helper introduction by Santiago; later shared-lazy work includes Peter Steinberger commits, making both appropriate routing contacts for the proposed extension. (src/shared/lazy-promise.ts:11, a2ffa4850d6c)
  • Current-main status: The reviewed PR head is not contained in the checked-out current main branch, so the central change is neither implemented on main nor present in the latest tagged release from this checkout. (src/shared/lazy-promise.ts:11, a1c2009b91b9)

Likely related people:

  • Santiago: Git blame attributes the current keyed promise helper implementation to Santiago’s introduction commit. (role: original helper introducer; confidence: high; commits: a2ffa4850d6c; files: src/shared/lazy-promise.ts)
  • Peter Steinberger: Recent history on the shared promise helper includes Peter’s changes, and the proposed branch extends that same abstraction. (role: recent shared-lazy contributor; confidence: medium; commits: e92a98c77d6a, ac5cdddb2c54; files: src/shared/lazy-promise.ts, src/cli/deps.ts)

Rank-up moves

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

  • Add redacted after-fix terminal or runtime evidence showing one transient loader failure followed by a successful next request without restart.
  • Refresh the branch against current main and retain the focused retry and lifecycle coverage on the final head.

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.

History

Review history (1 earlier review cycle)
  • reviewed 2026-08-02T22:31:17.928Z sha 6c9ef99 :: needs real behavior proof before merge. :: none

@steipete
steipete merged commit 75aa830 into main Aug 2, 2026
125 of 129 checks passed
@steipete
steipete deleted the cleanup/single-flight-adoption branch August 2, 2026 23:33
@steipete

steipete commented Aug 2, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 3, 2026
* fix: canonicalize promise single-flight caches

* fix: make TUI refresh outcome explicit

* fix: satisfy single-flight lint contracts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling cli CLI command changes gateway Gateway runtime maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: L status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant