Skip to content

perf(skills): reduce retained text resource payloads - #182525

Merged
steipete merged 4 commits into
mainfrom
steipete/perf-micro-skill-resource-delivery-20260919
Oct 24, 2026
Merged

steipete merged 4 commits into
mainfrom
steipete/perf-micro-skill-resource-delivery-20260919

Conversation

@steipete

@steipete steipete commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Performance qualified and final-head CI passed on 2a5e96c56b6678584a4649c09c9cdb8fabdf838c.

What Problem This Solves

Remote worker skill delivery base64-encodes every supporting file, retaining expanded strings for recoverable launches and decoding/re-encoding them during validation. Eight concurrent deliveries of the same synthetic skill set retain eight copies.

User Impact

Lower allocation and retained memory for text skill bundles. Exact file bytes, revisions, executability, fresh supporting-file reads, path safety, limits, and retry behavior remain intact. No configuration or protocol change. Ordinary local Codex turns do not use this bulk-delivery path.

Why This Change Was Made

Both bundle readers now use the existing UTF-8 representation for ASCII content when JSON escaping does not exceed base64 size. Unicode remains base64 so a single non-Latin-1 character cannot double a mostly ASCII JS string. NUL content remains base64 to preserve the library viewer's binary classification. Native JSON sizing handles other escaped controls; a native NUL search replaces the costly broad control-character regex. ZIP import uses the existing encoding-aware decoder.

A mutable-tree cache would need watcher-coverage and invalidation ownership to preserve immediate supporting-file freshness. This smaller change keeps the reads and removes unnecessary encoding work. Runtime growth is 14 lines for one-byte string storage, exact-byte/binary-preview compatibility, and bounded serialized size. Diff accounting: runtime +14, benchmark +357, benchmark documentation +40, tests/helpers +41. The requested non-test/non-docs/ filter reports +411 because it includes the benchmark and its README.

Evidence

Two synthetic skills model a directory-size inventory: 32 files and 1,302,894 bytes per turn. Each measured side completed 128 operations with eight retained deliveries, 4,096 source reads, and 166,770,432 bytes read. All measurements ran on the authorized Linux sandbox, Node 26.12.1, under the shared exclusive slot, with concurrent sides, interleaved 16-CPU sets, synchronized warm starts, swapped placement, and counterbalanced launch order. Allocation sampling and promotion tracing ran separately from untraced timing/GC gates.

Metric Pair 1, baseline → final Swapped pair 2, baseline → final Mean paired result
CPU ms / 128 operations, untraced 789.817 → 793.404 768.614 → 758.765 −3.131 ms; −0.41% (neutral)
Elapsed ms / 128 operations, untraced 479.058 → 486.350 469.377 → 476.254 +7.084 ms; +1.49%
Sampled JS allocation bytes / turn 5,506,621 → 4,732,798 5,503,195 → 4,751,381 −762,818 bytes; −13.86%
Total GC ms / 128 operations, untraced 34.498 → 24.137 32.484 → 22.221 −10.312 ms; −30.81%; −0.08056 ms/op
Maximum single pause ms, untraced 12.126 → 4.767 10.927 → 4.084 Both improved
Promoted bytes / 128 operations, separately traced 225,119,864 → 168,858,040 227,061,096 → 163,696,544 −59,813,188 bytes; −26.45%
Promotion-pass collection count 17 → 15 17 → 15 No cycle normalization
Post-GC heap delta bytes, eight deliveries held 9,618,464 → 6,152,216 9,617,096 → 6,153,944 −3,464,700 bytes; about 433,088 bytes/held turn
Loop p99/max ms (sample count), untraced 23.183 (22) → 22.069 (23) 24.756 (21) → 22.299 (22) Context only

Mean allocation was 5,504,908 → 4,742,090 bytes/turn. Exact retained payload characters fell 13,897,920 → 10,423,152 across eight deliveries (−25.0%). Descriptor JSON fell 13,924,288 → 11,004,856 bytes (−20.97%); transfer chunks still use base64, so this is not a claim about every transport's wire bytes. The absolute paired heap saving is useful; a percentage of the before/after heap delta is sensitive to warmup state.

Untraced GC detail Pair 1, baseline → final Pair 2, baseline → final
Minor total ms (count) 17.758 (15) → 15.388 (14) 14.765 (14) → 13.784 (14)
Major total ms (count) 15.966 (2) → 8.135 (2) 16.967 (2) → 7.806 (2)
Other GC total ms (count) 0.775 (2) → 0.614 (2) 0.753 (2) → 0.631 (2)
Minor maximum ms 1.441 → 1.288 1.274 → 1.653
Major/overall maximum ms 12.126 → 4.767 10.927 → 4.084
Minor p95/p99 ms (samples) 1.422/1.446 (15) → 1.238/1.294 (14) 1.118/1.278 (14) → 1.070/1.654 (14)
Major p95/p99 ms (samples) 12.158/12.158 (2) → 4.798/4.798 (2) 10.942/10.942 (2) → 4.094/4.094 (2)

All GC pause percentiles and loop tails are context at these sample counts; loop p95 was not collected. CPU signs differ slightly, so the signed absolute mean is reported without claiming a speedup. No adverse gate triggered; the predeclared would-gate-only extra pair and matched controls were unnecessary. Acceptance is supported by consistent allocation reduction, lower promotion/GC, and neutral CPU. The shared guard paused before the second final-candidate pair because dirty memory exceeded 2 GB, then cleared before it started. No pair was interrupted, excluded, or trimmed; maintenance stayed enabled.

Two earlier implementations were rejected and their results retained. The JS escape-loop version increased CPU 32.10% and 26.74% (mean +29.42%); max pauses were 7.770 → 3.035 ms and 13.045 → 9.413 ms. Native JSON sizing with the broad control regex still increased CPU 24.10% and 12.17% (mean +18.13%, both over 10%), despite allocation −14.73%; max pauses were 6.982 → 6.086 ms and 9.150 → 5.886 ms. Replacing that regex with the required NUL check removed the CPU regression. The first version's runs had fixed A-first launch order and no mpstat context; all fresh comparisons counterbalanced launch order and recorded mpstat. All 19 completed pairs, including earlier A/A controls, are preserved in the local evidence. Earlier identical-source controls included a 17.994 → 66.199 ms max-pause rise; they are context, not reused qualification for the final candidate.

Worker consumption proof

Real child-stdin staging materialized all synthetic files with exact byte readback on both versions. The actual isolated Gateway also used real device enrollment, sessions.dispatch, chat.send, and a deterministic mock provider. Baseline and final-candidate full turns passed: native exec read the staged supporting file, returned the same 476 bytes (SHA256 d32f8d12cdfd9fbe8dc49807861f3ab3e0a0ef9eccc0fe431aadc1cccd0a8f57), and completed with agent.wait status ok.

Preparation ran once per full turn: 25 skills, 71 files, 1,483,336 decoded bytes. Retained payload characters fell 1,977,888 → 1,506,527 (−23.83%). This proves real worker/tool consumption with a mock provider; it does not measure live-provider behavior or inference performance. Full Gateway runtime source was pinned to 280c7c7d494a796cc870fbd794088b84df1e53dc with the measured encoder overlaid, not rebuilt from the final PR head. Final encoder SHA256 is 675e09e07110d85de3b28a0aaff08e35f01d8ded0895167a16b9dfe3beac8c8f; baseline bundle SHA256 is a67b957c37e5e2fa2e97bbbde0b7ef562b5997441603793206bd5f2f64f6b93a, also verified on latest main after rebase.

The initial source-mode rig could not launch its native child-process anchor and misleadingly reported missing admission. The existing standalone-anchor build and sealed-registration fixture mechanism fixed setup without bypassing guards. The successful baseline had one separate post-turn title request outside the initial mock handling; its completed turn/file result was independently verified, and the final candidate handled that utility request with zero mock errors. Owned processes stopped, proof ports closed, and the measurement slot was released.

Validation

  • Retention regression failed on base: 3,200 text bytes retained as 4,268 content characters. Final round-trip cases cover ASCII, Unicode, binary, empty, dense escaping, sparse controls, and sparse NUL with preserved binary classification.
  • 130 unique focused tests passed across bundle/resource/library/paired-node, persistence, lint policy, and Gateway authoring consumers. The final 17-test bundle file passed in 687 ms (1.84 s wrapper). Its new NUL fixture initially used a reserved Windows device filename; renaming it fixed the fixture while preserving the portability guard.
  • Changed-file format/lint, targeted pnpm tsgo:core, and git diff --check passed. No broad local suite or Testbox/Crabbox lease. Final-head full CI (40095751000) and aggregate gate (40096374615) passed on 2a5e96c56b6678584a4649c09c9cdb8fabdf838c.
  • Initial CI found three base64-only fixture groups and a lint-suppression policy failure. Exact-byte consumer assertions and a suppression-free implementation fixed them; no CI rerun was used to chase green.
  • Independent subagent review (autoreview route unavailable): no actionable findings on the final source/test delta. The configured review route refused to start; configuration was not changed. Prior-head GitHub Codex and ClawSweeper reviews also found no correctness defect; performance qualification is now supplied above.

Rerun: node --expose-gc --import ./scripts/tsx.mjs scripts/perf/skill-resource-delivery-measure.ts --state-dir /path/to/isolated/fixture --operations 128 --concurrency 8. The performance README documents functional transfer, Unicode/binary, allocation, promotion, and synchronized-start modes. Raw measurement archive SHA256: 310c95d7fa8aa87dfb4ee7972ecb4bc99e614fdbe9da1c77a45f417c23b75962.

@clawsweeper

clawsweeper Bot commented Oct 24, 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 October 24, 2026 10:34
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review 🔄 Running since 2026-10-24T12:52:47.506898Z 2a5e96c New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime scripts Repository scripts size: M labels Oct 24, 2026
@steipete
steipete force-pushed the steipete/perf-micro-skill-resource-delivery-20260919 branch from b527df4 to 3bc2e46 Compare October 24, 2026 10:47
@steipete
steipete marked this pull request as draft October 24, 2026 10:58
@steipete
steipete force-pushed the steipete/perf-micro-skill-resource-delivery-20260919 branch from 3bc2e46 to 5c4c384 Compare October 24, 2026 11:09
@steipete
steipete marked this pull request as ready for review October 24, 2026 11:13
@clawsweeper clawsweeper Bot added clawsweeper:intake:feature Preliminary submission classification; full source review pending. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:feature Preliminary submission classification; full source review pending. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 24, 2026
@clawsweeper

clawsweeper Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR retains suitable ASCII skill resources as UTF-8 instead of base64 while preserving exact bytes and existing binary handling.

Example: Deliver a 3,200-byte ASCII supporting file containing ordinary newlines and quotes.

  • Before: The retained base64 content occupies 4,268 characters.
  • After: The retained UTF-8 content occupies 3,200 characters and decodes to the same bytes.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, source-correct optimization with meaningful paired measurements and reported worker consumption; evidence is bounded to synthetic workloads and the documented runtime overlay.
Proof confidence 🐚 platinum hermit (4/6) Maintainer-authored PR outside the ordinary proof gate; supplied evidence reports real child-stdin staging and an isolated Gateway worker turn consuming identical supporting-file bytes with a deterministic mock provider, using an older pinned runtime with the final encoder overlaid rather than a complete final-head rebuild.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Concurrent remote worker turns retain expanded base64 strings for ordinary text skill resources.
Reason: The feature-history owner approved this direction through the maintainer-authored PR, and the reported memory gains support a small change using an existing encoding contract.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-owned optimization remains useful and absent from main; the updated measurements address the earlier performance hold, and no actionable defect was found.

Priority: P2
Reviewed head: 2a5e96c56b6678584a4649c09c9cdb8fabdf838c

Before merge

None.

Findings

None.

Agent review details

How this fits together

Skill bundle readers convert filesystem artifacts into resource descriptors consumed by library APIs and remote worker staging; existing decoders recover bytes, executable metadata, and immutable revision identity.

flowchart LR
  A[Skill filesystem artifacts] --> B[Bundle readers]
  B --> C[Shared encoding selection]
  C --> D[Resource descriptors]
  D --> E[Existing byte decoder]
  E --> F[Library publication]
  E --> G[Worker staging]
Loading

Technical review

Best possible solution:

Land the shared encoder and encoding-aware import change through the existing exact-head gates, preserving fresh reads and byte-based revision identity.

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

Current-main source establishes unconditional base64 expansion, and the body reports the retention regression failing on the base; this read-only review executed no target code.

Is this the best way to solve the issue?

Selecting the representation at the existing bundle owner is the smallest complete change: it removes expansion without introducing cache invalidation, another delivery owner, or a new protocol.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Bundle encoding and import decoding keeps the original intent (75bcd26: Personal skill libraries preserve complete supporting artifacts and immutable revisions across library and worker transports; the original decoder already supports both encodings.)
  • Persistence and consumer assertions keeps the original intent (test(gateway, skills, cron): remove low-value tests (batch d262) #176775: Fixture consolidation preserved distinct persistence and delivery contracts; the revised assertions continue checking exact bytes, executable metadata, pins, and catalog identity.)
  • Retained supporting-file assertions keeps the original intent (f2e5268: Text-only edits retain exact supporting files while uploads are disabled; the updated expectations preserve that behavior under the existing UTF-8 representation.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

  • Focused introduced change: The pinned introduction diff adds one shared encoder to both bundle readers and updates import publication to use the existing encoding-aware decoder. (src/skills/library/bundle.ts:146, 2a5e96c56b66)
  • Existing representation and persistence contracts: The protocol already accepts UTF-8 and base64; bundle preparation hashes decoded bytes and metadata, and publication persists the same artifact bytes and manifest fields. (packages/gateway-protocol/src/schema/skill-library.ts:16, 2a5e96c56b66)
  • Current main still retains expanded payloads: Fetched main unconditionally base64-encodes resource content in both bundle readers, so this PR contributes distinct production work. (src/skills/library/bundle.ts:90, 0b55fb8d7eb5)
  • Binary-preview compatibility: The library viewer treats NUL-containing decoded base64 as binary; the encoder preserves base64 for these files and for non-ASCII bytes. (ui/src/pages/skills/library-file-text.ts:3, 2a5e96c56b66)
  • Updated performance qualification: The complete PR body reports counterbalanced baseline/candidate comparisons with allocation reduced 13.86%, promotion reduced 26.45%, approximately 3.46 MB less retained heap across eight deliveries, and neutral CPU; both rejected CPU-regressing implementations remain documented. This addresses the previous review's sole rank-up move. (2a5e96c56b66)
  • Regression and consumer coverage: The new filesystem-to-serialization regression verifies exact bytes and bounded descriptor size for ASCII, Unicode, binary, escaped, control-containing, NUL-containing, and empty resources; existing publication, persistence, and worker assertions retain their distinct contracts. (src/skills/library/bundle.test.ts:45, 2a5e96c56b66)

PR surface

Source +14, Tests +41, Docs +40, Other +357. Total +452 across 10 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 2 19 5 +14
Tests 6 60 19 +41
Docs 1 40 0 +40
Config 0 0 0 0
Generated 0 0 0 0
Other 1 357 0 +357
Total 10 476 24 +452

Labels

Label changes:

  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.

Label justifications:

  • P2: Concurrent worker deliveries retain avoidably expanded resource strings; this is a bounded memory improvement without evidence of an urgent 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.

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.

History

Review history (1 earlier review cycle)
  • reviewed 2026-10-24T11:41:26.137Z sha 5c4c384d263ffc1483ce638489995e630c792e4c :: needs maintainer review before merge. :: none

Reviewed October 24, 2026, 9:00 AM ET / 13:00 UTC (Revision 2).

@steipete
steipete force-pushed the steipete/perf-micro-skill-resource-delivery-20260919 branch from 5c4c384 to 2a5e96c Compare October 24, 2026 12:52
@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

The final native NUL-check implementation is now on 2a5e96c56b6678584a4649c09c9cdb8fabdf838c, with fresh paired measurements in the body: allocation −13.86%, promotion −26.45%, CPU neutral, and 3.46 MB less retained heap across eight deliveries. Both earlier CPU regressions remain documented. The final full worker turn consumed the exact supporting-file bytes and passed; focused tests and independent review are clean. Final-head CI is running.

@clawsweeper

clawsweeper Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added the clawsweeper:intake:feature Preliminary submission classification; full source review pending. label Oct 24, 2026
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. clawsweeper:intake:feature Preliminary submission classification; full source review pending. labels Oct 24, 2026
@steipete
steipete merged commit 45789f5 into main Oct 24, 2026
152 of 153 checks passed
@steipete
steipete deleted the steipete/perf-micro-skill-resource-delivery-20260919 branch October 24, 2026 13:04
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 25, 2026
* perf(skills): avoid base64 expansion for text resources

* test(skills): verify resource bytes across compact encodings

* perf(skills): size text payloads with native JSON serialization

* perf(skills): use native NUL detection for compact text resources
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. scripts Repository scripts size: L 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