Skip to content

fix(loading): clear an expired preload timer on stop - #114

Closed
SebTardif wants to merge 1 commit into
openclaw:mainfrom
SebTardif:fix/clear-expired-gc-timer
Closed

SebTardif wants to merge 1 commit into
openclaw:mainfrom
SebTardif:fix/clear-expired-gc-timer

Conversation

@SebTardif

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes: stop leaves a preload retention timer armed when navigation cache expiry is immediate.

User Impact

User impact: after a preloaded route is shown and then left, stop clears that retention timer instead of leaving it scheduled.

Why This Change Was Made

When retention has already elapsed, the timer id was removed from the map without clearing the timer. stop only clears timers that are still in the map. The immediate-expiry path now clears the timer first. A firing callback also leaves a newer timer registered.

The expiry path has skipped the clear since the router match loading refactor on 2026-06-20 (f047b64, 153 days). That commit has no linked pull request. The infinite-retention path in the same function already clears its timer.

Evidence

Terminal output from node against the built package. The same public calls ran before the patch and after it.

Before, one timer was still armed after stop, and the match was not cached:

$ node proof-f008.mjs
{"cachedAfterLeave":0,"armedTimersAfterStop":1}

After, stop leaves no timer armed:

$ node proof-f008.mjs
{"cachedAfterLeave":0,"armedTimersAfterStop":0}

Real behavior proof

  • Behavior or issue addressed: Preload a route with a finite preload retention time and immediate navigation cache expiry. Open that route, navigate away, then stop. The preload timer stayed armed.
  • Real environment tested: macOS 27.2.1, Node v26.13.1, package built from this branch.
  • Exact steps or command run after this patch: Create a router with gcTime 0 and preloadGcTime 60000. Preload /chat, navigate to /chat, navigate to /other, then stop. Count timers that were scheduled and not cleared.
  • Evidence after fix: terminal output from the patched package:
$ node proof-f008.mjs
{"cachedAfterLeave":0,"armedTimersAfterStop":0}

The same command on the previous package printed armedTimersAfterStop 1.

  • Observed result after fix: The cached match list is empty after leaving the route, and stop leaves zero retention timers armed.
  • What was not tested: A retention longer than one minute in a live process. The run uses a 60 second preload retention and stops before that delay.

Dropping a match whose retention already elapsed removed the timer
from the map without clearing it. stop only clears timers still in
the map, so the preload timer stayed armed. Clear it before deleting
the map entry.

Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca>
@SebTardif
SebTardif requested a review from a team as a code owner November 20, 2026 12:59
@clawsweeper

clawsweeper Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. P2 Normal priority bug or improvement with limited blast radius. proof: sufficient Contributor real behavior proof is sufficient. 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. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 20, 2026
@clawsweeper

clawsweeper Bot commented Nov 20, 2026

Copy link
Copy Markdown

Codex review: needs maintainer review before merge.

What this changes

This PR clears an outstanding preload retention timer before immediately expiring its match and preserves newer timer registrations when an older callback finishes.

Example: With gcTime 0 and preloadGcTime 60000, preload chat, navigate to chat, navigate to other, then stop.

  • Before: The cache is empty, but one retention timer remains armed.
  • After: The cache is empty and no retention timer remains armed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, correct repair supported by built-package terminal evidence, meaningful regression coverage, and passing checks on the reviewed head.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): Supplied terminal output exercises the built package's public preload, navigation, and stop methods on macOS with Node v26.13.1, showing the outstanding timer count fall from one before the fix to zero afterward.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A router configured for immediate navigation cache expiry can retain a preload timer after stop.
Reason: The repair restores the explicit resource-cleanup contract at low implementation cost.

Merge readiness

✅ Ready for maintainer review

This PR fixes a current timer-cleanup defect with a focused change; no actionable correctness or security findings remain.

Priority: P2
Reviewed head: 7c1f8932b3a217e8f57e544f0581be5666778287

Before merge

None.

Findings

None.

Agent review details

How this fits together

Public preload and navigation calls feed the router's match store and loading subsystem, which manage cached matches and host timers; stop releases their resources.

flowchart TD
  A[Public router calls] --> B[Navigation and preload]
  B --> C[Match store]
  B --> D[Route loading]
  D --> C
  D --> E[Retention timers]
  F[Router stop] --> D
  F --> C
Loading

Technical review

Best possible solution:

Land the focused timer cleanup while preserving existing retention semantics and public APIs.

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

The public-call sequence is explicit, current-main source explains the lost timer registration, and the contributor supplies matching before/after built-package output; review did not execute target code.

Is this the best way to solve the issue?

Clearing the existing timer in its owning expiry branch directly repairs the resource leak without changing cache policy, adding dependencies, or introducing another lifecycle owner.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 5acce8720c86.

Provenance checked

  • Immediate cache expiry keeps the original intent (f047b64: Separate preload retention from navigation retention and expire matches using their data-update timestamp.)
  • Callback cleanup when the cached match is absent keeps the original intent (dbe2d07: Harden match lifecycle cleanup and rearm garbage collection for refreshed entries.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

  • Current-main defect and focused repair: Main removes the timer registration on immediate expiry without clearing the host timer; the introduced patch clears it first. Loading cleanup can otherwise clear only timers still registered. (src/loading.ts:78, 7c1f8932b3a2)
  • Behavioral regression coverage: The added test exercises public preload, navigation, and stop calls with immediate navigation expiry, then checks both the empty cache and zero outstanding timers. (test/router-loading.test.ts:413, 7c1f8932b3a2)
  • Supplied built-package proof: The full PR body records Node v26.13.1 on macOS, public calls against the built package, and before/after terminal output changing armedTimersAfterStop from 1 to 0 while cachedAfterLeave remains 0; discussion contains no additional behavioral evidence. (7c1f8932b3a2)
  • Original expiry behavior: The historical loading.ts refactor introduced the immediate-expiry branch while separating preload retention and measuring expiry from updatedAt; it omitted clearing the previous timer. GitHub returns no linked PR for this commit. (loading.ts, f047b64a87a5)
  • Related retention repair preserves the contract: fix: do not expire Infinity gcTime via setTimeout overflow #25 addressed infinite and oversized retention, including clearing obsolete preload timers for Infinity; it does not fix immediate finite expiry. (src/loading.ts:67, 9393d585e0d8)
  • Exact-head validation: All five platform/runtime check jobs and CodeQL checks pass for the reviewed head; the CI workflow runs pnpm run check, covering build, types, lint, tests, formatting, and package validation. Local diff whitespace validation passes; no target code was executed during review. (.github/workflows/ci.yml, 7c1f8932b3a2)

Likely related people:

  • Sebastien Tardif: Raw commit 9393d58 adds src/loading.ts:103 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 9393d585e0d8; files: src/loading.ts)
  • Shakker: Raw commit f047b64 adds loading.ts:53 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: f047b64a87a5; files: loading.ts)
  • Vincent Koc: Raw commit 739c1a6 adds src/loading.ts:107 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 739c1a6fe8ba; files: src/loading.ts)

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Review metrics

Metric Value Why it matters
Patch scope Production +7/-1; tests +20; changelog +2 Small lifecycle repair with one distinct public-behavior regression test and the required release note.

Labels

Label changes:

  • add P2: A specific cache configuration leaves a router-owned timer armed after cleanup, with limited impact and no demonstrated message loss or outage.
  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: A specific cache configuration leaves a router-owned timer armed after cleanup, with limited impact and no demonstrated message loss or outage.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed November 20, 2026, 8:12 AM ET / 13:12 UTC.

@steipete

Copy link
Copy Markdown
Contributor

Thanks for finding and fixing this. The timer leak reproduced on current main (one timer remained after stop) and is now fixed in #112 / 760e341, with your contributor credit preserved. The regression passes, the complete 83-test package gate passes, and Linux/macOS/Windows CI is green. Closing this superseded PR.

@steipete steipete closed this Nov 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal priority bug or improvement with limited blast radius. proof: sufficient Contributor real behavior proof is sufficient. 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants