Skip to content

fix(loading): ignore a component import from before stop - #113

Merged
vincentkoc merged 1 commit into
openclaw:mainfrom
SebTardif:fix/stale-component-after-stop
Nov 20, 2026
Merged

vincentkoc merged 1 commit into
openclaw:mainfrom
SebTardif:fix/stale-component-after-stop

Conversation

@SebTardif

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes: a component import that is still running when the router stops can replace the module loaded after restart.

User Impact

User impact: after stop and a new preload, a late component import from the previous session no longer overwrites the module. The new loader data stays in place.

Why This Change Was Made

A failed loader does not abort the component import. stop() clears the module cache, and the next match starts again at fetch count 1, so the old import looked current. A component result is now accepted only when the stored match still uses that load's abort signal.

The fetch-count guard was rewritten in #90 without comparing the signal. #110 covers the case where the old import rejects.

Evidence

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

Before, the late import replaced replacement with stale module while data stayed fresh:

$ node proof-f007.mjs
{"componentCalls":2,"beforeLateImport":{"data":"fresh","module":"replacement"},"afterLateImport":{"data":"fresh","module":"stale module"}}

After, the module stays replacement:

$ node proof-f007.mjs
{"componentCalls":2,"beforeLateImport":{"data":"fresh","module":"replacement"},"afterLateImport":{"data":"fresh","module":"replacement"}}

Real behavior proof

  • Behavior or issue addressed: A loader throws while the component import stays pending. After stop, a new preload loads fresh data and a replacement module. The old import then resolves and used to replace that module.
  • Real environment tested: macOS 27.2.1, Node v26.13.1, package built from this branch.
  • Exact steps or command run after this patch: Preload a route whose loader throws and whose component import stays pending. Stop the router. Preload the same route with a loader that returns fresh data and a component that resolves to replacement. Resolve the old import to stale module. Read the cached match.
  • Evidence after fix: terminal output from the patched package:
$ node proof-f007.mjs
{"componentCalls":2,"beforeLateImport":{"data":"fresh","module":"replacement"},"afterLateImport":{"data":"fresh","module":"replacement"}}

The same command on the previous package printed module stale module after the late import.

  • Observed result after fix: The cached match keeps data fresh and module replacement after the old import resolves. The component function ran twice.
  • What was not tested: A dynamic import that hits the network. The run uses the public component and loader functions.

A failed load can leave its component import running. After stop, the
next load starts again at fetch count 1, so the old import replaced
the new module. Accept a component result only when the stored match
still uses that load's abort signal.

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. clawsweeper:intake:needs-environment 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. clawsweeper:intake:needs-environment 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

Reject component results whose load signal no longer belongs to the stored route match.

Example: A page preload fails while its component remains pending, then stop and another preload load a replacement component.

  • Before: Resolving the old import changes module "replacement" to "stale module" while data remains "fresh".
  • After: The cached match retains module "replacement" and data "fresh".

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, source-verified repair with relevant package-level runtime output, regression coverage, passing head checks, and no identified blockers.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): Supplied Node terminal output exercises the built package's public router API with a pending component, failed loader, stop, replacement preload, and late resolution; the patched cached match retains both the replacement module and fresh data.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A late component import can replace the component associated with fresh route data after the router is stopped and reused.
Reason: The repair enforces the documented stale-result contract using existing lifecycle identity without changing public APIs or defaults.

Merge readiness

✅ Ready for maintainer review

This PR fixes a current loading bug with a focused ownership check; no actionable defects were found.

Priority: P2
Reviewed head: 75464012557b42d5959bc610ed0016154447a5f9

Before merge

None.

Findings

None.

Agent review details

How this fits together

The framework-independent router coordinates navigation and preloads, runs application component and data functions, and publishes active, pending, and cached matches.

flowchart TD
  A[Navigation or preload] --> B[Route match and controller]
  B --> C[Parallel component and data loading]
  C --> D[Fetch ownership check]
  D --> E[Match store]
  E --> F[Application subscribers]
  G[Stop] --> B
  G --> E
Loading

Technical review

Best possible solution:

Retain the signal identity check in the existing fetch predicate and land the focused regression test and changelog entry.

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

Current-main source establishes the fetch-count collision after failed preload cleanup, and the contributor supplies matching before-and-after package output; no reproduction was executed during this review.

Is this the best way to solve the issue?

Checking the stored match's existing signal is the smallest complete repair and preserves valid preload sharing, component-first publication, and background revalidation.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

  • Repository policy: Read the complete root AGENTS.md; no nested policy files, maintainer notes directory, or pr-simplify skill were present. The repair follows the explicit stale-result suppression contract. (AGENTS.md:56, 75464012557b)
  • Current-main failure path: The existing predicate checks fetch count and the old signal's aborted state without checking the stored controller. A failed preload removes its cached match, leaving its component promise outside stop's match traversal; a replacement match can reuse fetch count 1. (src/loading.ts:172, 5acce8720c86)
  • Introduced fix: The pinned introduced diff adds signal identity to the existing shared fetch predicate, covering early component publication, completion, and error updates without adding another lifecycle owner. (src/loading.ts:178, 75464012557b)
  • Supplied runtime proof: The full REST-fetched body matches the supplied body associated with sourceRevision c632748161cf45ace6e5d2afedc1c98d1ee13f6f08865de6121983be45ec02f8. It records before-and-after terminal output using the built package's public preloadRoute, stop, and state APIs on macOS with Node 26.13.1; the replacement module survives late resolution after the patch. Discussion contains only status comments and no submitted reviews. (75464012557b)
  • Regression coverage: The added test exercises failed preload, stop, replacement preload, and delayed component resolution through public router APIs, asserting both retained data and module. Existing tests cover joined preloads, cancellation, parallel publication, and background reload. (test/router-loading-errors.test.ts:51, 75464012557b)
  • Prior intent and adjacent repair: refactor(router): consolidate match reuse and path normalization #90 consolidated an already equivalent fetch predicate; its commit does not establish introduction of this bug. fix(loading): keep a restarted router’s cached component #110 fixes late rejection evicting the module cache, a distinct effect from late fulfillment overwriting a match. (src/loading.ts:172, 739c1a6fe8ba)

Likely related people:

  • Vincent Koc: Raw commit a876b9f adds src/loading.ts:154 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: a876b9f8fedf; 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
Change size Production +10/-2; tests +43; changelog +2 A small change to the existing predicate supplies the fix, with one distinct public-API regression scenario.

Labels

Label changes:

  • add P2: A failed preload followed by stop and reuse can corrupt the replacement module in memory; the trigger has limited scope.
  • 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 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: A failed preload followed by stop and reuse can corrupt the replacement module in memory; the trigger has limited scope.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • 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.

@vincentkoc
vincentkoc merged commit de36a29 into openclaw:main Nov 20, 2026
15 checks passed
vincentkoc added a commit that referenced this pull request Nov 20, 2026
…ion-snapshots

* origin/main:
  refactor(tests): consolidate pending invalidation scenarios (#118)
  fix(loading): accept redirect records without a route location as data (#116)
  fix(loading): ignore a component import from before stop (#113)

# Conflicts:
#	test/router-invalidate-pending.test.ts
vincentkoc added a commit that referenced this pull request Nov 20, 2026
…replay

* origin/main:
  fix(history): replace the URL on an unmatched redirect (#115)
  refactor(tests): consolidate pending invalidation scenarios (#118)
  fix(loading): accept redirect records without a route location as data (#116)
  fix(loading): ignore a component import from before stop (#113)

# Conflicts:
#	CHANGELOG.md
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