Skip to content

PER-10496 feat: emit machine identity for slow-build diagnostics - #2384

Open
Shivanshu-07 wants to merge 3 commits into
masterfrom
feat/per-10496-machine-identity
Open

PER-10496 feat: emit machine identity for slow-build diagnostics#2384
Shivanshu-07 wants to merge 3 commits into
masterfrom
feat/per-10496-machine-identity

Conversation

@Shivanshu-07

@Shivanshu-07 Shivanshu-07 commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Summary

CLI side of Build-processing diagnostics (slow builds) — PER-10496. Pairs with percy-api https://github.com/percy/percy-api/pull/6715, which validates and consumes everything sent here for per-machine liveness on parallel builds (naming the dead CI machine when one stops sending snapshots).

  • env.machine getter (@percy/env): { id, hostname, runUrl } — sanitized-hostname id suffixed with the CI node index where the provider exposes one (CIRCLE_NODE_INDEX, BUILDKITE_PARALLEL_JOB), and the CI run URL for circle/buildkite/github/gitlab. Deliberately excluded from the env getter debug logging (like token) — those debug logs are uploaded with build logs, and hostnames should not ride along.
  • Build create (@percy/client): machine-id / machine-hostname / machine-ci-run-url attributes (only when an id exists).
  • X-Percy-Machine-Id header on snapshot-create and build-finalize calls, attached per-call via machineHeaders() — never in headers(), so it cannot leak to off-domain requests (validateDomain).

Server-side: percy-api enforces charset/length limits and an https + CI-host allowlist on the URL, and treats all of it as advisory. Old CLI versions degrade gracefully (the feature falls back to non-machine-specific messaging).

Testing

  • @percy/env: 5 new specs (sanitized id, node-index suffix + run URL on circle, composed GitHub Actions run URL, null run URL fallback, debug-logging exclusion). Suite green (128/128).
  • @percy/client: header specs for snapshot + finalize, machine attributes on build create; existing exact-payload expectations updated. Suite green under node 14 except one pre-existing environmental failure (proxy getProxy should return undefined if no proxy is set) that also fails on a clean checkout on this machine (local proxy present) — unrelated to this change.

Post-Deploy Monitoring & Validation

  • What to monitor: percy-api warn logs "machine identity ingest skipped" (should stay ≈0); Redis key growth percy:api:build-machines:* (bounded by active builds, 25h TTL).
  • Validation: run a parallel build with this CLI against an org with the slow-build-diagnostics flag ON → build show JSON carries machine facts in diagnosis; kill one shard → machine named in the receiving-state alert.
  • Expected healthy behavior: zero change for orgs with the flag off; no additional CLI network calls (attributes/header ride existing requests).
  • Failure signal / rollback: any snapshot POST regression correlated with the header → revert this PR; the API ignores absent identity entirely.
  • Window & owner: first minor release post-merge, @shivanshusingh.

🤖 Generated with Claude Code

New env.machine getter (hostname-based id with CI node-index suffix,
per-provider run URL) sent as build-create attributes plus an
X-Percy-Machine-Id header on snapshot/finalize calls so percy-api can
track per-machine liveness on parallel builds and name the dead
machine when one stops sending.

The getter is excluded from env debug logging (those logs are uploaded
with build logs) and the header is attached per-call, never in
headers(), so it cannot reach off-domain requests. percy-api validates
everything server-side; old CLIs degrade gracefully.
@Shivanshu-07
Shivanshu-07 requested a review from a team as a code owner August 13, 2026 18:25
@percy/env enforces 100% line and branch coverage; the new machine
getter left the buildkite/gitlab cases, the hostname failure path and
the optional-var fallbacks uncovered.
@percy/client also enforces 100% branch coverage; the build-attribute
spread and machineHeaders() fallbacks (old CLI / no resolvable hostname)
were untested.
@Shivanshu-07

Copy link
Copy Markdown
Contributor Author

CI is green (30/30). For the record on the two reds seen along the way:

  • Test @percy/env and Test @percy/client were mine: both packages enforce 100% line and branch coverage via test:coverage (a different command from test, which is what I'd run locally), and the new machine getter left the buildkite/gitlab cases, the hostname-failure path, and the no-machine-identity fallbacks uncovered. Fixed in ee8b24d and 3c6ceff — both packages now report 100/100/100/100.
  • Test @percy/core (Windows leg only) failed on should retry by default on the snapshot discovery upto 3 times, which observed 2 retry log lines instead of 3. That is a timing assertion in packages/core; this PR touches only packages/env and packages/client, and the Linux core leg passed on the same commit. Re-ran the job and it passed, so it was flaky rather than related.

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