Skip to content

Forward precommit hook failures from "Create PR" to the agent#2968

Open
salihudickson wants to merge 2 commits into
PostHog:mainfrom
salihudickson:feat/precommit-hook-failure
Open

Forward precommit hook failures from "Create PR" to the agent#2968
salihudickson wants to merge 2 commits into
PostHog:mainfrom
salihudickson:feat/precommit-hook-failure

Conversation

@salihudickson

Copy link
Copy Markdown
Contributor

Problem

fixes #2736

Changes

  1. Added a dedicated agent prompt in the errorPromt.ts file, the gives the agent instructions on how to handle commit-hook failures
  2. Created CommitFailureActions.tsx, which renders copy error and fix with agent buttons on the relevant failed tool outputs.
  3. Wired the buttons into Execute tool output

How did you test this?

  1. Wrote tests to check the button visibility in the ui, to ensure the buttons render appropriately

Automatic notifications

  • Publish to changelog?
  • Alert Sales and Marketing teams?

@greptile-apps

greptile-apps Bot commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

Reviews (1): Last reviewed commit: "add functionality to forward pre-commit ..." | Re-trigger Greptile

Comment on lines +22 to +23
const PRE_COMMIT_COMMAND_REGEX =
/\blefthook\b[\s\S]*?\bpre-commit\b|\bpre-commit\b(?:[\s\S]*?\brun\b|\s+run\b|$)|\bhusky\b|\bovercommit\b|\blint-staged\b|[./]*\.(?:git\/hooks|husky)\/pre-commit\b/i;

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.

P1 Overly-broad hook-manager patterns trigger misleading agent context

\bhusky\b and \bovercommit\b match any command that contains those words — including setup/installation commands like husky install, npx husky add .husky/pre-commit, or overcommit --install. When one of those commands fails with a non-zero exit, showCommitFailureActions becomes true and the agent receives a prompt saying "A git commit command failed, most likely because a pre-commit hook rejected the commit" — which is factually wrong. The agent would be directed to diagnose a hook failure that never occurred, against the wrong command context entirely.

Consider narrowing these alternatives to require a hook-execution indicator, for example: \bhusky\b(?:\s+run\b|.*\bpre-commit\b) for husky and \bovercommit\b.*(?:--run\b|\bpre-commit\b) for overcommit. lint-staged is almost always a hook body rather than a setup command, so it is probably fine as-is.

Comment on lines +50 to +93
describe("ExecuteToolView", () => {
it("shows commit failure actions for a git commit failure with hook output", () => {
renderView(
makeToolCall({
status: "failed",
rawInput: { command: 'git commit -m "test"' },
content: textContent(`Exit code 1\n╭───╮\n│ hook: pre-commit │\n╰───╯`),
}),
);

const actions = screen.getByTestId("commit-failure-actions");
expect(actions).toHaveAttribute("data-command", 'git commit -m "test"');
expect(actions).toHaveAttribute(
"data-output",
expect.stringContaining("hook: pre-commit"),
);
});

it("still shows commit failure actions when the tool status is completed but the output has a non-zero exit signal", () => {
renderView(
makeToolCall({
status: "completed",
rawInput: { command: "pre-commit run --all-files" },
content: textContent("exit status 1\npre-commit failed"),
}),
);

expect(screen.getByTestId("commit-failure-actions")).toBeInTheDocument();
});

it("does not show commit failure actions for unrelated failed bash output", () => {
renderView(
makeToolCall({
status: "failed",
rawInput: { command: "git push origin main" },
content: textContent("exit status 1\nnetwork error"),
}),
);

expect(
screen.queryByTestId("commit-failure-actions"),
).not.toBeInTheDocument();
});
});

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.

P2 Tests should be parameterised

The three it blocks all exercise the same condition (whether CommitFailureActions is rendered) with different command/output/status combinations. Per project convention, tests like these should be collapsed into a single it.each table. The attribute assertions from the first test can live in a short standalone it if needed.

Context Used: Do not attempt to comment on incorrect alphabetica... (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@salihudickson

Copy link
Copy Markdown
Contributor Author

hey @charlesvien could you please take a look at this?

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.

Forward precommit hook failures from "Create PR" to the agent

1 participant