feat(action): make prepush hook non-blocking after one failure (#777)

* feat(action): make prepush hook non-blocking after one failure

push_branch now treats the repository's prepush hook as best-effort: it
runs at most once per run, surfaces the failure output if the script
exits non-zero, and every subsequent push_branch call this run skips
the hook so the agent isn't blocked by failures unrelated to its
change. The agent can iterate by running the hook command itself via
the shell tool when shell access is available; push_branch will not
re-run the hook automatically after a failure.

Why: a one-line OSS-allowlist change took 9 minutes (#776) because the
agent retried push_branch six times against a prepush hook that was
failing for env-leak and missing-build-artifact reasons unrelated to
the change. CI catches the same checks on the GitHub side; the local
prepush gate was duplicating work and blocking unrelated fixes.

- ToolState: new prepushFailureCount counter (per-run, never resets)
- executeLifecycleHook: returns structured failure (kind/output/exitCode)
  so prepush can compose its own agent-facing message instead of
  inheriting the generic retry/no-retry advice meant for setup
- push_branch: composes a shell-mode-aware error message; surfaces
  prepushSkipped on the success payload + appends a note to the message
- instructions.ts + wiki/prompt.md + docs/comparisons.mdx: updated to
  reflect best-effort semantics

* fix(action): clarify prepush latch semantics + soften static guidance

review fixes from PR #777:

- toolState comment, instructions, success message, tool description:
  replace "runs at most once per run" / "first call only" wording with
  the actual semantic — successful prepush keeps running on later
  push_branch calls; only a hook FAILURE latches the bypass.
- tool description: drop hardcoded "via the shell tool" guidance so
  the static description doesn't mislead in shell:disabled runs (the
  dynamic agent prompt in instructions.ts already does shell-conditional
  messaging).
- LifecycleHookFailure.output JSDoc: match the implementation
  (stderr-preferred fallback to stdout, empty for timeout/spawn).

* fix(action): shorten prepush-skip log to terse operator telemetry

the previous log line tried to address the agent ("re-run the hook
command yourself via shell"), but log.info writes to the action
runtime's stdout — the agent never sees it. agent-facing skip
guidance already lives in the error message from
buildPrepushFailureMessage, the success message when bypassed, and
the system prompt in instructions.ts. log line is now just operator
telemetry.

* refactor(action): drop slop from prepush soft-fail

self-audit pass after the previous review-fix round. removed
duplication between code-level comment and the five other places that
already explain the same behavior, tightened verbose JSDoc, and
collapsed redundant clauses in agent-facing strings.

- LifecycleHookFailure → discriminated union. drops the optional
  exitCode/spawnError fields (and the empty-output sentinel for
  timeout/spawn) plus the corresponding ?? fallbacks in the helper.
- PushBranchTool: 7-line code comment above the latch removed
  (toolState field comment + tool description + error message +
  success message + system prompt all already cover it). tool
  description third sentence dropped (restated the second). success
  message tightened to a parenthetical.
- buildPrepushFailureMessage: 4-line JSDoc → 1 line. shared "if you
  think the failure could indicate a real bug in your code" prefix
  factored out across the shell-conditional branches.
- ToolState.prepushFailureCount comment: 8 lines → 3. the "what" is
  in git.ts; comment now only documents the invariant (never
  decremented within a run).
- instructions.ts prepush guidance: collapsed nested bullets + ternary
  into one paragraph; dropped the "so re-running via shell is the only
  way…" tail that restated "push_branch will NOT re-run it".

* fix(action): hint prepush bypass on dirty tree after hook failure

When push_branch blocks on a dirty working tree and the prepush latch
is already set, tell the agent the hook will be skipped once the tree is clean.

* fix(test): narrow CI matrix for lifecycle and toolState changes

Remove lifecycle.ts from ALWAYS_RUN_ALL and add lifecycle.ts + toolState.ts
to push/git agnostic test coverage so PRs touching prepush latch logic run
targeted tests instead of the full matrix.
This commit is contained in:
Colin McDonnell
2026-05-20 02:43:23 +00:00
committed by pullfrog[bot]
parent 7e90e5cae6
commit cb0dbcd371
10 changed files with 99 additions and 29 deletions
+1 -1
View File
@@ -269,7 +269,7 @@ Rules:
- Never push commits directly to the default branch or any protected branch (commonly: main, master, production, develop, staging). Always create a feature branch following the pattern: \`pullfrog/<issue-number>-<kebab-case-description>\` (e.g., \`pullfrog/123-fix-login-bug\`).
- Never add co-author trailers (e.g., "Co-authored-by" or "Co-Authored-By") to commit messages.
- Untracked files from tests or tooling (e.g. \`coverage/\`) often remain *after* your last commit and still block \`${t("push_branch")}\` — delete them, extend \`.gitignore\`, or only add files that truly belong in the repo.
- \`${t("push_branch")}\` runs the repository's optional **prepush** hook before the network push. If the error includes \`lifecycle hook 'prepush' failed\` (with an exit code and script output after it), the hook script exited non-zero (commonly tests or lint). Fix that or change the hook — do not describe it as an infrastructure "timeout" unless the tool output or logs clearly show a timeout.
- \`${t("push_branch")}\` runs the repository's optional **prepush** hook (commonly tests or lint) — best-effort. On failure the output is returned, the hook is latched off, and every subsequent \`${t("push_branch")}\` call this run skips it. If the failure is unrelated to your changes (pre-existing breakage, env-dependent test, flaky check), just call \`${t("push_branch")}\` again. If it could be a real bug in your code, ${ctx.payload.shell === "disabled" ? `fix it from the failure output (shell is disabled, so you can't re-run the hook)` : `re-run the hook via the shell tool to iterate — \`${t("push_branch")}\` itself won't re-run it`}. Don't describe the failure as an infrastructure "timeout" unless the tool output clearly shows one.
- If push or PR creation fails, \`${t("report_progress")}\` must summarize using the **actual** error from the tool. Do not substitute vague causes unless they match what failed.
### GitHub
+21 -3
View File
@@ -12,22 +12,37 @@ export interface ExecuteLifecycleHookParams {
script: string | null;
}
/** structured failure info — `output` on the `exit` variant is trimmed
* stderr, falling back to stdout when stderr is empty. */
export type LifecycleHookFailure =
| { kind: "exit"; exitCode: number; output: string }
| { kind: "timeout" }
| { kind: "spawn"; spawnError: string };
export interface LifecycleHookResult {
/**
* human-readable warning when the hook failed. includes retry guidance:
* transient spawn/exit errors are worth retrying, timeouts and
* persistent failures are not. absent when the hook succeeded or was
* skipped.
* skipped. setup/post-checkout callers surface this verbatim; prepush
* builds its own message from `failure` instead.
*/
warning?: string;
/**
* structured failure info — undefined when the hook succeeded or was
* skipped. lets callers compose their own messaging without parsing the
* `warning` string.
*/
failure?: LifecycleHookFailure;
}
/**
* execute a lifecycle hook script if one is configured.
*
* soft-fails: instead of throwing on hook errors, returns a warning string
* so callers can choose whether to surface it (mcp tools) or upgrade it to
* a fatal error (setup/prepush). timeouts are flagged as non-retryable.
* (and structured failure info) so callers can choose whether to surface
* it (mcp tools) or upgrade it to a fatal error (setup). timeouts are
* flagged as non-retryable in the warning text.
*/
export async function executeLifecycleHook(
params: ExecuteLifecycleHookParams
@@ -50,6 +65,7 @@ export async function executeLifecycleHook(
if (result.exitCode !== 0) {
const output = (result.stderr || result.stdout).trim();
return {
failure: { kind: "exit", output, exitCode: result.exitCode },
warning:
`lifecycle hook '${params.event}' failed with exit code ${result.exitCode}. ` +
`output: ${output || "(empty)"}. ` +
@@ -67,6 +83,7 @@ export async function executeLifecycleHook(
if (isTimeout) {
const minutes = Math.round(LIFECYCLE_HOOK_TIMEOUT_MS / 60000);
return {
failure: { kind: "timeout" },
warning:
`lifecycle hook '${params.event}' timed out after ${minutes}min. ` +
`do NOT retry — the script is likely hung or doing too much work. ` +
@@ -75,6 +92,7 @@ export async function executeLifecycleHook(
}
const msg = err instanceof Error ? err.message : String(err);
return {
failure: { kind: "spawn", spawnError: msg },
warning:
`lifecycle hook '${params.event}' failed to spawn: ${msg}. ` +
`this is likely a transient failure — retry the operation.`,