fix: avoid O(N²) shallow-copy in mapSensitivePaths schema traversal#55018
Conversation
Greptile SummaryThis PR fixes an O(N²) performance bottleneck in Confidence Score: 5/5Safe to merge — minimal, well-scoped refactor with no behavioral regressions and full test coverage. The change is a clean algorithmic optimisation with a single modified file. Logic equivalence is verified by the existing test suite; the only production call site passes a fresh object so mutation semantics are harmless. The sole open item is a non-blocking documentation suggestion. No files require special attention.
|
| Filename | Overview |
|---|---|
| src/config/schema.hints.ts | Extracts a private mapSensitivePathsMut helper that mutates hints in-place instead of spreading it on every recursive call, reducing complexity from O(N²) to O(N). Logic is functionally identical; all production call sites pass freshly created objects so the mutation semantic change is safe. |
Comments Outside Diff (1)
-
src/config/schema.hints.ts, line 191-201 (link)Document mutation side-effect on the public function
The public
mapSensitivePathsnow mutates itshintsargument in-place, which is a semantic change from the original (which returned a fresh object). All current call sites pass a freshly created{}orbuildBaseHints(), so there's no regression here, but since the function is exported, adding a brief JSDoc note would prevent future callers from being surprised:Prompt To Fix With AI
This is a comment left during a code review. Path: src/config/schema.hints.ts Line: 191-201 Comment: **Document mutation side-effect on the public function** The public `mapSensitivePaths` now mutates its `hints` argument in-place, which is a semantic change from the original (which returned a fresh object). All current call sites pass a freshly created `{}` or `buildBaseHints()`, so there's no regression here, but since the function is exported, adding a brief JSDoc note would prevent future callers from being surprised: How can I resolve this? If you propose a fix, please make it concise.
Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/config/schema.hints.ts
Line: 191-201
Comment:
**Document mutation side-effect on the public function**
The public `mapSensitivePaths` now mutates its `hints` argument in-place, which is a semantic change from the original (which returned a fresh object). All current call sites pass a freshly created `{}` or `buildBaseHints()`, so there's no regression here, but since the function is exported, adding a brief JSDoc note would prevent future callers from being surprised:
```suggestion
/**
* Traverses the Zod schema tree and marks every sensitive path in `hints`.
*
* Note: `hints` is mutated in-place for performance (avoids O(N²) copies).
* The same object is also returned for call-site convenience.
*/
export function mapSensitivePaths(
schema: z.ZodType,
path: string,
hints: ConfigUiHints,
): ConfigUiHints {
// Mutate `hints` in-place to avoid O(N²) shallow-copy overhead.
// Previous impl did `{ ...hints }` on every recursive call which caused
// ~30 s blocking for the full OpenClawSchema tree.
mapSensitivePathsMut(schema, path, hints);
return hints;
}
```
How can I resolve this? If you propose a fix, please make it concise.Reviews (1): Last reviewed commit: "fix: avoid O(N²) shallow-copy in mapSens..." | Re-trigger Greptile
|
Gentle ping 🙏 CI is all green, and the Greptile P2 feedback (JSDoc note on in-place mutation) has been addressed in the latest commit. |
|
Just following up on this PR in case it fell through the cracks 🙏 The branch is in good shape: CI is green, the prior review feedback has been addressed, and there shouldn’t be any remaining action items on my side. It’s still a small, single-file performance optimization with unchanged behavior. Happy to rebase, squash, or make any further adjustments if needed. Thanks again for reviewing when you have time. |
|
ClawSweeper review: did not complete due to Codex infrastructure failure. Reviewed June 23, 2026, 11:49 PM ET / 03:49 UTC. Summary PR surface: Source +11. Total +11 across 1 file. Reproducibility: unclear. The review failed before ClawSweeper could establish a reproduction path. Review metrics: none identified. Stored data model Merge readiness This is a ClawSweeper/Codex infrastructure failure, not a PR readiness or patch-quality verdict. Risk before merge
Maintainer options:
Next step before merge
Review detailsBest possible solution: Retry the Codex review after fixing the execution failure. Do we have a high-confidence way to reproduce the issue? Unclear. The review failed before ClawSweeper could establish a reproduction path. Is this the best way to solve the issue? Unclear. Retry the review first so ClawSweeper can evaluate the actual issue and fix direction. AGENTS.md: unclear because the file could not be read completely. Codex review notes: model internal, reasoning high; reviewed against 89acdd95dcbd. Label changesLabel changes:
Evidence reviewedPR surface: Source +11. Total +11 across 1 file. View PR surface stats
What I checked:
Likely related people:
How this review workflow works
|
|
ClawSweeper PR egg 🎁 Pass real behavior proof to wake the egg and unlock a hatchable treat. Where did the egg go?
|
|
This pull request has been automatically marked as stale due to inactivity. |
8194291 to
a208dc3
Compare
a208dc3 to
e92edbf
Compare
Dependency graph guard clearedThis PR no longer has blocked dependency graph changes. A future dependency graph change requires a fresh
|
|
Maintainer closeout proof for
Ready to merge. |
|
Merged via squash.
|
What Problem This Solves
Fixes an issue where config schema hint generation could spend excessive time copying a growing hints map while walking large Zod schema trees. As OpenClaw's config schema grows, the recursive
{ ...hints }copy pattern turns traversal into repeated work and can block config/schema initialization paths.Why This Change Was Made
The traversal now copies the caller-provided hints map once at the public
mapSensitivePathsboundary, then uses an internal accumulator for recursive schema walking. That keeps the existing copy-return contract for callers while removing the recursive O(N^2)-style shallow-copy cost.User Impact
Config schema and UI-hint generation stay behaviorally identical but avoid a large repeated-allocation slowdown on bigger schema trees. Sensitive config path marking remains unchanged.
Evidence
origin/main: clean, no accepted/actionable findings, patch correctness 0.98.cbx_fd11288428d7, runrun_627efbec345c: focusedsrc/config/schema.hints.test.tspassed 11 tests.cbx_fd11288428d7, runrun_627efbec345c:corepack pnpm check:changedpassed.oxfmt --checkandgit diff --checkpassed after the final rebase.Compatibility / Migration
No config, migration, or user action required. The public
mapSensitivePathsfunction still returns a new hints map and does not mutate caller-owned entries.Co-authored-by: Vincent Koc [email protected]