Repository navigation
perf(plugins): stop re-hashing a verified plugin binary on manifest reads - #1371
Conversation
…eads Every manifest read went through ArchiveCache.Ensure, which reads and SHA-256 hashes the whole plugin binary under the cache's global mutex. The admin plugin list reads the manifest of every installation on each load, and a plugin asset request reads it twice, so each navigation hashed tens of megabytes serially per installed plugin. Add ArchiveCache.Manifest for callers that only read the manifest or serve packaged assets. It skips the hash while the binary is the same file, with the same size and mtime, that this process last hashed against the checksum the manifest still names. Any change, a new release path, or a failed check sends the read through the full check and repair. Launch paths (Start, the connection test, preload) keep calling Ensure, which still hashes the binary on every call, so the tamper check in front of exec is unchanged. The hash now streams the file instead of loading it whole, which drops a launch check's allocation from the binary's size to about 37 KB. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Review follow-up for the manifest read change. The archive cache test now renames a different binary with the verified size and mtime over the installed one and expects Manifest to hash and repair it. Without the os.SameFile comparison the test fails; before, nothing covered it. Rename the service helper installedManifest to loadForManifestRead so it no longer shares a name with a local variable in doEnsureClient, and rename the benchmark case launch to ensure, since it measures ArchiveCache.Ensure and starts no process. Correction to the previous commit message: startup preload checks and rehydrates files without executing them. Launches go through start or the connection test, and both call Ensure. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
|
Warning Review limit reachedNext included review available in 1 minute. View limit detailsLimit details: You’ve used all 2 included reviews currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (6)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Quick104 has reached the 50-credit limit for trial accounts. To continue receiving code reviews, upgrade your plan.
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. |
Problem
Related issue: N/A
Validation tasks: could reach #1224 C1 (load a catalog plugin, verify SHA-256, reject mismatches) and #1225 C1 (install a catalog plugin and see usable status); neither case has a recorded result. The checksum check before a plugin launches is unchanged.
Every read of an installed plugin's manifest hashed the plugin's whole binary.
ArchiveCache.Ensurereads the binary, computes its SHA-256, and compares it with the checksum in the installed manifest, all under the cache's one mutex. Callers that only need the manifest went through it too:With a 16 MiB binary, one warm manifest read took about 59 ms and allocated 16.8 MB in the benchmark below. The mutex serializes these reads, so a plugin page load hashes every installed binary in turn, and concurrent plugin asset requests wait behind it.
Approach
ArchiveCachegets aManifestmethod for callers that read the manifest or serve packaged assets and never execute the binary. After a successful hash, the cache records per installation the binary's path, the checksum it matched, and the file's identity (device and inode), size, and mtime, taken from the open file before hashing. A laterManifestcall skips the hash only if the binary at that path is still the same file with the same size and mtime, and the manifest still names the same checksum. Any other case goes through the full check and repair thatEnsureruns: the first read in a process, a new release path, a replaced or rewritten file, a changed checksum. A failed check drops the record.Ensurestill hashes the binary on every call and never reads the record. Every launch goes throughstart(reached fromStart, the on-demand client path, and the resident supervisor) or the admin connection test, and both callEnsurebefore exec. Startup preload, which checks and rehydrates files without running them, also still callsEnsure. The manifest-only service paths (manifestForInstallation,ResolveAssetPath,SetGlobalConfigWithClears,networkAccessManifest) now callManifest.Security reasoning:
Ensurehashes the binary, rejects it, and restores the stored archive before exec.TestArchiveCacheManifestTrustsOnlyAnUnchangedVerifiedBinarycovers this case.On a cluster, the record lives in each process's memory. Every API server and proxy node hashes its own copy of a binary once after it starts before trusting it. A new release lands in a new install directory, so its path changes and it is hashed before the record applies.
The hash now streams the file with
io.Copyinstead of loading it withos.ReadFile. That gives tests a hook to count hashed bytes, and it cuts the allocation of each launch check from the binary's size to about 37 KB.Alternatives considered:
Before and after
Fixture: an installed plugin with a 16 MiB binary and one packaged asset, read after one warm-up read. For "before", a temporary copy of the same fixture and benchmark ran against the base commit. Its hashed-byte counter was a temporary one-line counter at the base's hash call, not committed.
countHashedBytesafterServeAssetcallStart)rchardelta in/proc/self/ioaround one call, no instrumentation. The after value is the 420-byte manifest file plus about 113 bytes from reading/proc/self/ioitselfBenchmarkInstalledPluginWarmRead/manifest,-benchmemEnsure), B/opBenchmarkInstalledPluginWarmRead/ensure(the check only; no process starts)Ensure), timeTestServiceManifestReadsSkipRehashOfVerifiedBinaryasserts zero hashed bytes for each warm manifest-only path and a full hash on everyStart. With the record disabled, it fails: each warm read hashes 1,048,576 bytes (its 1 MiB fixture) and an asset request hashes 2,097,152.TestArchiveCacheManifestTrustsOnlyAnUnchangedVerifiedBinarycovers each part of the file check.Manifesthashes and repairs after a visible change and after a different file is renamed over the binary with the verified size and mtime. It skips an in-place rewrite that keeps size and mtime, which the nextEnsurecatches and repairs. A failed check clears the record, and a new release path is hashed before it is trusted.Validation
All checks below ran on the branch after a clean rebase onto current
main. The branch changes no web, migration or workflow files, so the web build,make migrate-validateand workflow lint did not apply.make embed-stub,go build ./...,go vet ./...: pass.gofmt -l .: empty.make lint-changed: 0 issues.GOFLAGS=-p=6 make test-go: 158 packages pass, includinginternal/plugins,internal/api/handlersandinternal/apiv2. One failure:internal/policyTestEngineReloadRejectsInvalidCustomSource, where a policy evaluation hit its 25 ms timeout while the shared host ran at load average about 165.internal/policydoes not importinternal/plugins. Run alone, the test passed 5 of 5 times on this branch and onmain, and the whole package passed on a re-run.make verify-settings-bindings-all verify-playback-fixtures verify-route-inventory verify-migration-ledger verify-scenario-catalogs verify-offline-routes verify-apiv2-openapi verify-apiv2-contract verify-apiv2-fixtures verify-local-paths: all pass.go test -count=1 -run '^TestCommittedArtifactMatchesRouter$' ./internal/apiv2/: pass.-race.Manifestforced to hash, both new tests fail, and the service test reports 1,048,576 hashed bytes per warm read and 2,097,152 per asset request. WithEnsureforced to trust the record, both fail. With the size and mtime comparison removed, or the file identity comparison removed, the archive cache test fails.Ensure. Six runs each at load average about 50 gave a 42.9 µs median (36.0 to 58.7) for a warm manifest read and a 60.9 ms median (52.2 to 64.5) forEnsure, in line with the table.Risks
statcalls and a manifest parse instead of a full hash.Checklist
AI Disclosure
EnsureandManifest, and re-ran the measurements in scratch worktrees of the base and the branch. Every deterministic number in the table reproduced exactly; its timings differed only with host load. It also ran negative checks: forcingManifestto hash, forcingEnsureto trust the record, and removing parts of the file check. It approved with no blocking findings. Its findings and how each was resolved:os.SameFileleft the package passing. Fixed: the archive cache test now renames a different same-size file with the verified mtime over the binary and expects a hash and repair. It fails withoutos.SameFile.startor the connection test, and preload only checks and rehydrates files. The first commit's message is left as is because the squash merge replaces it.installedManifestshared its name with a local variable indoEnsureClient. Fixed: renamed toloadForManifestRead.launchmeasured onlyEnsure, not a process start. Fixed: renamed toensure.🤖 Generated with Claude Code