Skip to content

fix(ui): keep canvas leases lifecycle-owned and timer-safe - #117173

Merged
steipete merged 1 commit into
mainfrom
codex/qa400-gateway-canvas-lease-owner
Aug 1, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/qa400-gateway-canvas-lease-owner

Conversation

@steipete

@steipete steipete commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

Control UI canvas capability renewal had two independent lifecycle defects in its private scheduler:

  1. A refreshed-URL observer can synchronously stop or reconnect the gateway, but the retired generation still installed a renewal timer. A late retired timer callback could also discard the current reconnect generation's timer handle, leaving the live renewal orphaned.
  2. A legitimate safe-integer capability expiry beyond the native browser timer maximum was passed directly to setTimeout. Chromium converts delays above 2,147,483,647 ms into immediate callbacks, producing a real RPC storm.

On frozen current main fdcb321bfaaadb5a1e7d123b6be7a934980f8b12, independent Google Chrome 150 plus the full production createApplicationGateway, genuine device-authenticated WebSocket challenge, and actual canvas refresh RPCs produced 123 server requests and 122 URL rotations in 120 ms. The same browser proof reproduced a timer being installed after stop and an active reconnect timer being orphaned.

Why This Change Was Made

The existing canvas lease owns both the generation and its renewal timer, so both repairs belong in that one private scheduler. A canonical generation predicate now guards scheduling and checks stale callbacks before they mutate the active timer handle. All duplicate lifecycle checks reuse that predicate.

Every native delay goes through the existing exported browser-safe resolveSafeTimeoutDelayMs helper; normal expiry, minimum delay, retry backoff, missing-expiry renewal, and single-flight behavior stay unchanged.

Only one existing private production owner and its colocated tests change. There are no protocol, authentication, security, public configuration, persistence, dependency, or package-surface changes.

User Impact

  • Long-lived canvas widgets no longer overload the gateway with continuous capability-refresh requests.
  • Disconnects and reconnects leave no retired or orphaned renewal timers.
  • Canvas capability rotation still performs the initial refresh and preserves all normal retry behavior.

Verification

Frozen base: fdcb321bfaaadb5a1e7d123b6be7a934980f8b12.

Immutable candidate: e65158e7e953858ce3041159eb13831f51c817c6.

  • Dedicated Blacksmith Testbox exact production and test blob guards, six real UI owner/caller/browser/widget suites: 132/132 passing, six files, no failures.
  • Type-aware oxlint --type-aware --type-check, targeted oxfmt --check, and git diff --check all passed.
  • Independent real Chrome 150 + complete production application gateway + real device-authenticated WebSocket: 15/15 assertions, 123 refresh requests → exactly one, safe 2,147,483,647-ms delay, zero retired timers after stop, current reconnect timer remains owned, zero browser errors.
  • Two independent complete-owner/caller/dependency/history reviews: zero P0/P1/P2/P3 findings, confidence 0.99 each.
  • Genuine full-branch P3 autoreview: TruffleHog clean, zero findings, patch correct, confidence 0.97.

Native timer contracts: Node.js timers and browser maximum timer delay.

@openclaw-barnacle openclaw-barnacle Bot added app: web-ui App: web-ui size: S maintainer Maintainer-authored PR labels Aug 1, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P1 High-priority user-facing bug, regression, or broken workflow. labels Aug 1, 2026
@steipete
steipete merged commit 4a27e2d into main Aug 1, 2026
108 of 116 checks passed
@steipete
steipete deleted the codex/qa400-gateway-canvas-lease-owner branch August 1, 2026 02:55
@steipete

steipete commented Aug 1, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

@clawsweeper

clawsweeper Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 31, 2026, 10:41 PM ET / August 1, 2026, 02:41 UTC.

ClawSweeper review

What this changes

The branch makes Control UI canvas capability renewal reject retired lease generations before changing timer state and clamps renewal delays to the shared browser-safe timer limit.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

This PR remains necessary: current main still schedules an unbounded native timer and can install or clear the wrong renewal timer when a refresh publication synchronously changes the lease lifecycle. The patch keeps generation and timer ownership inside the existing lease scheduler, has no actionable correctness finding, and should remain open for protected maintainer review after the exact-head CI finishes.

Priority: P1
Reviewed head: e65158e7e953858ce3041159eb13831f51c817c6
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A narrowly scoped, source-consistent repair with focused regression coverage and detailed real-browser proof.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The PR body documents an after-fix real Chrome run through the production application gateway, device-authenticated WebSocket, and actual canvas refresh RPCs, with 15 assertions and the request storm reduced to one refresh.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR body documents an after-fix real Chrome run through the production application gateway, device-authenticated WebSocket, and actual canvas refresh RPCs, with 15 assertions and the request storm reduced to one refresh.
Evidence reviewed 7 items Current-main defect remains: Current main's lease scheduler clears the shared handle and installs a callback without checking ownership first; its callback nulls the shared timer before validating the generation. A synchronous onChange lifecycle transition can therefore allow a retired response or callback to affect a live lease.
Owner and caller boundary: The gateway store lazily constructs one canvas lease, starts it only for the active gateway client and generation, and forwards lease URL changes into the gateway snapshot; this confirms the lease is the correct owner for renewal lifecycle state.
Candidate fixes the owner-boundary race: The candidate adds one ownsGeneration predicate, checks it before scheduling and before clearing a callback's active timer handle, and routes all renewal delays through the established safe-delay helper.
Findings None None.
Security None None.

How this fits together

The Control UI gateway store starts a per-tab canvas capability lease after a gateway hello and publishes refreshed canvas URLs to mounted widgets. The lease refreshes its server-issued capability before expiry, so its timer and generation state determine whether gateway refresh RPCs continue, stop, or reconnect safely.

flowchart LR
  A[Gateway hello canvas URL] --> B[Canvas lease]
  B --> C[Refresh capability RPC]
  C --> D[Publish refreshed canvas URL]
  D --> E[Lifecycle change: stop or reconnect]
  C --> F[Generation-owned renewal timer]
  E --> F
  F --> C
Loading

Decision needed

Question Recommendation
After the in-progress exact-head checks complete, should the Control UI owner approve this private scheduler repair for merge despite the protected maintainer label? Approve after exact-head CI: Merge the clean three-way result once the remaining UI and lint checks pass on the reviewed head.

Why: The patch is source-supported and narrowly scoped, but the protected label requires explicit maintainer handling rather than automated cleanup.

Before merge

  • Resolve merge risk (P1) - The branch is behind current main, and the supplied exact-head UI/lint checks were still in progress; refresh the clean three-way merge result and wait for the required checks before landing.
  • Complete next step (P2) - The active PR already contains the bounded repair; the remaining action is protected maintainer approval after exact-head CI and merge-state refresh, not a second repair branch.
Agent review details

Security

None.

PR surface

Source +9, Tests +90. Total +99 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 18 9 +9
Tests 1 90 0 +90
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 108 9 +99

Review metrics

None.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Land the focused lease-owner repair once the exact candidate head is green and cleanly merged with current main, retaining the shared safe-delay helper rather than adding a separate UI timer policy.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Land the focused lease-owner repair once the exact candidate head is green and cleanly merged with current main, retaining the shared safe-delay helper rather than adding a separate UI timer policy.

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

Yes, from source: invoke onChange synchronously during a refresh to stop or reconnect the lease, then observe current main schedule a retired generation; separately return a safe-integer expiry above the native timer ceiling. The candidate's focused tests encode both paths, but this read-only review did not execute them.

Is this the best way to solve the issue?

Yes. The repair belongs in the single private lease scheduler, centralizes the existing generation invariant, and reuses the repository's shared browser-safe delay contract instead of introducing UI-specific timer behavior.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P1: A stale or overflowed renewal timer can repeatedly issue canvas refresh RPCs or orphan the live renewal path for active Control UI users.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR body documents an after-fix real Chrome run through the production application gateway, device-authenticated WebSocket, and actual canvas refresh RPCs, with 15 assertions and the request storm reduced to one refresh.
  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body documents an after-fix real Chrome run through the production application gateway, device-authenticated WebSocket, and actual canvas refresh RPCs, with 15 assertions and the request storm reduced to one refresh.

Label justifications:

  • P1: A stale or overflowed renewal timer can repeatedly issue canvas refresh RPCs or orphan the live renewal path for active Control UI users.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body documents an after-fix real Chrome run through the production application gateway, device-authenticated WebSocket, and actual canvas refresh RPCs, with 15 assertions and the request storm reduced to one refresh.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body documents an after-fix real Chrome run through the production application gateway, device-authenticated WebSocket, and actual canvas refresh RPCs, with 15 assertions and the request storm reduced to one refresh.

Evidence

What I checked:

  • Current-main defect remains: Current main's lease scheduler clears the shared handle and installs a callback without checking ownership first; its callback nulls the shared timer before validating the generation. A synchronous onChange lifecycle transition can therefore allow a retired response or callback to affect a live lease. (ui/src/app/canvas-surface-lease.runtime.ts:56, 91aff8089c9e)
  • Owner and caller boundary: The gateway store lazily constructs one canvas lease, starts it only for the active gateway client and generation, and forwards lease URL changes into the gateway snapshot; this confirms the lease is the correct owner for renewal lifecycle state. (ui/src/app/gateway-store.ts:142, 91aff8089c9e)
  • Candidate fixes the owner-boundary race: The candidate adds one ownsGeneration predicate, checks it before scheduling and before clearing a callback's active timer handle, and routes all renewal delays through the established safe-delay helper. (ui/src/app/canvas-surface-lease.runtime.ts:50, e65158e7e953)
  • Shared timeout contract: The browser gateway-client entry exports resolveSafeTimeoutDelayMs; its implementation floors finite delays and clamps them to 2,147,483,647 ms, and its focused tests cover the ceiling. The UI already imports this same browser entry for gateway timer policy. (packages/gateway-client/src/timeouts.ts:54, 91aff8089c9e)
  • Regression coverage: The branch adds focused cases for synchronous stop/reconnect during refreshed-URL publication, a late retired callback, and capability expiries above the browser timer ceiling. (ui/src/app/canvas-surface-lease.test.ts:188, e65158e7e953)
  • Feature history: The current lease implementation was last materially introduced by f94a790df599de2b1aecdaf43d56e275e4b9da2d by Peter Steinberger; the candidate is a one-commit repair on top of parent fdcb321bfaaadb5a1e7d123b6be7a934980f8b12. Current main commit 91aff8089c9e5c1ca616bf59137752848472dd2e does not modify either lease file. (ui/src/app/canvas-surface-lease.runtime.ts:45, f94a790df599)

Likely related people:

  • steipete: Peter Steinberger introduced the current lease implementation in the recent feature refactor and authored the focused lifecycle repair; file history and blame concentrate the scheduler path in that work. (role: introduced current lease behavior and authored targeted repair; confidence: high; commits: f94a790df599, e65158e7e953; files: ui/src/app/canvas-surface-lease.runtime.ts, ui/src/app/canvas-surface-lease.test.ts, ui/src/app/gateway-store.ts)

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.

vincentkoc added a commit to chenyangjun-xy/openclaw that referenced this pull request Aug 1, 2026
* origin/main:
  fix(ui): keep canvas lease renewals lifecycle-owned and timer-safe (openclaw#117173)
  fix(teams): restore the official square product icon (openclaw#117170)
vincentkoc added a commit that referenced this pull request Aug 1, 2026
* origin/main:
  fix(telegram): confirm polling before long poll (#116970)
  fix(tlon): wire autoDiscoverChannels through the settings-store round-trip (#114949)
  fix(gateway): yield before post-ready background work (#117083)
  fix(ui): keep canvas lease renewals lifecycle-owned and timer-safe (#117173)
wingwkyuen pushed a commit to tcgoidc/openclaw that referenced this pull request Aug 1, 2026
* commit '6938f7dddb63bad59862c014c427d63f0a41a6f4': (368 commits)
  fix: allow gateway service commands for named profiles (openclaw#116314)
  fix(plugins): invalidate bundled artifact locations after metadata refresh (openclaw#117041)
  fix(ollama): honor model requests and pull completion contracts (openclaw#117171)
  fix(agents): prevent fallback after stale lifecycle abort (openclaw#117168)
  fix(telegram): confirm polling before long poll (openclaw#116970)
  fix(tlon): wire autoDiscoverChannels through the settings-store round-trip (openclaw#114949)
  fix(gateway): yield before post-ready background work (openclaw#117083)
  fix(ui): keep canvas lease renewals lifecycle-owned and timer-safe (openclaw#117173)
  fix(teams): restore the official square product icon (openclaw#117170)
  refactor(ui): replace duplicated locale bundles with canonical translation memory (openclaw#117157)
  fix(ui): retire stale Gateway event-log observers (openclaw#117169)
  fix(agents): keep subagent status consistent after restart and large fan-outs (openclaw#117141)
  refactor(ui): unify filtered session list ownership (openclaw#117158)
  refactor(agents): consolidate context budgets and compaction recovery (openclaw#117149)
  fix(net-policy): redact sig and x-* auth params in URLs and bodies (openclaw#116957)
  refactor(agents): remove duplicate generated-media delivery fallbacks (openclaw#117150)
  refactor(reply): unify turn lifecycle state ownership (openclaw#117145)
  fix(ui): preserve emoji agent avatar initials (openclaw#104912)
  refactor(auto-reply): unify command and directive ownership (openclaw#117143)
  refactor(plugins): consolidate descriptor and startup ownership (openclaw#117146)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 1, 2026
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 1, 2026
* origin/main:
  fix(telegram): confirm polling before long poll (openclaw#116970)
  fix(tlon): wire autoDiscoverChannels through the settings-store round-trip (openclaw#114949)
  fix(gateway): yield before post-ready background work (openclaw#117083)
  fix(ui): keep canvas lease renewals lifecycle-owned and timer-safe (openclaw#117173)
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 1, 2026
* commit '55215cd9edd2b585cbaee5481d5352aabf7e4399': (368 commits)
  fix: allow gateway service commands for named profiles (openclaw#116314)
  fix(plugins): invalidate bundled artifact locations after metadata refresh (openclaw#117041)
  fix(ollama): honor model requests and pull completion contracts (openclaw#117171)
  fix(agents): prevent fallback after stale lifecycle abort (openclaw#117168)
  fix(telegram): confirm polling before long poll (openclaw#116970)
  fix(tlon): wire autoDiscoverChannels through the settings-store round-trip (openclaw#114949)
  fix(gateway): yield before post-ready background work (openclaw#117083)
  fix(ui): keep canvas lease renewals lifecycle-owned and timer-safe (openclaw#117173)
  fix(teams): restore the official square product icon (openclaw#117170)
  refactor(ui): replace duplicated locale bundles with canonical translation memory (openclaw#117157)
  fix(ui): retire stale Gateway event-log observers (openclaw#117169)
  fix(agents): keep subagent status consistent after restart and large fan-outs (openclaw#117141)
  refactor(ui): unify filtered session list ownership (openclaw#117158)
  refactor(agents): consolidate context budgets and compaction recovery (openclaw#117149)
  fix(net-policy): redact sig and x-* auth params in URLs and bodies (openclaw#116957)
  refactor(agents): remove duplicate generated-media delivery fallbacks (openclaw#117150)
  refactor(reply): unify turn lifecycle state ownership (openclaw#117145)
  fix(ui): preserve emoji agent avatar initials (openclaw#104912)
  refactor(auto-reply): unify command and directive ownership (openclaw#117143)
  refactor(plugins): consolidate descriptor and startup ownership (openclaw#117146)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 1, 2026
* origin/main:
  fix(ui): keep canvas lease renewals lifecycle-owned and timer-safe (openclaw#117173)
  fix(teams): restore the official square product icon (openclaw#117170)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: web-ui App: web-ui maintainer Maintainer-authored PR P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor 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