Skip to content

improve(tooling): reduce import-cycle check peak memory - #149266

Merged
steipete merged 2 commits into
mainfrom
codex/perf-import-cycle-fallback-r12
Sep 16, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/perf-import-cycle-fallback-r12

Conversation

@steipete

@steipete steipete commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

The import-cycle check constructs extension and index fallback paths even when an import already matches a known file or alias.

User Impact

Internal tooling only. In three fresh-process comparisons on Windows with Node 24.19.0, peak working set fell about 21% (roughly 64 MiB). Node 26.8.2 peak memory was effectively unchanged. This does not establish a CLI speedup: mean wall time changed +1.94% on Node 24 and -1.09% on Node 26; mean CPU time changed +1.50% and +0.97%, respectively.

Why This Change Was Made

Check the existing exact-file and alias matches before allocating the fallback candidates. The same resolver still owns extension/index priority, alias collisions, and unresolved imports. No cache, new interface, or persistent state is added.

Evidence

  • All 32 executable fixture cases passed across baseline/candidate and Node 24/26, including exact-file/alias collisions, extension and index priority, re-exports, exclusions, and type-only imports.
  • Four full repository captures matched all 17,393 nodes and 62,540 ordered edges, including 516 duplicate edges. The uninstrumented CLI returned the same complete output in all twelve timing runs.
  • Independent source review found no actionable P0–P2 issue. Formatting and git diff --check passed. The required exact-head CI gate passed in run 35047779892.

Three adjacent baseline/candidate pairs per runtime, with order BCCBBC on Node 24 and CBBCCB on Node 26. Positive deltas mean the candidate used more time or memory. All adverse samples are retained:

Node Pair Baseline wall (s) Candidate wall (s) CPU change Peak working-set change
24 1 8.783 8.569 +0.45% -20.95%
24 2 7.697 8.121 +4.70% -20.61%
24 3 7.641 7.898 -0.50% -21.92%
26 1 7.668 7.919 +5.34% +0.22%
26 2 7.879 7.472 -3.21% -0.10%
26 3 7.634 7.538 +0.86% +0.10%

Each sample runs node --import ./scripts/tsx.mjs scripts/check-import-cycles.ts against the same source base, 861766d, varying only this file. The publication base is 57956a7c8e8061d0227d913002c380614d535fd9. The resolver baseline and measured patch remain byte-identical; the measurements above describe the original captured source base. These are fresh Node processes on a previously read filesystem; wall time includes startup. CPU and peak working set come from the retained Windows process handle and cover the direct process. Three pairs limit precision; no cold-cache, retained-heap, or universal platform claim is made.

The original, unused 8 GiB host admission was revised to 6 GiB before any timing data, using the completed captures' 328–379 MB direct-process peaks. The 2 GiB process cap, twelve-run order, deadlines, and output assertions remained unchanged. Full source verification took longer under host load and is excluded from individual CLI timings.

Current integration: head f038a9bd4ea52223bbfee3ec032dc8e8b4cf8e7b refreshes the unchanged patch onto 57956a7c8e8061d0227d913002c380614d535fd9, including the landed cron synchronization repair #149412. The prior failed CI run 35007406393 remains retained and failed. Earlier native-fixture failures and their canonical repairs #149294/#149301 are also retained in the PR history. The exact-head required CI gate passed in run 35047779892; native landing gates remain required.

The checker, shared graph helper, loader/shim/runtime sources and package.json are byte-identical to the measured inputs. Current lock/workspace changes concern the separate proxy-addr override; tsconfig adds an unrelated model-contract alias. Seventeen named retained TypeScript/tsx/esbuild files still match their recorded hashes. This is scoped source continuity, not a full dependency-closure or current-corpus equivalence claim. The Windows measurements above remain tied to frozen 861766ddc8ce334b3440f21c8089374de72a17ff; no benchmark was rerun for this refresh. Exact old/new patch comparison, range-diff, owner hashes and git diff --check passed. Existing independent source review applies to the identical patch.

@clawsweeper

clawsweeper Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
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.

@steipete
steipete marked this pull request as ready for review September 15, 2026 16:23
@openclaw-barnacle openclaw-barnacle Bot added scripts Repository scripts size: XS maintainer Maintainer-authored PR labels Sep 15, 2026
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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. labels Sep 15, 2026
@clawsweeper

clawsweeper Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 15, 2026, 11:04 PM ET / September 16, 2026, 03:04 UTC (Revision 9).

ClawSweeper review

What this changes

The import-cycle checker avoids allocating fallback filenames when an import already matches a known source file or alias.

Merge readiness

✅ Ready for maintainer review

This remains a useful, narrowly scoped optimization absent from current main. The resolver preserves existing behavior, the supplied measurements support the bounded memory claim, and no actionable defect was found.

Priority: P3
Reviewed head: f038a9bd4ea52223bbfee3ec032dc8e8b4cf8e7b

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, behavior-preserving optimization supported by unusually careful, appropriately bounded real-process measurements.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The supplied Windows measurements exercise the actual import-cycle CLI with the candidate resolver, record lower Node 24 peak working set, and retain identical output and graph results. Verified owner-source continuity supports reusing this evidence for the unchanged patch; the measurements remain scoped to the captured source base.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The supplied Windows measurements exercise the actual import-cycle CLI with the candidate resolver, record lower Node 24 peak working set, and retain identical output and graph results. Verified owner-source continuity supports reusing this evidence for the unchanged patch; the measurements remain scoped to the captured source base.
Evidence reviewed 6 items Introduced change preserves resolution priority: The complete checker retains exact-file lookup before alias lookup, followed by the same ordered extension and index candidates. Import filtering, graph construction, cycle detection, and exit status are unchanged.
Optimization remains absent from main and latest release: The inspected current-main checker still constructs all candidates before checking the base path. Its contents match v2026.9.4, so neither inspected revision contains this optimization.
Real checker measurements: The complete supplied PR body records twelve real Windows CLI runs across Node 24.19.0 and 26.8.2. Three Node 24 pairs reduced peak working set by 20.61–21.92%; Node 26 was effectively unchanged. Complete CLI output matched, and four graph captures matched 17,393 nodes and 62,540 ordered edges. Measurements explicitly belong to source base 861766d, not a newly benchmarked integration head.
Findings None None.
Security None None.

How this fits together

OpenClaw’s development checks scan repository source imports and build a dependency graph. The import-cycle checker resolves those imports and reports runtime dependency cycles to developers and CI.

flowchart TD
  A[Repository source files] --> B[Runtime imports]
  B --> C{Exact file or alias match}
  C -->|Yes| E[Dependency graph]
  C -->|No| D[Extension and index fallbacks]
  D --> E
  E --> F[Cycle report and exit status]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Other +6. Total +6 across 1 file.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 0 0 0 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 7 1 +6
Total 1 7 1 +6

Review metrics

Metric Value Why it matters
Measured peak memory Node 24: 20.61–21.92% lower across 3 pairs; Node 26: effectively unchanged Real checker measurements support a runtime-specific memory improvement without establishing a speedup.

Technical review

Best possible solution:

Retain the existing resolver and its ordering while avoiding unnecessary fallback allocation on successful direct lookups.

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

Not applicable to a functional bug: this is a performance optimization. Source confirms the avoidable allocation, and the supplied real CLI measurements demonstrate the bounded Windows Node 24 improvement; this read-only review ran no target code.

Is this the best way to solve the issue?

Yes. Moving the existing first lookup ahead of fallback construction preserves lookup semantics without adding a cache, another resolver, or a public interface.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P3: This is a bounded internal-tooling optimization with unchanged cycle-check behavior.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The supplied Windows measurements exercise the actual import-cycle CLI with the candidate resolver, record lower Node 24 peak working set, and retain identical output and graph results. Verified owner-source continuity supports reusing this evidence for the unchanged patch; the measurements remain scoped to the captured source base.
  • proof: sufficient: Contributor real behavior proof is sufficient. The supplied Windows measurements exercise the actual import-cycle CLI with the candidate resolver, record lower Node 24 peak working set, and retain identical output and graph results. Verified owner-source continuity supports reusing this evidence for the unchanged patch; the measurements remain scoped to the captured source base.

Evidence

What I checked:

  • Introduced change preserves resolution priority: The complete checker retains exact-file lookup before alias lookup, followed by the same ordered extension and index candidates. Import filtering, graph construction, cycle detection, and exit status are unchanged. (scripts/check-import-cycles.ts:52, f038a9bd4ea5)
  • Optimization remains absent from main and latest release: The inspected current-main checker still constructs all candidates before checking the base path. Its contents match v2026.9.4, so neither inspected revision contains this optimization. (scripts/check-import-cycles.ts:53, c1c870a41755)
  • Real checker measurements: The complete supplied PR body records twelve real Windows CLI runs across Node 24.19.0 and 26.8.2. Three Node 24 pairs reduced peak working set by 20.61–21.92%; Node 26 was effectively unchanged. Complete CLI output matched, and four graph captures matched 17,393 nodes and 62,540 ordered edges. Measurements explicitly belong to source base 861766d, not a newly benchmarked integration head. (861766ddc8ce)
  • Measured-source continuity: The checker baseline, shared graph helper, tsx entrypoint, and package.json are byte-identical between the measured source base and publication base. This supports reuse of the bounded measurements without claiming full dependency or repository-corpus equivalence. (scripts/check-import-cycles.ts:31, 57956a7c8e80)
  • Historical routing: Current-main file history includes the original guard, shared-helper extraction, and later performance work by Peter Steinberger. GitHub commit metadata identifies steipete on the original added checker. Local blame and deeper follow-history encountered unavailable historical objects; no blame-derived introduction claim is required for this routing candidate. (scripts/check-import-cycles.ts, d41188b65e29)
  • Review continuity and related repairs: The prior completed review covers this same head and contains no findings or published rank-up moves. The supplied merged PRs fix: PR workflow tests fail during repository identity checks #149294 and fix(cron): avoid checking scheduled completion before settlement #149412 repair separate test failures; neither implements this resolver optimization. Broader GitHub search was unavailable, but current source establishes that the requested optimization remains missing. (f038a9bd4ea5)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

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 (8 earlier review cycles)
  • reviewed 2026-09-15T17:06:35.283Z sha 33b99e4 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-15T17:15:11.827Z sha d3fa907 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-15T17:26:43.448Z sha d3fa907 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-15T17:47:02.347Z sha d3fa907 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-15T18:49:25.743Z sha c8a83a0 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-15T20:01:40.073Z sha c8a83a0 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-15T21:03:20.581Z sha c8a83a0 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-16T02:30:33.909Z sha f038a9b :: needs maintainer review before merge. :: none

@steipete
steipete merged commit 4c4fcf9 into main Sep 16, 2026
140 of 141 checks passed
@steipete
steipete deleted the codex/perf-import-cycle-fallback-r12 branch September 16, 2026 03:28
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. scripts Repository scripts size: XS 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