Repository navigation
Hash agent-mode jar members through the shared streaming zip comparator instead of buffering each member #914
Description
Activity
- addedpm:mavenMavenMavenarch-auditFiled by a scheduled architecture audit routine (see the architecture review discussion)Filed by a scheduled architecture audit routine (see the architecture review discussion)refactorStructural change: duplicated code or logic, missing abstraction, layering, dead codeStructural change: duplicated code or logic, missing abstraction, layering, dead code
on Oct 6, 2026 - added a commit that references this issue
on Oct 6, 2026 mikolalysenko commented
on Oct 6, 2026 CollaboratorAuthorMore actions[agent] Triaged as priority:p3 (Maven/Gradle agent-mode refactor). Not a duplicate: #569 (fixed by #587) covered the vendored routine only. No open PR covers it yet.
Generated by Claude Code
- added a commit that references this issue
on Oct 6, 2026 mikolalysenko commented
on Oct 9, 2026 CollaboratorAuthorMore actions[agent] Claiming this issue for the architecture refactor routine (highest leverage among free files: removes the buffered jar-member read on every agent-mode Maven/Gradle verify, S 3). Slice: the shared streaming helper plus
jvm_jar.rs;vendor/common.rsfollows when #1227 frees it. Branch: arch-refactor/914-jar-member-stream. Claim-ID: 2026-10-09T08:58:00Z-02b9a7
Generated by Claude Code
mikolalysenko commented
on Oct 9, 2026 CollaboratorAuthorMore actions[agent] Draft PR: #1253 (shared
zip_member_git_sha256helper + thejvm_jar.rsverify path). Thevendor/common.rscaller remains for a follow-up once #1227 no longer changes that file.
Generated by Claude Code
- added a commit that references this issue
on Oct 9, 2026 mikolalysenko commented
on Oct 9, 2026 CollaboratorAuthorMore actions[agent] The agent-mode slice merged in #1253:
jvm_jar::verify_member_bytesnow streams each member throughhash::git_sha256::zip_member_git_sha256(302 → 30 MiB peak RSS on a 256 MiB member). Remaining: movevendor/common.rs::zip_bytes_match_after_hashesonto the same helper (the file is free now that #1227 merged) and commit a test for a member whose declared size disagrees with its stream. Releasing the claim until a PR takes that slice.
Generated by Claude Code
[agent] Filed by the scheduled architecture audit routine (CLI and core). Register: register comment.
Kind: refactor (performance; one duplicated routine). Source: new finding, register row C51. It is the agent-mode twin of C01 (#569, fixed by #587).
Problem (main @
9c43dfc)There are two routines that hash named zip members with Git SHA-256 and compare them to a patch record, and they have drifted apart.
Vendored (streams):
vendor/common.rs::zip_bytes_match_after_hashes. Since #587, following the maintainer's direction on #569, it streams each member throughcompute_git_sha256_from_std_reader:Agent mode (buffers):
patch/jvm_jar.rs::verify_member_bytesinflates every patched member into aVecand then hashes it:verify_member_bytesruns on every agent-mode Maven/Gradle jar record: inapplyverification throughverify_members(apply.rs L397–L401), invexverification (vex/verify.rs L344–L349), inapply_jar_swap(L464) and in the rollback restore (L634). That covers every copy in~/.m2and in each Gradle cache hash directory.Measured (temporary core lib test, debug build, peak RSS from
/proc/self/statusVmHWM, run twice with the same result): a jar holding one deflated 1 GiB member (1.0 MB on disk) plus one small member, with a record for the big member.jvm_jar::verify_member_bytescommon::zip_bytes_match_after_hashesSymptoms
None filed. Impact: memory grows with the inflated member size on each agent-mode jar verification, in
apply,rollbackandvex. This is the same defect #569 fixed for vendored mode, so it is per the maintainer a performance problem, not a trust one; no cap is proposed. Size: ~20 lines.Proposed change
hash::git_sha256::zip_member_git_sha256(archive, name) -> Option<io::Result<String>>. It looks up a member and streams it throughcompute_git_sha256_from_std_reader.zip_bytes_match_after_hashesandverify_member_bytesboth call it.read_to_endclosure inverify_member_bytes, and the duplicate lookup-and-hash loop inzip_bytes_match_after_hashes.is_safe_relative_subpath, and agent mode reports a missing member asNotFound/Ready.Size and scope
hash/git_sha256.rs,patch/jvm_jar.rs,vendor/common.rs: about 40 changed production lines.unpatched_membersandvendor::verify::read_zip_bytes_to_map(they need whole member bytes to rebuild the jar); the vendored per-file readers invendor/mod.rs(the sibling area); hash case (Agent-mode apply and rollback reject a manifest hash in uppercase hex that blob download accepts as valid #707); the digest helpers that Route Gradle digests through utils::digest #878 and sbt, Mill and scala-cli support in agent, hosted and vendored modes #690 touch injvm_jar.rs.Acceptance criteria
verify_member_bytesdoesn't buffer a member:rg "read_to_end" crates/socket-patch-core/src/patch/jvm_jar.rsprints nothing in the verify path.jvm_jarbuilds (streaming) a jar with a large zero-filled deflated member and checks theVerifyResultfor it. The peak-RSS check can stay out of CI, as Stream ZIP member hashes during vendored verification #587's did.jvm_jartests,patch::applyandvex::verifyjar tests, the Maven/Gradle agent e2e tests andvendor::commontests stay green.cargo clippy --workspace --all-features -- -D warningsis clean.Dependencies
None. It touches
jvm_jar.rslines that #878 and #690 don't edit (those change the privatesha256_hex/sha1_hex).