Repository navigation
fix(preflight): address #3580 review findings - #3594
Closed
Daniel Meppiel (danielmeppiel) wants to merge 1 commit into
Closed
Daniel Meppiel (danielmeppiel) wants to merge 1 commit into
Daniel Meppiel (danielmeppiel) wants to merge 1 commit into
Conversation
- launcher: check push / update-tool / gh publish patterns independently - gate: drop `git fetch` from the read-only chain allowlist - gate: deny implicit pushes under push.default=matching or remote.<name>.push (incl. -c, --config-env, GIT_CONFIG_* overrides) - gate: bind API PR creation to its requested head/base and ready operations to the PR's actual head/base (bounded gh lookup); deny when the target cannot be established - runner: SIGKILL the whole check process group after the grace period even when the leader already exited - runner: pin APM_BINARY_PATH to the project env's apm so lifecycle checks never exercise a stale dist/ build - tests: run the shared-checks test with --keep-going - README: document the above and activation per Copilot surface Fixes #3584 Co-authored-by: Copilot App <[email protected]>
Daniel Meppiel (danielmeppiel)
requested a review
from Sergio Sisternes (sergio-sisternes-epam)
as a code owner
November 12, 2026 11:21
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Critical target-validation gaps allow multi-mutation queries, unresolved or changed bases, and repository overrides to authorize publishing unverified targets using verification for a different target.
4 open issues
What changed in this PR
This follow-up to #3580 addresses #3584 by strengthening the repo-local preflight gate's commit checks and runner reliability.
Changes:
- Tightens publish detection, implicit-push checks, and PR head/base validation.
- Hardens process-group cancellation, pins the lifecycle-test binary, and adds regression coverage.
- Documents Copilot activation, updates deployed scripts, and refreshes lock hashes.
| File | Description |
|---|---|
packages/preflight-gate/tests/test_runner.py |
Tests binary pinning and removes a fail-fast race. |
packages/preflight-gate/tests/test_launcher.py |
Covers tool-name text masking PR creation. |
packages/preflight-gate/tests/test_gate.py |
Adds push-config, PR-target, and lookup-timeout coverage. |
packages/preflight-gate/tests/test_concurrency.py |
Tests cancellation of SIGTERM-resistant children. |
packages/preflight-gate/tests/test_chain.py |
Covers denial of fetch-before-publish chains. |
packages/preflight-gate/README.md |
Documents activation and updated gate limitations. |
packages/preflight-gate/.apm/hooks/scripts/preflight.py |
Strengthens cancellation and pins the project binary. |
packages/preflight-gate/.apm/hooks/scripts/gate.py |
Adds push-config checks and PR-target verification. |
packages/preflight-gate/.apm/hooks/scripts/gate-launcher.sh |
Checks publish patterns independently. |
apm.lock.yaml |
Refreshes package and deployed-script hashes. |
.github/hooks/scripts/preflight-gate/.apm/hooks/scripts/preflight.py |
Deploys the runner changes. |
.github/hooks/scripts/preflight-gate/.apm/hooks/scripts/gate.py |
Deploys the gate changes. |
.github/hooks/scripts/preflight-gate/.apm/hooks/scripts/gate-launcher.sh |
Deploys the launcher correction. |
Review effort: Balanced
| fields, opaque = _api_fields(api_args) | ||
| if path == "graphql": | ||
| query = fields.get("query") or " ".join(api_args) | ||
| found = set(GRAPHQL_PR_MUTATION.findall(" ".join(api_args))) |
Comment on lines
+665
to
+667
| if head is None: | ||
| action.deny = "cannot establish the head of the GraphQL createPullRequest" | ||
| action.fix = FIX_PR_CREATE_TARGET |
| argv += ["--json", "headRefOid,baseRefName"] | ||
| if target.repo: | ||
| argv += ["-R", target.repo] | ||
| env = dict(os.environ, GH_PROMPT_DISABLED="1", GH_NO_UPDATE_NOTIFIER="1", NO_COLOR="1") |
| f"commit {verified[:12]}" | ||
| ) | ||
| return why, (FIX_PR_PUSH_FIRST if current == verified else None) | ||
| return _base_problem(str(info["baseRefName"]), receipt, hint) |
Collaborator
Author
|
Closing: the preflight-gate hook from #3580 was reverted in #3598, and its local-preflight approach is dropped for now (Daniel Meppiel (@danielmeppiel), 2026-11-12). These review fixes no longer apply. Posted with AI assistance on behalf of Daniel Meppiel (@danielmeppiel). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

TL;DR
Fixes the 7 Copilot review findings left open on merged #3580 (the repo-local
preflight-gatepackage). Four close gate bypasses (launcher fast path,git fetchchaining, implicit pushes under push config, API PR create/ready not bound to the real head). Two harden the runner (resistant child processes, staledist/binary). One de-flakes a test. The README also gets a short "Activation by Copilot surface" section.Fixes #3584
Problem (WHY)
dist/build.Review thread → fix → regression test
update_pull_requestin a PR title masksgh pr creategate-launcher.shchecks the push, update-tool andghpatterns in three separatecaseblocks, so one match cannot hide anothertest_launcher.py::test_gh_pr_create_mentioning_update_tool_name_starts_pythongit fetch x:x && git push xfetchremoved fromREAD_ONLY_GIT; chain tests and README allowlist updatedtest_chain.py::test_fetch_moving_branch_before_push_is_denied(+ 2 new rows intest_mutating_segment_before_publish_is_denied)push.default=matching/remote.<name>.pushpush.defaultismatchingor anyremote.*.pushis set. The check readsgit -coverrides and two localgit configcalls (no network).--config-envandGIT_CONFIG_*assignments on the command deny an implicit push outright. An explicit refspec is unaffectedtest_gate.py::test_implicit_push_with_push_default_matching_is_denied,test_gate.py::test_implicit_push_with_remote_push_refspecs_is_deniedheadunsetgh apiPOSTpulls, GraphQLcreatePullRequestincl.$variables): keeps the requestedhead/base. The head must resolve to a branch whose commit equalsreceipt.head(local branch first, thenorigin/<branch>, as forgh pr create -H), and the base must equal the receipt base. A missing or--inputhead is denied. Ready (gh pr ready [n|url] [-R],gh apiPATCHpulls/N,markPullRequestReadyForReview,*update_pull_request):gh pr view … --json headRefOid,baseRefName(or a GraphQLnodelookup) reads the PR's actual head and base, capped at 8 s with the process group killed on timeout. The command is denied when no PR can be found, on timeout, or when the tool call has no PR numbertest_gate.py::test_api_pr_creation_binds_requested_head_and_base,::test_ready_operations_bind_the_prs_actual_head,::test_default_pr_lookup_asks_gh_for_the_pr_head,::test_pr_lookup_timeout_denies_within_hook_budgetproc.wait()skips SIGKILL_kill_group: sends SIGTERM, then polls the leader and the group for the grace period, then always sends SIGKILL to the grouptest_concurrency.py::test_cancel_kills_child_that_ignores_sigtermdist/overPATHtests/integration/conftest.py::_resolve_apm_binarychecksAPM_BINARY_PATHfirst, thendist/, thenPATH. The runner now pinsAPM_BINARY_PATH=<project env>/bin/apmin every check environmenttest_runner.py::test_lifecycle_checks_pin_project_apm_over_stale_dist--keep-goingtest_runner.py::test_failure_still_runs_shared_checks_of_every_tier(updated)Tests 5 and 6 were run against the pre-fix
preflight.pyand both fail there; both pass with the fix.How verification now binds each gated action
Legend: what the gate compares against the receipt once the receipt itself is fresh, green and complete.
flowchart TD A["gated action, fresh green receipt"] --> B{"kind"} B -->|"git push, no refspec"| C{"push.default=matching<br/>or remote.*.push set?"} C -->|yes| X["deny: name the source"] C -->|no| H["HEAD == receipt.head?"] B -->|"PR create: gh pr create, gh api POST pulls,<br/>GraphQL createPullRequest, *create_pull_request"| R["requested head branch -> commit<br/>== receipt.head, base == receipt base"] B -->|"PR ready: gh pr ready, gh api PATCH pulls/N,<br/>markPullRequestReadyForReview, *update_pull_request"| L["gh lookup of the PR (8 s cap)"] L -->|"unknown / timeout"| X2["deny: PR cannot be established"] L -->|"headRefOid, baseRefName"| P["PR head == receipt.head,<br/>PR base == receipt base"]Implementation (HOW)
packages/preflight-gate/.apm/hooks/scripts/gate-launcher.shcaseblocks (finding 1).packages/preflight-gate/.apm/hooks/scripts/gate.pyREAD_ONLY_GITwithoutfetch.git -c/--config-envcollection andAction.implicit, checked by_implicit_push_problem._gh_api_actions/_api_fields/_graphql_argkeep the API head and base.PRTarget+lookup_pr, injectable asGateConfig.pr_lookup, power_verify_existing_pr._resolve_head_argresolvesrefs/heads/<b>, thenrefs/remotes/origin/<b>, and no longer accepts arbitrary revs.packages/preflight-gate/.apm/hooks/scripts/preflight.py_kill_group+_group_alive(finding 5);APM_BINARY_PATHpin (finding 6).packages/preflight-gate/README.mdfetch, new Limits bullets (implicit push, API create, ready lookup) replacing "gh pr readydoes not verify the PR base", and Activation by Copilot surface: Copilot CLI and cloud agent load repo.github/hooks. The desktop app needs a one-file user-level shim (~/.copilot/hooks/apm-preflight-gate-shim.json) that runs the repo's own launcher only inside repos that have the package. Hooks are read at session start.packages/preflight-gate/tests/*gh pr readyin the existing allow test now uses a fake lookup..github/hooks/scripts/preflight-gate/…apm.lock.yamlsha256lines for the 3 deployed scripts and the./packages/preflight-gatecontent_hash. Noapm installchurn.Trade-offs
matching/remote.*.pushmeans re-implementing git's refspec and upstream rules in the hook. Denying and telling the agent to rungit push origin HEADis exact and costs at most 2 localgit configcalls. Anyremote.*.pushtriggers the deny, not just the target remote's (slightly broader than necessary, and rare).gh pr readyalso looks up the current-branch PR, because local HEAD can be ahead of the PR head.*update_pull_requestwithout a PR number is denied rather than guessed from the current branch.origin/<branch>when no local branch exists, asgh pr create -Halready did. The commit equality check is unchanged.Benefits
dist/build. The new test fails on the old code.Validation
Commands and results
.venv/bin/pytest packages/preflight-gate/tests -q -p no:xdist→364 passed, 2 failedin one full run under host load avg ~100-260 on 8 cores:test_phase_a_failure_cancels_siblings_and_skips_phase_b(wall-clock< 20s bound hit 28 s; it also failed the same way on unmodifiedmainin this session) andtest_cancellation_kills_the_whole_process_group(pidfile not yet written before the cancel). Re-runningtests/test_concurrency.py→14 passed.venv/bin/ruff check packages/preflight-gate && .venv/bin/ruff format --check packages/preflight-gate→All checks passed!/15 files already formattedpreflight.pyswapped back toHEAD~, thenpytest …::test_cancel_kills_child_that_ignores_sigterm …::test_lifecycle_checks_pin_project_apm_over_stale_dist→2 failed; with the fix → pass.venv/bin/pytest tests/unit/test_triage_advisory.py::test_local_package_snapshots_match_lockfile -q→1 passed.venv/bin/apm audit --ci→[*] All 10 check(s) passedcmpof every file inpackages/preflight-gate/.apm/hooks/scripts/vs.github/hooks/scripts/preflight-gate/.apm/hooks/scripts/→ identicalDogfood (deployed runner at the PR head, from the repo root):
Scenario evidence
test_gh_pr_create_mentioning_update_tool_name_starts_pythonfetchand publish it in the same calltest_fetch_moving_branch_before_push_is_deniedtest_implicit_push_with_push_default_matching_is_denied,test_implicit_push_with_remote_push_refspecs_is_deniedtest_api_pr_creation_binds_requested_head_and_base,test_ready_operations_bind_the_prs_actual_head,test_default_pr_lookup_asks_gh_for_the_pr_head,test_pr_lookup_timeout_denies_within_hook_budgettest_cancel_kills_child_that_ignores_sigtermtest_lifecycle_checks_pin_project_apm_over_stale_distHow to test
.venv/bin/pytest packages/preflight-gate/tests -q -p no:xdist(the package's session cleanup is not xdist-safe)git -c push.default=matching pushwith a fresh receipt → deny naminggit push origin HEADgh pr ready <n>for a PR whose head is not the verified commit → deny with the PR head shapython3 .github/hooks/scripts/preflight-gate/.apm/hooks/scripts/preflight.py→ PASSDescription
Follow-up to #3580 that fixes its 7 unresolved Copilot review findings (see the table above), plus a README activation section.
Issue and approved scope
Issue: Fixes #3584
Human scope-approval comment: maintainer request on #3580, "if those are legit, fix them" (recorded in #3584; human direction and review contact Daniel Meppiel (@danielmeppiel)). All 7 findings were triaged as legitimate.
Does this PR complete the issue, or what remains? It completes #3584.
Type of change
Testing
Spec conformance (OpenAPM v0.1)
CONFORMANCE.{md,json}regenerated