apm icon indicating copy to clipboard operation
apm copied to clipboard

[BUG] apm --version reports unrelated parent Git repository SHA

Open DaveMeadAdjust opened this issue 2 months ago • 4 comments

Describe the bug

apm --version can report an unrelated parent Git repository commit as though it were the APM build commit.

The packaged apm_cli.version.get_build_sha() has no injected __BUILD_SHA__. For a non-frozen installation it runs git rev-parse --short HEAD from its installed Python library directory. Git walks upward and may discover an unrelated ancestor repository.

To Reproduce

With APM 0.31.0 installed through Homebrew, run:

$ apm --version
Agent Package Manager (APM) CLI version 0.31.0 (edb70f031e)

The displayed SHA belongs to the Homebrew repository rather than APM:

$ git -C /opt/homebrew show -s --format='%H%n%s' edb70f031e
edb70f031e4170c780799633a1226ff73e1077f4
Merge pull request #24018 from Homebrew/sandbox-security-review

For comparison, the native APM v0.31.0 release archive reports:

Agent Package Manager (APM) CLI version 0.31.0 (8fd10ac)

Expected behavior

Installed PyPI/Homebrew packages should either:

  1. report a release SHA embedded during the package build, or
  2. omit the SHA when no trustworthy APM source checkout can be identified.

Runtime Git fallback should only be used after proving that the resolved repository is the APM source checkout. It must not accept an arbitrary ancestor Git repository.

Environment (please complete the following information):

  • OS: macOS
  • Python Version: 3.14.7
  • APM Version: 0.31.0 installed with the Homebrew core formula
  • VSCode Version (if relevant): Not applicable

Logs

The relevant command output is included in the reproduction above.

DaveMeadAdjust avatar Sep 18 '26 21:09 DaveMeadAdjust

Triage recommendation: accept (bounded)

Thanks for the clear reproduction and side-by-side comparison -- this is a solid bug report. apm --version's Git fallback in get_build_sha() walks upward from the installed library path and can pick up an unrelated ancestor repository (here, Homebrew's own repo) when no __BUILD_SHA__ was injected at package build time.

Proposed scope: For non-frozen installs, before trusting a git rev-parse result, verify the resolved repository root actually corresponds to the APM source checkout (e.g., check for a known APM marker file/path, or compare the repo's remote/toplevel against the installed package location) rather than accepting any ancestor Git repository. If it can't be verified, omit the SHA rather than showing a misleading one. Done when: apm --version never reports a commit SHA from an unrelated ancestor repository; either a verified release SHA or no SHA is shown. Exclusions: no change to how frozen/PyInstaller builds embed __BUILD_SHA__. Review needs: maintainer familiar with apm_cli.version and the packaging/build pipeline.

This is advisory only -- a responsible maintainer still confirms scope and priority per GOVERNANCE.md and CONTRIBUTING.md. If you'd like to work on this once scope is approved, just say so on the issue.

Automated triage advisory. Not a human scope decision.

Generated by Triage Panel · copilot · auto · 110.9 AIC · ⌖ 5.97 AIC · ⊞ 12K · ◷

github-actions[bot] avatar Sep 20 '26 12:09 github-actions[bot]

Hi, I’d like to work on this issue. Could a responsible maintainer confirm the proposed scope and name a review contact familiar with apm_cli.version and the packaging pipeline? I’d keep frozen/PyInstaller build behavior out of scope.

icecold009 avatar Sep 24 '26 17:09 icecold009

Decision: approve Area: project Scope: Repair non-frozen build-revision provenance: display a runtime Git SHA only when the loaded APM module demonstrably belongs to that actual APM source checkout; otherwise omit the SHA while preserving the correct version and successful apm --version output. Preserve existing injected build-SHA precedence and frozen/PyInstaller behavior. Done when: Real-CLI package-location regressions show that installed wheels under unrelated Git ancestors, and wheels installed inside an APM checkout, do not borrow those repositories' revisions. Genuine source/editable installations, forks and Git worktrees retain their own verified revision. Missing Git, no repository or unavailable provenance yields version-only output. Preserve and cover existing embedded/frozen paths and update directly related version-output documentation. A nearby marker or official remote alone is not proof that the loaded package is the checkout. Out of scope: Automatic CLI version selection or installation; new flags or configuration files; mandatory official-remote matching; release/distribution pipeline redesign or new build-SHA embedding requirements; changes to semantic-version resolution or frozen/PyInstaller output; unrelated diagnostic rewrites; assignment or automated delivery dispatch. Review contact: @danielmeppiel

danielmeppiel avatar Oct 15 '26 13:10 danielmeppiel

The bounded build-revision repair is accepted following my explicit confirmation, with me as review contact.

The goal is truthful troubleshooting information: if APM cannot establish its source revision, showing the version alone is better than reporting a Homebrew or other ancestor repository's commit. This does not require a new version manager, configuration file or release-pipeline redesign. Existing embedded build revisions and frozen/PyInstaller behavior remain unchanged.

The distinction is the loaded code, not merely a nearby Git repository. An installed wheel inside an APM checkout must not borrow that checkout's revision; a genuine source/editable installation, including a fork or worktree, should retain its own verified revision.

@icecold009's existing volunteer request is preserved. I am the review contact; no assignment or replacement implementation has been made. This records scope approval, not a delivery restart, PR approval, merge commitment or release date.

The separate unedited apm-scope:v1 comment is the machine-readable scope record. This explanation was drafted and posted with AI assistance after my explicit confirmation.

danielmeppiel avatar Oct 15 '26 13:10 danielmeppiel