Skip to content

fix(api): include build-flag env vars in hosted bundle cache key#83

Merged
skullcrushercmd merged 1 commit intomainfrom
fix/bundle-cache-build-flag-key
Apr 28, 2026
Merged

fix(api): include build-flag env vars in hosted bundle cache key#83
skullcrushercmd merged 1 commit intomainfrom
fix/bundle-cache-build-flag-key

Conversation

@skullcrushercmd
Copy link
Copy Markdown
Contributor

Summary

When the API process runs with ANYSCAN_USE_AF_XDP=1 (or any of the sibling ANYSCAN_USE_DPDK / ANYSCAN_USE_PFRING_ZC / ANYSCAN_INSTALL_KERNEL_BACKPORT knobs), package-worker-bundle.sh rebuilds the scanner with matching feature linkage. The bundle carries a feature-flagged scanner even though the installed /opt/anyscan/bin/scanner is unchanged.

current_hosted_agent_bundle_source_fingerprint previously only hashed the embedded asset payload + the installed binaries — the build-flag env vars were absent from the cache key. A default-flags rebuild produced a fingerprint identical to a feature-flagged one and silently overwrote the cached AF_XDP/DPDK bundle. Operators bootstrapping via /api/agent/install.sh?rebuild=false then received an AF_PACKET-only stub scanner.

Reported in PR #65 issuecomment-4339242358 (anygpt-52): "/api/agent/install.sh?rebuild=false served a stub scanner".

Fix

Fold each documented build-flag env var name + value into the fingerprint hash. Bundles built with different flags now land in different cache slots; rebuild=false serves the bundle that matches the API's current build-flag environment instead of a stale one.

  • BUNDLE_BUILD_FLAG_ENV_VARS pins the exact set as a const &[&str] so any future ANYSCAN_USE_* knob surfaces as a compile-time decision (the test pin at the bottom of the test module enforces this).
  • hash_bundle_build_flag_env_vars takes an env-lookup closure so unit tests can hash hermetic inputs without poking std::env (which would race with parallel cargo test execution).

Test plan

  • cargo test --bin anyscan-api — 36 tests pass (including 5 new)
  • New: default vs ANYSCAN_USE_AF_XDP=1 produce different fingerprints
  • New: each flag flipped on its own produces a unique fingerprint (no AF_XDP/DPDK collision)
  • New: same flag with values \"1\" / \"0\" / unset are all distinct
  • New: repeated lookup with same input returns same fingerprint (determinism)
  • New: static check that the four documented flags are all in the const

🤖 Generated with Claude Code

When the API process runs with ANYSCAN_USE_AF_XDP=1 (or any of the
sibling ANYSCAN_USE_DPDK / ANYSCAN_USE_PFRING_ZC /
ANYSCAN_INSTALL_KERNEL_BACKPORT knobs), package-worker-bundle.sh
rebuilds the scanner with matching feature linkage. The resulting
bundle carries a feature-flagged scanner binary even though the
*installed* /opt/anyscan/bin/scanner stays the same.

`current_hosted_agent_bundle_source_fingerprint` previously only
hashed the embedded asset payload and the installed binaries — the
build-flag env vars were absent from the cache key. So a default-flags
rebuild produced a fingerprint identical to a feature-flagged one and
silently overwrote the cached AF_XDP/DPDK bundle. Operators bootstrapping
via /api/agent/install.sh?rebuild=false then received an
AF_PACKET-only stub scanner. Reported in PR #65 issuecomment-4339242358
(anygpt-52): "/api/agent/install.sh?rebuild=false served a stub scanner".

Fix: fold each documented build-flag env var name + value into the
fingerprint hash. Bundles built with different flags now land in
different cache slots; rebuild=false serves the bundle that matches
the API's current build-flag environment instead of a stale one.

- BUNDLE_BUILD_FLAG_ENV_VARS pins the exact set so future ANYSCAN_USE_*
  knobs surface as a static-array compile-time decision.
- hash_bundle_build_flag_env_vars takes an env-lookup closure so unit
  tests can hash hermetic inputs without poking std::env (which would
  race with parallel test execution).
- bundle_build_flag_env_fingerprint is a #[cfg(test)] helper that
  produces just the build-flag contribution as a SHA-256 hex digest.

Tests:
- Default vs ANYSCAN_USE_AF_XDP=1 produce different fingerprints.
- Each flag flipped on its own produces a unique fingerprint (no
  collisions between AF_XDP-only and DPDK-only builds).
- Same flag with values "1" / "0" / unset are all distinct.
- Repeated lookup with same input returns same fingerprint.
- Static check that the four documented flags are all in the const.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@skullcrushercmd skullcrushercmd merged commit 113e50e into main Apr 28, 2026
@skullcrushercmd skullcrushercmd deleted the fix/bundle-cache-build-flag-key branch April 28, 2026 22:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant