Skip to content

feat: add state-fingerprint shared helper for unchanged-state skip - #1998

Merged
stranske merged 2 commits into
mainfrom
feat/state-fingerprint-helper
May 4, 2026
Merged

feat: add state-fingerprint shared helper for unchanged-state skip#1998
stranske merged 2 commits into
mainfrom
feat/state-fingerprint-helper

Conversation

@stranske

@stranske stranske commented May 4, 2026

Copy link
Copy Markdown
Owner

Source: Issue #1

Closes #1

Automated Status Summary

Scope

scripts/validate_fast.sh contains 12 TODO Phase 4 markers referencing Trend_Model_Project-specific features (SRC_FILES detection, autofix tests, coverage requirements) that are not applicable to this workflow repository. These dead code paths and stale references cause confusion and add maintenance burden.

Tasks

  • Remove all TODO Phase 4 markers and their associated dead/commented code blocks.
  • Remove SRC_FILES and AUTOFIX_FILES detection logic that references src/ directory patterns not present in this repo.
  • Update linting targets to use scripts/ and .github/ instead of src/ tests/.
  • Replace Python package-specific validation (coverage requirements, import tests) with workflow-specific checks (actionlint, YAML validation).
  • Ensure the script still runs successfully after cleanup.

Acceptance criteria

  • grep -c "TODO Phase" scripts/validate_fast.sh returns 0.
  • Script executes without errors: bash scripts/validate_fast.sh --help works.
  • No references to src/ directory or Trend_Model_Project-specific patterns remain.
  • Validation targets are appropriate for a workflow repository (scripts/, .github/).

Head SHA: 1b8a469
Latest Runs: ✅ success — Gate
Required: gate: ✅ success

Workflow / Job Result Logs
Gate ✅ success View run
Health 40 Sweep ✅ success View run
Health 44 Gate Branch Protection ✅ success View run
Health 45 Agents Guard ✅ success View run
Health 50 Security Scan ✅ success View run
Health 73 Template Completeness ✅ success View run
Maint 52 Validate Workflows ✅ success View run
PR 11 - Minimal invariant CI ✅ success View run
Selftest CI ✅ success View run
Validate Sync Manifest ✅ success View run

@stranske
stranske temporarily deployed to agent-standard May 4, 2026 16:54 — with GitHub Actions Inactive
@stranske-keepalive

stranske-keepalive Bot commented May 4, 2026

Copy link
Copy Markdown
Contributor

Automated Status Summary

Head SHA: 2b022a0
Latest Runs: ⏳ pending — Gate
Required contexts: Gate / gate, Health 45 Agents Guard / guard
Required: core tests (3.12): ⏳ pending, core tests (3.13): ⏳ pending, docker smoke: ⏳ pending, gate: ⏳ pending

Workflow / Job Result Logs
(no jobs reported) ⏳ pending

Coverage Overview

  • Coverage history entries: 1

Coverage Trend

Metric Value
Current 93.12%
Baseline 85.00%
Delta +8.12%
Minimum 70.00%
Status ✅ Pass

Top Coverage Hotspots (lowest coverage)

File Coverage Missing
src/cli_parser.py 81.8% 4
src/percentile_calculator.py 95.0% 1
src/aggregator.py 95.0% 2
src/__init__.py 100.0% 0
src/ndjson_parser.py 100.0% 0

Updated automatically; will refresh on subsequent CI/Docker completions.


Keepalive checklist

Scope

scripts/validate_fast.sh contains 12 TODO Phase 4 markers referencing Trend_Model_Project-specific features (SRC_FILES detection, autofix tests, coverage requirements) that are not applicable to this workflow repository. These dead code paths and stale references cause confusion and add maintenance burden.

Tasks

  • Remove all TODO Phase 4 markers and their associated dead/commented code blocks.
  • Remove SRC_FILES and AUTOFIX_FILES detection logic that references src/ directory patterns not present in this repo.
  • Update linting targets to use scripts/ and .github/ instead of src/ tests/.
  • Replace Python package-specific validation (coverage requirements, import tests) with workflow-specific checks (actionlint, YAML validation).
  • Ensure the script still runs successfully after cleanup.

Acceptance criteria

  • grep -c "TODO Phase" scripts/validate_fast.sh returns 0.
  • Script executes without errors: bash scripts/validate_fast.sh --help works.
  • No references to src/ directory or Trend_Model_Project-specific patterns remain.
  • Validation targets are appropriate for a workflow repository (scripts/, .github/).

@stranske
stranske temporarily deployed to agent-standard May 4, 2026 17:04 — with GitHub Actions Inactive
@stranske
stranske marked this pull request as ready for review May 4, 2026 19:49
Copilot AI review requested due to automatic review settings May 4, 2026 19:49
@stranske
stranske merged commit ac4b539 into main May 4, 2026
59 checks passed
@stranske
stranske deleted the feat/state-fingerprint-helper branch May 4, 2026 19:49
@stranske
stranske temporarily deployed to agent-standard May 4, 2026 19:49 — with GitHub Actions Inactive

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces a new shared Python helper (scripts/state_fingerprint.py) intended to compute/persist a small JSON “state fingerprint” and emit GitHub Actions outputs that enable unchanged-state skip gates. It also adds unit tests for the helper and registers the script in the consumer sync manifest.

Changes:

  • Add scripts/state_fingerprint.py CLI/library for computing, comparing, and storing workflow state fingerprints via PR comments or repo variables.
  • Add pytest coverage for core fingerprint/compare behavior plus the CLI “warning” mode output behavior.
  • Register the new script in .github/sync-manifest.yml under the scripts: section.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
scripts/state_fingerprint.py New helper script implementing fingerprint compute/compare + GitHub-backed storage backends and a compare CLI.
tests/scripts/test_state_fingerprint.py Adds tests for canonicalization, compare decisions, warning mode behavior, and malformed marker tolerance.
.github/sync-manifest.yml Adds the new helper to the scripts list so it can be distributed to consumer repos.

Comment on lines +2 to +8
"""Compute and persist workflow state fingerprints.

The helper gives workflows a cheap unchanged-state gate. Callers provide a
workflow name and a deliberately small JSON input surface; the script hashes the
canonical JSON representation, compares it with the prior stored value, and
emits GitHub Actions outputs that downstream steps can use for ``if:`` gates.
"""
Comment on lines +156 to +159

if not payload:
return None
return json.loads(payload)
Comment on lines +274 to +281
return int(os.environ["PR_NUMBER"])

event_path = os.environ.get("GITHUB_EVENT_PATH")
if not event_path:
raise RuntimeError("PR_NUMBER or GITHUB_EVENT_PATH is required for pr-comment storage")

with open(event_path, encoding="utf-8") as handle:
event = json.load(handle)
Comment thread .github/sync-manifest.yml
Comment on lines +210 to +212
- source: scripts/state_fingerprint.py
description: "Computes workflow state fingerprints for unchanged-state skip gates"

stranske added a commit that referenced this pull request May 5, 2026
…TECTION_TOKEN in health-44

Wave 1's state-fingerprint helper (#1998 + #2002 wireup) broke
Health 44 enforce because the workflow's GITHUB_TOKEN can't access
the actions/variables endpoint even with `actions: write` set —
that endpoint requires a token with Variables permission (PAT,
GitHub App, or fine-grained PAT).

Resulting failure observed on every PR running Health 44 enforce
since #2002 merged (incl. PR #2006, PR #2007 today):

  GET /repos/stranske/Workflows/actions/variables/STATE_FINGERPRINT_HEALTH_44_GATE_BRANCH_PROTECTION_*
  failed: 403 "Resource not accessible by integration"

Two-part fix:

1) `scripts/state_fingerprint.py` — `RepoVariableStorage` now treats
   401/403 from the variables API as "storage unavailable" rather
   than fatal. Read returns None (no prior fingerprint), write skips
   silently, and a warning goes to stderr so the operator sees the
   misconfiguration in workflow logs. The existing 404 (no prior)
   path is unchanged.

   Effect: any workflow that adopts `--storage repo-variable` but
   doesn't have the right token degrades gracefully (skips the
   optimization, runs anyway) instead of failing outright. Future
   Wave 1+ workflows using repo-variable storage benefit from this.

2) `.github/workflows/health-44-gate-branch-protection.yml` — uses
   `BRANCH_PROTECTION_TOKEN` (already used downstream by `enforce`)
   when present, falling back to `GITHUB_TOKEN`. Now the
   fingerprint optimization actually works when the secret is
   configured.

Existing 6 tests in tests/scripts/test_state_fingerprint.py still
pass. py_compile clean.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
stranske added a commit that referenced this pull request May 5, 2026
…back (#2010)

* fix(keepalive): handle no-checklist draft PRs with accurate disposition

Phase 6 sync-PR review surfaced two related bugs in
keepalive_orchestrator_gate_runner.js (Copilot review on stranske/*
sync PRs):

- routeDraftToHuman() emitted "0 unchecked checklist item(s)" when
  the PR had no checkboxes at all, suggesting the user just needed
  to check boxes that didn't exist.
- The branching at line 404 fell through to the same "needs human"
  path for both genuine missing-acceptance-items cases and PRs that
  legitimately have no checklist at all.

This change distinguishes the no-checklist case end-to-end:

- Adds a noChecklist flag in the caller (computed once where
  checkboxCounts is built).
- Threads noChecklist through routeDraftToHuman so the comment body
  and summary line accurately describe "no acceptance checklist
  found" vs "N unchecked items".
- Adds a distinct reason key 'pr-draft-no-checklist' so weekly
  metrics can distinguish the two cases.

Lockstep edit: canonical .github/scripts/ + templates/consumer-repo/
both updated identically. node --check passes on both.

Out of scope here: the perceived "missing closing brace" Copilot
flagged was already addressed by PR #1985 / #1986 on 2026-04-30 —
the GraphQL mutation block in markDraftReadyForReview() has the
correct three closing braces. The isConcreteAgentLabel() concern
about agent:rate-limited / agent:retry routing as concrete agent
labels is separate and needs broader review of the keepalive
loop's label-routing semantics; deferred.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* fix(state-fingerprint): graceful fallback on 401/403 + use BRANCH_PROTECTION_TOKEN in health-44

Wave 1's state-fingerprint helper (#1998 + #2002 wireup) broke
Health 44 enforce because the workflow's GITHUB_TOKEN can't access
the actions/variables endpoint even with `actions: write` set —
that endpoint requires a token with Variables permission (PAT,
GitHub App, or fine-grained PAT).

Resulting failure observed on every PR running Health 44 enforce
since #2002 merged (incl. PR #2006, PR #2007 today):

  GET /repos/stranske/Workflows/actions/variables/STATE_FINGERPRINT_HEALTH_44_GATE_BRANCH_PROTECTION_*
  failed: 403 "Resource not accessible by integration"

Two-part fix:

1) `scripts/state_fingerprint.py` — `RepoVariableStorage` now treats
   401/403 from the variables API as "storage unavailable" rather
   than fatal. Read returns None (no prior fingerprint), write skips
   silently, and a warning goes to stderr so the operator sees the
   misconfiguration in workflow logs. The existing 404 (no prior)
   path is unchanged.

   Effect: any workflow that adopts `--storage repo-variable` but
   doesn't have the right token degrades gracefully (skips the
   optimization, runs anyway) instead of failing outright. Future
   Wave 1+ workflows using repo-variable storage benefit from this.

2) `.github/workflows/health-44-gate-branch-protection.yml` — uses
   `BRANCH_PROTECTION_TOKEN` (already used downstream by `enforce`)
   when present, falling back to `GITHUB_TOKEN`. Now the
   fingerprint optimization actually works when the secret is
   configured.

Existing 6 tests in tests/scripts/test_state_fingerprint.py still
pass. py_compile clean.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* chore: apply Black formatting to state_fingerprint.py 401/403 fallback

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.

Clean up validate_fast.sh Phase 4 TODOs and remove project-specific references

2 participants