Skip to content

perf: reuse prepared plugin metadata normalizers - #136063

Merged
steipete merged 1 commit into
mainfrom
codex/perf3-metadata-normalizer
Sep 2, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/perf3-metadata-normalizer

Conversation

@steipete

@steipete steipete commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

Plugin metadata completion and multi-workspace composition build an alias normalizer during rebase, then immediately discard it through the worker-restoration path. This repeats preparation of the same immutable plugin inventory.

Why This Change Was Made

Finalize prepared local snapshots through the existing recursive-freeze and cache-binding owners. Worker restoration still unconditionally rebuilds its process-local normalizer, including when the input carries a stale function. Inlining the one-call completion wrapper absorbs this distinction while retaining parameter capture order, projection caching, and source/receiving-cache ownership.

Production: 49 additions / 50 deletions, net −1. Tests unchanged. No configuration, persistence, schema, plugin API, or dependency changes.

User Impact

Metadata values, alias precedence, disabled membership, workspace collision rejection, and snapshot immutability are preserved. Completion and workspace composition each avoid one 184-entry alias Map and one 151-reference sorted array on the current 151-plugin fixture. These are observed preparation counts, not an RSS or latency claim.

Evidence

  • The existing four-file, 78-test suite passed before and after, including complete freeze rewalks, prototype-based Map/Set mutation, accessors, projection/source-cache ownership, and config composition. The canonical changed gate passed.
  • Actual source-module probes produced 23,160,363 identical canonical semantic bytes, SHA-256 59673aa2cfff7b3aaa5a86aa03d73f71532cda951c12d5bff8243bb72e6f9959, and the same 370 alias answers. Object and collection ordering, undefined/functions, reference contracts, and parameter read order are checked. Two measured timing fields, an independently asserted fingerprint, and the private test-home prefix are normalized.
  • An actual WorkerTaskPool / serveWorkerTasks exchange uses Node structured-clone transport. Both arms receive native Maps without the function, restore exactly once, bind the receiving cache, retain shared graph references, reject mutation, and replace an injected stale normalizer. Both pool closes were awaited.
  • Scoped projection and worker restoration retain one normalizer construction; cached completion remains zero. The full freeze walker is unchanged. This exercises the metadata and worker boundaries, not a complete Gateway request.
  • Managed Codex review passed at the default P0 floor with no findings. Independent parent review inspected the full owner, cache, worker producers/consumers, tests, and the history introducing cache binding. All owned proof processes and private runtime roots were cleaned up.

@clawsweeper

clawsweeper Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added size: S maintainer Maintainer-authored PR labels Sep 2, 2026
@steipete
steipete marked this pull request as ready for review September 2, 2026 06:41
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. 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 2, 2026
@clawsweeper

clawsweeper Bot commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 2, 2026, 2:53 AM ET / 06:53 UTC.

ClawSweeper review

What this changes

This PR reuses the normalizer prepared during plugin-metadata rebasing for local snapshot finalization, while retaining worker-side reconstruction after structured cloning.

Merge readiness

✅ Ready for maintainer review

Keep open. Current main still rebuilds the normalizer after completion and config-wide composition; this branch preserves explicit worker reconstruction while finalizing already-local prepared snapshots. No introduced correctness or security defect was found.

Priority: P3
Reviewed head: 3897a98a898893ace8cf86a58ecd56fe82061851

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, net-negative internal refactor with a clear local-versus-worker ownership split and no supported blocking defect.
Proof confidence 🌊 off-meta tidepool Not applicable: Not applicable to this MEMBER-authored internal refactor; the supplied PR evidence describes a real worker transport scenario, while source inspection confirms the changed owner and retained worker restoration boundary.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: Not applicable to this MEMBER-authored internal refactor; the supplied PR evidence describes a real worker transport scenario, while source inspection confirms the changed owner and retained worker restoration boundary.
Evidence reviewed 6 items Current-main baseline: Current main's restore path builds a fresh plugin-ID normalizer, freezes the result, and binds its cache; completion uses that restore path after rebasing. The central optimization is therefore not already on main.
Introduced boundary split: The introduced diff adds a local finalizer that freezes and preserves the supplied normalizer, while restore continues to construct a normalizer before finalization.
Cache-owner contract: Snapshot cache ownership is held in a WeakMap and bound by the same helper the new finalizer calls, preserving deferred access in the source cache generation.
Findings None None.
Security None None.

How this fits together

Plugin metadata snapshots collect immutable plugin manifests, aliases, and ownership facts for configuration, CLI, and Gateway startup. Local composition can retain prepared functions, but worker transfers must restore process-local functions that structured cloning omits.

flowchart LR
  A[Plugin inventory] --> B[Metadata snapshot]
  B --> C[Rebase manifests and aliases]
  C --> D{Execution boundary}
  D -->|Local composition| E[Freeze and bind cache]
  D -->|Worker transfer| F[Rebuild normalizer]
  E --> G[CLI and Gateway consumers]
  F --> G
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source -1. Total -1 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 2 49 50 -1
Tests 0 0 0 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 49 50 -1

Review metrics

Metric Value Why it matters
Production versus test LOC production −1 net; tests unchanged The refactor consolidates the local finalization path without adding test-only or runtime surface area.

Stored data model

Persistent data-model change detected: unknown-data-model-change: src/plugins/plugin-metadata-snapshot.ts, vector/embedding metadata: src/plugins/plugin-metadata-snapshot.ts. Confirm migration or upgrade compatibility proof before merge.

Technical review

Best possible solution:

Use the shared finalizer for snapshots that remain in-process, and reserve restoration for worker-transferred snapshots where the function is absent.

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

Not applicable: this PR optimizes internal snapshot preparation rather than reporting a user-facing bug.

Is this the best way to solve the issue?

Yes. The new finalizer centralizes existing freeze/cache binding while preserving reconstruction at the sole worker boundary that requires it.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P3: This is a small internal performance refactor with no configuration, persisted-state, API, or user-visible behavior change.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: Not applicable to this MEMBER-authored internal refactor; the supplied PR evidence describes a real worker transport scenario, while source inspection confirms the changed owner and retained worker restoration boundary.

Evidence

What I checked:

  • Current-main baseline: Current main's restore path builds a fresh plugin-ID normalizer, freezes the result, and binds its cache; completion uses that restore path after rebasing. The central optimization is therefore not already on main. (src/plugins/plugin-metadata-snapshot.ts:110, c505a0b65b70)
  • Introduced boundary split: The introduced diff adds a local finalizer that freezes and preserves the supplied normalizer, while restore continues to construct a normalizer before finalization. (src/plugins/plugin-metadata-snapshot.ts:110, 3897a98a8988)
  • Cache-owner contract: Snapshot cache ownership is held in a WeakMap and bound by the same helper the new finalizer calls, preserving deferred access in the source cache generation. (src/plugins/plugin-cache.ts:73, 3897a98a8988)
  • Worker caller remains explicit: The model-catalog worker restores the transferred metadata snapshot before preparing its runtime generation, so it continues to receive a newly constructed local normalizer. (src/agents/prepared-model-catalog.worker.ts:99, 3897a98a8988)
  • Relevant existing coverage: The metadata test suite already exercises worker-style structured cloning, restored alias normalization, and immutable collection behavior; this refactor changes no tests. (src/plugins/plugin-metadata-snapshot.test.ts:933, 3897a98a8988)
  • Area history: Recent history shows repeated merged metadata-cache and prepared-runtime work by Peter Steinberger; the available history supports routing but not a source-line introduction pointer because a required historical blob is unavailable locally. (src/plugins/plugin-metadata-snapshot.ts:110, 38f80876377c)

Likely related people:

  • Peter Steinberger: 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 (1 earlier review cycle)
  • reviewed 2026-09-02T06:46:07.120Z sha 3897a98 :: needs maintainer review before merge. :: none

@steipete

steipete commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

Parent maintainer review is complete. The stored-data-model notice is a filename-based false positive: this change reuses a process-local alias normalizer and the existing freeze/cache-binding functions. It does not change a database, persisted representation, migration, retention, or concurrency policy. Worker recipients still rebuild their own normalizer unconditionally. The 78 existing tests and actual structured-clone/receiving-cache proof cover that boundary; no migration or upgrade action is required.

@steipete
steipete merged commit 3725a3a into main Sep 2, 2026
338 of 339 checks passed
@steipete
steipete deleted the codex/perf3-metadata-normalizer branch September 2, 2026 07:10
@steipete

steipete commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

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. rating: 🐚 platinum hermit Good normal PR readiness with ordinary 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