Skip to content

refactor: consolidate async timing helpers - #99721

Merged
RomneyDa merged 1 commit into
mainfrom
refactor/async-timeout-consolidation
Jul 4, 2026
Merged

RomneyDa merged 1 commit into
mainfrom
refactor/async-timeout-consolidation

Conversation

@RomneyDa

@RomneyDa RomneyDa commented Jul 4, 2026

Copy link
Copy Markdown
Member

What Problem This Solves

OpenClaw had many exact-contract setTimeout promise wrappers spread across core, bundled plugins, and scripts, plus a local Promise.race timeout that duplicated the shared timeout lifecycle. These copies obscured which timing differences were intentional and repeated timer mechanics across owner boundaries.

Why This Change Was Made

  • Reuses the existing clamped core sleep contract through a focused utility leaf and the Plugin SDK runtime export.
  • Adds one scripts-boundary raw sleep helper for .mjs callers whose durations must be forwarded directly to global setTimeout.
  • Reuses the existing withTimeout helper for realtime fast-context lookup while preserving duration normalization, custom error identity/message, race behavior, and timer cleanup.
  • Leaves abortable sleeps, unref timers, retry/backoff/jitter policy, polling cadence, subprocess lifecycle, provider/channel timeout policy, and distinct deadline/result semantics with their current owners.
  • Deletes 175 net non-test lines while keeping one canonical path per identical contract.

User Impact

No intended user-visible behavior change. Timing resolution/rejection shapes, timer observability for fake clocks, zero/negative/infinite duration handling, and caller-specific timeout errors remain unchanged.

Evidence

  • node scripts/run-vitest.mjs test/scripts/sleep.test.ts src/utils.test.ts src/talk/fast-context-runtime.test.ts extensions/feishu/src/app-registration.test.ts
  • Additional focused shards covered migrated browser, channel, memory, CLI, config, doctor, and talk callers.
  • check:changed passed in Blacksmith Testbox tbx_01kwn79rj5gdj387ryb9h4yf05 on exact head da57a754670f (Actions run 28688802468).
  • Fresh branch autoreview reported no accepted/actionable findings and rated the patch correct with 0.96 confidence.
  • git diff --check origin/main...HEAD
  • Runtime import-cycle guard passed in the changed gate.

@openclaw-barnacle openclaw-barnacle Bot added channel: discord Channel integration: discord channel: imessage Channel integration: imessage channel: signal Channel integration: signal gateway Gateway runtime extensions: memory-core Extension: memory-core cli CLI command changes scripts Repository scripts commands Command implementations docker Docker and sandbox tooling channel: feishu Channel integration: feishu channel: qqbot extensions: codex extensions: xai size: M maintainer Maintainer-authored PR labels Jul 4, 2026
@clawsweeper

clawsweeper Bot commented Jul 4, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 3, 2026, 8:44 PM ET / 00:44 UTC.

Summary
The PR moves clamped OpenClaw sleep into a leaf helper, retargets the Plugin SDK runtime export, adds a raw script sleep helper, migrates duplicate local sleep wrappers, and reuses shared withTimeout for fast-context lookup.

PR surface: Source -109, Tests +56, Other -66. Total -119 across 43 files.

Reproducibility: not applicable. this is a cleanup/refactor PR, not a bug report with a failing user reproduction. The review used source contracts, dependency inspection, related issue context, and current-head CI instead.

Review metrics: none identified.

Stored data model
Persistent data-model change detected: migration/backfill/repair: extensions/codex/src/migration/apply.ts, migration/backfill/repair: src/commands/doctor-whatsapp-responsiveness.ts, vector/embedding metadata: extensions/memory-core/src/memory/watch-settle.ts, vector/embedding metadata: extensions/memory-core/src/short-term-promotion.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #99689
Summary: The open maintainer cleanup issue describes the same exact-contract async timing utility consolidation, and this PR is the implementation candidate for that work.

Members:

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

Merge readiness
Overall: 🐚 platinum hermit
Proof: 🌊 off-meta tidepool
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:

  • none.

Next step before merge

  • [P2] No repair lane is needed because no actionable review findings remain; the remaining action is ordinary maintainer review and merge gating.

Security
Cleared: The diff does not change dependencies, lockfiles, workflows, package publishing metadata, secrets handling, permissions, or downloaded code execution paths.

Review details

Best possible solution:

Land this focused cleanup after normal maintainer review, keeping the clamped core/plugin sleep and raw script sleep contracts distinct.

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

Not applicable: this is a cleanup/refactor PR, not a bug report with a failing user reproduction. The review used source contracts, dependency inspection, related issue context, and current-head CI instead.

Is this the best way to solve the issue?

Yes: this is the right maintainable shape because it preserves the existing clamped core/plugin helper, keeps raw script timing separate, and only reuses withTimeout where the error and cleanup contract is matched.

AGENTS.md: found and applied where relevant.

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

Label changes

Label justifications:

  • P3: This is a behavior-preserving cleanup refactor with no intended user-visible, config, storage, protocol, or default behavior change.
  • 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: The external-contributor real behavior proof gate is not applicable because this is a member-authored, maintainer-labeled cleanup PR; the PR body and live checks provide validation context.
Evidence reviewed

PR surface:

Source -109, Tests +56, Other -66. Total -119 across 43 files.

View PR surface stats
Area Files Added Removed Net
Source 23 39 148 -109
Tests 2 56 0 +56
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 18 28 94 -66
Total 43 123 242 -119

What I checked:

  • Repository policy applied: Root AGENTS.md and scoped guides for extensions/, src/plugin-sdk/, src/gateway/, src/tui/, scripts/, and test/ were read; plugin boundary, SDK compatibility, script wrapper, and fake-timer rules shaped the review. (AGENTS.md:1, f59310a555d7)
  • Protected live PR state: Live GitHub metadata shows this PR is open, authored by RomneyDa, labeled maintainer and P3, and currently points at head da57a754670f8d6255c21691c313409294f01c88; cleanup should not auto-close it. (da57a754670f)
  • Current main clamped sleep contract: Current main’s shared sleep already clamps timer input through resolveTimerTimeoutMs(ms, 0, 0), which is the contract the PR preserves while moving it to src/utils/sleep.ts. (src/utils.ts:65, f59310a555d7)
  • PR preserves SDK sleep export shape: The PR keeps sleep exported from src/plugin-sdk/runtime-env.ts while retargeting it from the broad ../utils.js module to the new leaf helper; no public SDK subpath is added or removed. (src/plugin-sdk/runtime-env.ts:19, da57a754670f)
  • Script raw sleep remains native: The PR adds scripts/lib/sleep.mjs as a scripts-only helper that forwards the provided delay directly to global setTimeout, with a test covering zero, negative, NaN, and Infinity forwarding. (scripts/lib/sleep.mjs:1, da57a754670f)
  • Fast-context timeout contract checked: Current main has a local fast-context Promise.race timeout with custom error identity and timer cleanup; the PR normalizes before calling shared withTimeout and adds a focused fake-timer cleanup/error test. (src/talk/fast-context-runtime.ts:115, f59310a555d7)

Likely related people:

  • steipete: GitHub history shows recent work on shared sleep clamping, central timer timeout resolution, fast-context timeout capping, and Plugin SDK runtime-env helper exports. (role: recent timing helper owner; confidence: high; commits: dbddf4093f30, a0c1f5962dec, 75ef73d4f75e; files: src/utils.ts, src/talk/fast-context-runtime.ts, src/plugin-sdk/runtime-env.ts)
  • vincentkoc: GitHub history shows recent merged work in scripts/run-node.mjs and memory-core files touched by the timing cleanup. (role: recent scripts and memory runtime contributor; confidence: medium; commits: 7a077ffead4a, b980d678a48f, abd8a46b0a52; files: scripts/run-node.mjs, extensions/memory-core/src/short-term-promotion.ts)
  • RomneyDa: Beyond authoring this PR, GitHub history shows a recent merged refactor in an affected Discord runtime file. (role: recent adjacent contributor; confidence: medium; commits: 792060bb6369; files: extensions/discord/src/monitor/message-handler.process.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.

@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. labels Jul 4, 2026
@RomneyDa

RomneyDa commented Jul 4, 2026

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 4, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

@RomneyDa

RomneyDa commented Jul 4, 2026

Copy link
Copy Markdown
Member Author

Land-ready verification for da57a754670f:

  • Focused proof: node scripts/run-vitest.mjs test/scripts/sleep.test.ts src/utils.test.ts src/talk/fast-context-runtime.test.ts extensions/feishu/src/app-registration.test.ts
  • Broad changed gate: Blacksmith Testbox tbx_01kwn79rj5gdj387ryb9h4yf05, Actions run 28688802468, passed on the exact head.
  • PR CI: Actions run 28689123293 attempt 2 passed, including the QA Smoke rerun.
  • Runtime import-cycle guard passed.
  • Fresh branch autoreview: no accepted/actionable findings, patch correct at 0.96 confidence.
  • Fresh ClawSweeper review: current-head platinum hermit, best-fix positive, ready for maintainer review.
  • Diff: 43 files, +123/-242 total; non-test net -175 lines.

@RomneyDa
RomneyDa merged commit c7aca4f into main Jul 4, 2026
271 of 282 checks passed
@RomneyDa
RomneyDa deleted the refactor/async-timeout-consolidation branch July 4, 2026 00:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: discord Channel integration: discord channel: feishu Channel integration: feishu channel: imessage Channel integration: imessage channel: qqbot channel: signal Channel integration: signal cli CLI command changes commands Command implementations docker Docker and sandbox tooling extensions: codex extensions: memory-core Extension: memory-core extensions: xai gateway Gateway runtime maintainer Maintainer-authored PR P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. scripts Repository scripts size: M 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