Repository navigation
perf(skills): reduce retained text resource payloads - #182525
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
b527df4 to
3bc2e46
Compare
3bc2e46 to
5c4c384
Compare
|
Codex review: needs maintainer review before merge. What this changesThis 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.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete 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 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherSkill 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]
Technical reviewBest 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
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +14, Tests +41, Docs +40, Other +357. Total +452 across 10 files. Added test files: 0. View PR surface stats
LabelsLabel changes:
Label justifications:
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (1 earlier review cycle)
Reviewed October 24, 2026, 9:00 AM ET / 13:00 UTC (Revision 2). |
5c4c384 to
2a5e96c
Compare
|
@clawsweeper re-review The final native NUL-check implementation is now on |
|
🦞👀 Re-review progress:
|
* 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
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.
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.
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: nativeexecread the staged supporting file, returned the same 476 bytes (SHA256d32f8d12cdfd9fbe8dc49807861f3ab3e0a0ef9eccc0fe431aadc1cccd0a8f57), and completed withagent.waitstatusok.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
280c7c7d494a796cc870fbd794088b84df1e53dcwith the measured encoder overlaid, not rebuilt from the final PR head. Final encoder SHA256 is675e09e07110d85de3b28a0aaff08e35f01d8ded0895167a16b9dfe3beac8c8f; baseline bundle SHA256 isa67b957c37e5e2fa2e97bbbde0b7ef562b5997441603793206bd5f2f64f6b93a, 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
pnpm tsgo:core, andgit diff --checkpassed. No broad local suite or Testbox/Crabbox lease. Final-head full CI (40095751000) and aggregate gate (40096374615) passed on2a5e96c56b6678584a4649c09c9cdb8fabdf838c.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.