Skip to content

fix(nix): embed full git revision in packaged build identity - #2743

Merged
Sinity merged 1 commit into
masterfrom
feat/expose-build-revision
Jul 12, 2026
Merged

Sinity merged 1 commit into
masterfrom
feat/expose-build-revision

Conversation

@Sinity

@Sinity Sinity commented Jul 12, 2026

Copy link
Copy Markdown
Owner

Summary

Nix-packaged Polylogue runtimes (polylogue/polylogued/polylogue-mcp) now embed the full 40-character git commit instead of a 7-character short revision, and the daemon's polylogue_daemon_build_info Prometheus metric now correctly exposes that full revision (it previously always reported version="unknown" due to a broken import).

Problem

flake.nix wrote BUILD_COMMIT from self.shortRev (7 hex chars), so every packaged runtime — polylogue --version, polylogued --version, ArchiveIdentity.build_commit (daemon status JSON), and the daemon build-info metric — could only ever report a truncated, collision-prone prefix. The Nix build/flake.lock retain the full revision, but nothing embedded it into the artifact, so a running artifact couldn't independently attest its exact source identity against a consuming flake's flake.lock rev/narHash during schema-sensitive rollouts.

Separately, polylogue_daemon_build_info always reported version="unknown" because it imported the nonexistent polylogue.__version__ (no such attribute on the package) inside a bare try/except.

Verified before fixing: building the package at HEAD (d81942345…) embedded BUILD_COMMIT = "d819423" (shortRev) into _build_info.py.

Solution

  • flake.nix: derive buildRevision from self.rev (falling back to self.dirtyRev with the literal "-dirty" suffix stripped, then "unknown"), and buildDirty from self ? dirtyRev; embed both into polylogue/_build_info.py. Added a checks.build-info derivation that builds the package and asserts the installed _build_info.py's BUILD_COMMIT/BUILD_DIRTY literally match self.rev/self.dirtyRev, and that polylogue --version surfaces the matching short prefix — a package-level proof the reported revision matches the flake input.
  • polylogue/daemon/metrics.py: fixed polylogue_daemon_build_info to source version/revision/dirty from polylogue.version.VERSION_INFO (the real API) instead of the broken __version__ import, and added revision (full commit) and dirty labels alongside the existing concise version label.
  • docs/daemon.md: new "Build Identity & Deployment Attestation" section documenting the concise-version vs. full-revision fields and how to join a running daemon's revision against a consuming flake's flake.lock rev/narHash.
  • tests/unit/daemon/test_metrics_endpoint.py: replaced the substring-order-dependent version-label assertion (labels are emitted alphabetically sorted, so {version= no longer prefixes the label set once dirty/revision are added) with an order-independent check, plus a new test pinning the revision/dirty labels and the full 40-char length.

polylogue/version.py and the storage/archive_identity.py / insights/export_bundles.py read paths already exposed VERSION_INFO.commit as a full, untruncated field for source checkouts and PyPI/hatch builds (git rev-parse HEAD is already full there) — only the Nix packaging path and the metrics label were truncated/broken. No schema change.

Acceptance criteria

  • Nix builds embed the full immutable revision when available — done (buildRevision/buildDirty in flake.nix).
  • CLI and daemon observability expose it in a stable machine-readable field while retaining a concise human version — done: VERSION_INFO.commit / archive_storage.identity.build_commit (daemon status JSON) / polylogue_daemon_build_info{revision=...} (Prometheus) are full; polylogue --version / POLYLOGUE_VERSION remain the concise 8-char-prefix human form.
  • Dirty/source-checkout behavior remains explicit — done: BUILD_DIRTY/VERSION_INFO.dirty/dirty="true|false" label, derived from self ? dirtyRev in Nix.
  • A package-level test proves the reported full revision matches the flake input — done: checks.x86_64-linux.build-info in flake.nix.
  • Document how operators join runtime identity to deployment lock/NAR evidence — done: new docs/daemon.md section.

Verification

  • nix flake check --no-build: all checks pass.
  • nix build .#checks.x86_64-linux.build-info --no-link --print-out-paths: passes; inspected the built store path directly — _build_info.py now contains BUILD_COMMIT = "d819423459dc1fdf3c2a249a5182d8d3970df3dd" (full 40 hex) and BUILD_DIRTY = True (dirty worktree at build time), vs. the prior BUILD_COMMIT = "d819423" on the same build.
  • devtools test tests/unit/daemon/test_metrics_endpoint.py tests/unit/core/test_version.py: 59 passed.
  • mypy --strict polylogue/daemon/metrics.py: no issues.
  • Pre-push hook ran devtools verify --quick (format + lint + mypy + render all --check): exit 0.
  • Not run: the full/heavy devtools test/devtools verify --all suite (per operator lean-verification directive for this session — the coordinator runs consolidated verification before merging).

Note: per the task instructions, GitHub CI is currently blocked by an account billing lock unrelated to this diff.

Ref polylogue-6rvt

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Jul 12, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

@Sinity, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 19 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 289f152e-c83b-4942-b638-8c4fa9156e83

📥 Commits

Reviewing files that changed from the base of the PR and between 59b179c and 88af2e3.

📒 Files selected for processing (4)
  • docs/daemon.md
  • flake.nix
  • polylogue/daemon/metrics.py
  • tests/unit/daemon/test_metrics_endpoint.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/expose-build-revision

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0328a88281

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

from polylogue import __version__ as polylogue_version
from polylogue.version import VERSION_INFO

build_version = VERSION_INFO.version

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep the metrics version label aligned with --version

For any build with commit metadata, this emits only the base package version (e.g. 0.1.0) while the new docs and commit message describe the metrics version label as the same concise human identity exposed by polylogue --version/POLYLOGUE_VERSION (e.g. 0.1.0+<8-char>[-dirty]). Operators comparing the build-info metric to CLI/log output will see different version strings for the same runtime, and dirty builds also lose the dirty marker in this label. Use VERSION_INFO.full/POLYLOGUE_VERSION here and leave the new revision label as the full machine-readable hash.

Useful? React with 👍 / 👎.

Problem: flake.nix wrote BUILD_COMMIT from self.shortRev (7 hex
chars), so every packaged runtime (polylogue --version, polylogued
--version, ArchiveIdentity.build_commit, the daemon build-info
metric) could only ever report a truncated, collision-prone prefix.
The Nix build itself already retains the full revision (self.rev),
but nothing embedded it, so a running artifact could not
independently attest its exact source identity against a consuming
flake's flake.lock rev/narHash during schema-sensitive rollouts.
Separately, polylogue_daemon_build_info always reported
version="unknown" because it imported the nonexistent
polylogue.__version__ (the package has no such attribute) and
silently fell back in a bare except.

What changed:
- flake.nix: derive buildRevision from self.rev (falling back to
  self.dirtyRev with its "-dirty" suffix stripped, then "unknown"),
  and buildDirty from `self ? dirtyRev`; embed both into
  polylogue/_build_info.py instead of the short forms. Added a
  checks.build-info derivation that builds the package and asserts
  the installed _build_info.py's BUILD_COMMIT/BUILD_DIRTY literally
  match self.rev/self.dirtyRev, and that `polylogue --version`
  surfaces the matching short prefix — a package-level proof the
  reported revision matches the flake input.
- polylogue/daemon/metrics.py: fixed polylogue_daemon_build_info to
  source version/revision/dirty from polylogue.version.VERSION_INFO
  (the real API) instead of the broken __version__ import, and added
  `revision` (full commit) and `dirty` labels alongside the existing
  concise `version` label.
- docs/daemon.md: new "Build Identity & Deployment Attestation"
  section documenting the concise-version vs full-revision fields
  and how to join a running daemon's revision against a consuming
  flake's flake.lock rev/narHash.
- tests/unit/daemon/test_metrics_endpoint.py: replaced the
  substring-order-dependent version-label assertion (labels are
  emitted sorted, so `{version=` no longer prefixes the label set)
  with an order-independent check, and added a test pinning the new
  revision/dirty labels and full 40-char length.

polylogue/version.py and the storage/archive_identity.py /
insights/export_bundles.py read paths already exposed
VERSION_INFO.commit as a full, untruncated field for source
checkouts and PyPI/hatch builds (git rev-parse HEAD is already full
there) — only the Nix packaging path and the metrics label were
truncated/broken.

Verification:
- nix flake check --no-build: all checks pass.
- nix build .#checks.x86_64-linux.build-info: passes; inspected the
  built store path directly — _build_info.py now contains
  BUILD_COMMIT = "d819423459dc1fdf3c2a249a5182d8d3970df3dd" (full 40
  hex, this worktree's base commit) and BUILD_DIRTY = True (dirty
  worktree), vs. the prior BUILD_COMMIT = "d819423" (shortRev) on
  the same build.
- devtools test tests/unit/daemon/test_metrics_endpoint.py
  tests/unit/core/test_version.py: 59 passed.
- mypy --strict polylogue/daemon/metrics.py: no issues.

Ref polylogue-6rvt

Co-Authored-By: Claude <[email protected]>
@Sinity
Sinity force-pushed the feat/expose-build-revision branch from 0328a88 to 88af2e3 Compare July 12, 2026 05:40
@Sinity
Sinity merged commit 355aa30 into master Jul 12, 2026
2 of 14 checks passed
@Sinity
Sinity deleted the feat/expose-build-revision branch July 12, 2026 05:40
Sinity added a commit that referenced this pull request Jul 12, 2026
## Summary

Completes the release-artifact recovery path for v0.2.0, makes every
documented install channel exercise its production packaging route, and
attaches verifiable browser-store submission metadata.

## Problem

v0.2.0 has a real GitHub tag/release but no release assets, no
release/Homebrew tag workflow run, and no PyPI project. Rebuilding from
current master could have published newer source under an older release
version. The documented pipx and Homebrew install paths had not been
exercised by their release workflows, and store archives were not bound
to a full source revision.

## Solution

- Release, container, and extension workflows accept release_tag,
resolve refs/tags/vX.Y.Z, and reject a checkout whose commit differs
from the tag target. Manual PyPI publication requires it.
- PyPI release CI builds and installs the wheel through pipx, smokes
CLI/daemon/MCP entrypoints, and requires installed VERSION_INFO to
contain the full 40-character checked-out revision.
- GHCR builds embed the full checkout revision, publish it as an OCI
label, then pull slim and distroless images and assert the concise CLI
prefix plus the exact machine-readable VERSION_INFO.commit. Recovery
never rewrites latest.
- Homebrew now audits, installs, and runs brew test on the generated
resource-expanded formula before opening its tap PR.
- Extension releases attach a source-revision-and-SHA-256
store-submission manifest alongside exactly one version-matched Chrome
archive, Firefox archive, and screenshot bundle. The installation matrix
documents every route and the no-recut recovery sequence.

## Acceptance matrix

| Bead | Status | Evidence |
| --- | --- | --- |
| polylogue-y8s5 | implementation support satisfied; external
publication deferred | Release, pipx, GHCR, Homebrew, and extension
lanes now have recovery/publish/smoke wiring. The documented v0.2.0
dispatches still require operator-owned PyPI Trusted Publishing and
Homebrew credentials. |
| polylogue-6rvt | satisfied/extended | PR #2743 supplied full revision
for Nix. This PR proves it from the installed wheel and embeds/smokes
the same full revision in GHCR runtimes. |

## Verification

- nix develop --command devtools release verify-distribution --work-dir
/realm/tmp/polylogue-distribution-pipx — built wheel + sdist, installed
each in isolated venvs, and exercised CLI, daemon, MCP, parser, and
diagnostics entrypoints.
- pipx install --suffix=-smoke
/realm/tmp/polylogue-distribution-pipx/dist/polylogue-0.2.0-py3-none-any.whl
— installed the built wheel through real pipx; polylogue-smoke,
polylogued-smoke, and polylogue-mcp-smoke all passed.
- node browser-extension/scripts/build.mjs --out
/realm/tmp/polylogue-adversarial-store --no-source-sync — emitted one
Chrome and one Firefox v0.2.0 archive; manifest checks verified
version-matched names, a 40-character source revision, SHA-256, and
sizes.
- nix develop --command devtools verify ci-workflows — verify
ci-workflows: 17 workflow files checked, no errors.
- nix shell nixpkgs#actionlint -c actionlint on the changed workflows —
exit 0.
- Pre-push devtools verify --quick — exit 0 after each commit.

The focused extension build suite has one reproducible unrelated
failure: its pre-existing packaged-service-worker fixture expects two
page requests and receives one. It does not cover any changed
workflow/docs/package-metadata path; its archive-emission tests pass.

No tests were added. The release verifier exercises the production Hatch
build configuration and installed console entrypoints; removing a
runtime dependency or entrypoint would fail the isolated-wheel smoke.
The pipx smoke exercises the documented installer rather than a test
wrapper. The Homebrew smoke executes the formula test shipped to users.
The extension build uses the production archive builder, and the
submission-manifest validation would fail if a required archive or its
integrity metadata were removed.
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