fix(git): rejected commit hooks no longer swallow the reason and the message #7706
ClosedDraftProducts(GitHub profile, opens in a new tab)wants to merge 14 commits into
main fromrefs/pull/7706/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- apps/web/src/components/GitActionsControl.tsx lines 1637 to 1641OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -1623,14 +1626,16 @@16231626 };162416271625- const runDialogAction = () => {1628+ const runDialogAction = async () => {16261629 if (!isCommitDialogOpen) return;16271630 const commitMessage = dialogCommitMessage.trim();16281631 setIsCommitDialogOpen(false);1629- setDialogCommitMessage("");1630- setExcludedFiles(new Set());1631- setIsEditingFiles(false);1632- void runGitActionWithToast({1632+ const committed = await runGitActionWithToast({16331633 action: "commit",16341634 ...(commitMessage ? { commitMessage } : {}),16351635 ...(!allSelected ? { filePaths: selectedFiles.map((f) => f.path) } : {}),16361636 });1637+ if (committed) {1638+ setDialogCommitMessage("");1639+ setExcludedFiles(new Set());1640+ setIsEditingFiles(false);1641+ }
- apps/server/src/git/GitManager.ts line 2072Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -1656,7 +1660,13 @@16561660 },16571661 }16581662 : null;1659- const { commitSha } = yield* gitCore.commit(cwd, suggestion.subject, suggestion.body, {1660- timeoutMs: COMMIT_TIMEOUT_MS,1661- ...(commitProgress ? { progress: commitProgress } : {}),1662- });1663+ const { commitSha } = yield* gitCore1664+ .commit(cwd, suggestion.subject, suggestion.body, {1665+ timeoutMs: COMMIT_TIMEOUT_MS,1666+ ...(commitProgress ? { progress: commitProgress } : {}),1667+ })1668+ .pipe(1669+ // The driver error only says "exited with a non-zero status" and carries no output, so a1670+ // hook rejection is indistinguishable from a broken repository without naming the hook.1671+ Effect.mapError((error) => {1672+ const hook = failedHook;apps/mobile/src/features/threads/git/GitCommitSheet.tsx line 51OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -40,5 +48,4 @@4048 const isDefaultRef = gitStatus.data?.isDefaultRef ?? false;4149 const allFiles = gitStatus.data?.workingTree?.files ?? [];425043- const [dialogCommitMessage, setDialogCommitMessage] = useState("");44- const [excludedFiles, setExcludedFiles] = useState<ReadonlySet<string>>(new Set());51+ const draft = pendingCommitDraft?.cwd === selectedThreadCwd ? pendingCommitDraft : null;
- apps/web/src/components/GitActionsControl.tsx line 1641OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -1623,14 +1626,16 @@16231626 };162416271625- const runDialogAction = () => {1628+ const runDialogAction = async () => {16261629 if (!isCommitDialogOpen) return;16271630 const commitMessage = dialogCommitMessage.trim();16281631 setIsCommitDialogOpen(false);1629- setDialogCommitMessage("");1630- setExcludedFiles(new Set());1631- setIsEditingFiles(false);1632- void runGitActionWithToast({1632+ const committed = await runGitActionWithToast({16331633 action: "commit",16341634 ...(commitMessage ? { commitMessage } : {}),16351635 ...(!allSelected ? { filePaths: selectedFiles.map((f) => f.path) } : {}),16361636 });1637+ if (committed) {1638+ setDialogCommitMessage("");1639+ setExcludedFiles(new Set());1640+ setIsEditingFiles(false);1641+ }
- apps/mobile/src/features/threads/git/GitCommitSheet.tsx line 62Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -40,5 +53,5 @@4053 const isDefaultRef = gitStatus.data?.isDefaultRef ?? false;4154 const allFiles = gitStatus.data?.workingTree?.files ?? [];425543- const [dialogCommitMessage, setDialogCommitMessage] = useState("");44- const [excludedFiles, setExcludedFiles] = useState<ReadonlySet<string>>(new Set());56+ const draftKey = commitDraftKey(selectedThread?.environmentId ?? null, selectedThreadCwd);57+ const draft =
- apps/server/src/git/GitManager.ts lines 2076 to 2081Resolvedby DraftProducts(GitHub profile, opens in a new tab)@@ -1657,6 +1665,16 @@1665+ progress: commitProgress,1666+ })1667+ .pipe(1668+ // The driver error only says "exited with a non-zero status" and carries no output, so a1669+ // hook rejection is indistinguishable from a broken repository without naming the hook.1670+ Effect.mapError((error) => {1671+ const hook = failedHook;1672+ if (hook === null) {1673+ return error;16571674 }1658- : null;1659- const { commitSha } = yield* gitCore.commit(cwd, suggestion.subject, suggestion.body, {1660- timeoutMs: COMMIT_TIMEOUT_MS,1661- ...(commitProgress ? { progress: commitProgress } : {}),1662- });1675+ return new GitManagerError({1676+ operation: "runCommitStep",1677+ cwd,1678+ detail: `The ${hook.hookName} hook rejected the commit (exit code ${hook.exitCode}).`,1679+ cause: error,1680+ });
- apps/web/src/components/GitActionsControl.tsx line 1647Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -1617,6 +1637,8 @@16171637 void runGitActionWithToast({ action: "create_pr" });16181638 return;16191639 }1620- setExcludedFiles(new Set());1621- setIsEditingFiles(false);1622- setIsCommitDialogOpen(true);1640+ if (!hasFailedCommitDraft) {1641+ setExcludedFiles(new Set());1642+ setIsEditingFiles(false);1643+ }1644+ setCommitDialogOpen(true);
- apps/web/src/components/GitActionsControl.tsx lines 1013 to 1023OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -1007,3 +1007,17 @@10071007 });10081008 const setDraftThreadContext = useComposerDraftStore((store) => store.setDraftThreadContext);10091009 const [isCommitDialogOpen, setIsCommitDialogOpen] = useState(false);1010+ // Mirrors isCommitDialogOpen so a commit that resolves after the user reopened the dialog can1011+ // tell "nothing to preserve" from "the user is already typing a new draft".1012+ const commitDialogOpenRef = useRef(false);1013+ const [hasFailedCommitDraft, setHasFailedCommitDraft] = useState(false);1014+ const setCommitDialogOpen = (open: boolean) => {1015+ commitDialogOpenRef.current = open;1016+ setIsCommitDialogOpen(open);1017+ };1018+ const discardCommitDraft = () => {1019+ setDialogCommitMessage("");1020+ setExcludedFiles(new Set());1021+ setIsEditingFiles(false);1022+ setHasFailedCommitDraft(false);1023+ };
- apps/web/src/components/GitActionsControl.tsx line 1655OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -1617,6 +1649,7 @@16171649 void runGitActionWithToast({ action: "create_pr" });16181650 return;16191651 }1620- setExcludedFiles(new Set());1621- setIsEditingFiles(false);1622- setIsCommitDialogOpen(true);1652+ if (!hasFailedCommitDraft) {1653+ setExcludedFiles(new Set());1654+ setIsEditingFiles(false);1655+ }
- apps/server/src/git/GitManager.ts line 2066Resolvedby DraftProducts(GitHub profile, opens in a new tab)@@ -1758,0 +1747,21 @@1747+ exitCode: number | null;1748+ durationMs: number | null;1749+ }) => {1750+ if (currentHookName === hookName) {1751+ currentHookName = null;1752+ }1753+ if (exitCode !== null && exitCode !== 0) {1754+ failedHook = { hookName, exitCode };1755+ }1756+ return emit({1757+ kind: "hook_finished",1758+ hookName,1759+ exitCode,1760+ durationMs,1761+ });1762+ },1763+ };1764+ const { commitSha } = yield* gitCore1765+ .commit(cwd, suggestion.subject, suggestion.body, {1766+ timeoutMs: COMMIT_TIMEOUT_MS,1767+ progress: commitProgress,
juliusmarminge added labelsmacroscope-review
- apps/mobile/src/features/threads/git/GitCommitSheet.tsx line 113Resolvedby DraftProducts(GitHub profile, opens in a new tab)@@ -57,11 +93,19 @@57935894 const runCommitAction = useCallback(5995 async (featureBranch: boolean) => {96+ isSubmittingRef.current = true;6097 const commitMessage = dialogCommitMessage.trim();98+ const submitted =99+ draftKey === null ? null : { key: draftKey, message: commitMessage, excludedFiles };100+ if (submitted) {101+ pendingCommitDraft = submitted;102+ }61103 navigation.goBack();62- await gitActions.onRunSelectedThreadGitAction({104+ const result = await gitActions.onRunSelectedThreadGitAction({63105 action: "commit",64106 featureBranch,65107 ...(commitMessage ? { commitMessage } : {}),66108 ...(!allSelected ? { filePaths: selectedFiles.map((file) => file.path) } : {}),67109 });110+ // Identity check: a concurrent commit elsewhere may already own the stored draft.111+ if (result !== null && pendingCommitDraft === submitted) {apps/server/src/vcs/GitVcsDriverCore.ts line 717Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -633,3 +645,4 @@633645 }634646635647 if (event === "child_exit") {648+ if (!started) {
- apps/mobile/src/features/threads/git/GitCommitSheet.tsx lines 62 to 63Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -44,5 +57,6 @@4457 const isDefaultRef = gitStatus.data?.isDefaultRef ?? false;4558 const allFiles = gitStatus.data?.workingTree?.files ?? [];465947- const [dialogCommitMessage, setDialogCommitMessage] = useState("");48- const [excludedFiles, setExcludedFiles] = useState<ReadonlySet<string>>(new Set());60+ const draftKey = commitDraftKey(selectedThread?.environmentId ?? null, selectedThreadCwd);61+ const draft =62+ draftKey !== null && pendingCommitDraft?.key === draftKey ? pendingCommitDraft : null;apps/mobile/src/features/threads/git/GitCommitSheet.tsx lines 64 to 66Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -44,5 +57,9 @@4457 const isDefaultRef = gitStatus.data?.isDefaultRef ?? false;4558 const allFiles = gitStatus.data?.workingTree?.files ?? [];465947- const [dialogCommitMessage, setDialogCommitMessage] = useState("");48- const [excludedFiles, setExcludedFiles] = useState<ReadonlySet<string>>(new Set());60+ const draftKey = commitDraftKey(selectedThread?.environmentId ?? null, selectedThreadCwd);61+ const draft =62+ draftKey !== null && pendingCommitDraft?.key === draftKey ? pendingCommitDraft : null;63+ const [dialogCommitMessage, setDialogCommitMessage] = useState(draft?.message ?? "");64+ const [excludedFiles, setExcludedFiles] = useState<ReadonlySet<string>>(65+ draft?.excludedFiles ?? new Set(),apps/server/src/vcs/GitVcsDriverCore.ts line 717Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -633,3 +645,4 @@633645 }634646635647 if (event === "child_exit") {648+ if (!started) {apps/web/src/components/GitActionsControl.tsx lines 1618 to 1619OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -1575,12 +1605,15 @@1575- const runDialogAction = () => {1605+ const runDialogAction = async () => {15761606 if (!isCommitDialogOpen) return;15771607 const commitMessage = dialogCommitMessage.trim();1578- setIsCommitDialogOpen(false);1579- setDialogCommitMessage("");1580- setExcludedFiles(new Set());1581- setIsEditingFiles(false);1582- void runGitActionWithToast({1608+ setCommitDialogOpen(false);1609+ const committed = await runGitActionWithToast({15831610 action: "commit",15841611 ...(commitMessage ? { commitMessage } : {}),15851612 ...(!allSelected ? { filePaths: selectedFiles.map((f) => f.path) } : {}),15861613 });1614+ // A failed commit keeps the draft so reopening the dialog restores it.1615+ if (!committed) {1616+ return;1617+ }1618+ if (!commitDialogOpenRef.current) {1619+ discardCommitDraft();
- apps/web/src/components/GitActionsControl.tsx line 1660Resolvedby DraftProducts(GitHub profile, opens in a new tab)@@ -1573,14 +1611,15 @@1611+ // wipe the file selection a rejected hook is about to hand back.1612+ setCommitDialogOpen(true);15731613 };157416141575- const runDialogAction = () => {1615+ const runDialogAction = async () => {15761616 if (!isCommitDialogOpen) return;15771617 const commitMessage = dialogCommitMessage.trim();1578- setIsCommitDialogOpen(false);1579- setDialogCommitMessage("");1580- setExcludedFiles(new Set());1581- setIsEditingFiles(false);1582- void runGitActionWithToast({1618+ const submittedScope = sourceControlScope;1619+ setCommitDialogOpen(false);1620+ const committed = await runGitActionWithToast({15831621 action: "commit",15841622 ...(commitMessage ? { commitMessage } : {}),15851623 ...(!allSelected ? { filePaths: selectedFiles.map((f) => f.path) } : {}),15861624 });1625+ discardCommitDraftAfterCommit(committed, submittedScope);
- apps/mobile/src/state/use-selected-thread-git-actions.ts lines 418 to 428Resolvedby DraftProducts(GitHub profile, opens in a new tab)@@ -355,4 +355,14 @@355355 },356356 });357357 if (AsyncResult.isFailure(syncResult)) {358- return AsyncResult.failure(syncResult.cause);358+ // The action itself landed, so reporting a failure here would hand the commit359+ // sheet its draft back and invite a duplicate commit.360+ const error = Cause.squash(syncResult.cause);361+ const message =362+ error instanceof Error ? error.message : "Failed to update the thread.";363+ setPendingConnectionError(message);364+ showGitActionResult({365+ type: "error",366+ title: "Thread branch not updated",367+ description: message,368+ });
- apps/mobile/src/state/use-selected-thread-git-actions.ts line 430Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -410,4 +410,20 @@410410 });411411 if (AsyncResult.isFailure(syncResult)) {412- return AsyncResult.failure(syncResult.cause);412+ // The action itself landed, so reporting a failure here would hand the commit413+ // sheet its draft back and invite a duplicate commit.414+ const error = Cause.squash(syncResult.cause);415+ const message =416+ error instanceof Error ? error.message : "Failed to update the thread.";417+ setPendingConnectionError(message);418+ showGitActionResult({419+ type: "error",420+ title: "Thread branch not updated",421+ description: message,422+ // Single notification slot: this replaces the success one, so a PR the action423+ // just opened would otherwise lose its only link.424+ prUrl:425+ result.value.toast.cta.kind === "open_pr"426+ ? result.value.toast.cta.url427+ : undefined,428+ });413429 }
maria-rcks closed this
Sign in to join this conversation.




Important
Review skipped#
We couldn't safely recover the incremental review. No full review was started, and the last reviewed checkpoint was preserved. Retry later, or explicitly request a full review by commenting
@coderabbitai full review.You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
112ff848-b83d-401a-91d4-73439da19427📥 Commits
Reviewing files that changed from the base of the PR and between a1a23ef8bd3b1eff76568a332f8f572839b28663 and 1de0407b42dbf1016fc192305c32c8f6a5995e7c.
📒 Files selected for processing (2)
apps/server/src/git/GitManager.test.tsapps/server/src/git/GitManager.tsIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.
📝 Walkthrough
Walkthrough#
Mobile and web commit dialogs retain or discard drafts at defined points. Server Git handling reports hook names and exit codes, and Trace2 setup failures no longer prevent Git commands. Mobile thread actions retain a successful action result when branch-state synchronization fails.
Changes#
Commit workflows
apps/mobile/src/features/threads/git/GitCommitSheet.tsx,apps/web/src/components/GitActionsControl.tsxapps/server/src/vcs/GitVcsDriverCore.ts,apps/server/src/vcs/GitVcsDriverCore.test.tscodefield for the exit status. Tests cover trace-file creation failure.apps/server/src/git/GitManager.ts,apps/server/src/git/GitManager.test.tsGitManagersupplies hook progress callbacks even without a progress reporter. It reports an error naming the failed hook and exit code when a hook exits with a nonzero status. Tests cover failures with and without progress reporting, including a nested Git command.Thread branch synchronization
apps/mobile/src/state/use-selected-thread-git-actions.tsPriority: ⬇️ Low
Estimated code review effort: 3 (Moderate) | ~25 minutes
Change: Bug fix
Sequence Diagram(s)#
Suggested reviewers:
juliusmarmingeMerge Risk
Merge Risk: 🔵 Low · up to
1de04A failed commit’s message and excluded-file selection can reappear after switching away from a repository and returning. This is a bounded draft-lifecycle issue to address or explicitly accept before merging.
Security Architecture Review
Security architecture risk: 🔵 Low · up to
1de04The failure-handling changes do not appear to expand execution permissions. However, mobile commit drafts can outlive environment removal or account cleanup and reappear when the same environment and repository are reopened. This is a limited local-data lifecycle risk, not an established remote access vulnerability.
Retained concerns
Security review details
Security Blast Radius
Security Findings and Attack Paths
Trust Boundaries and Controls
Resilience and Maintainability Implications
Hardening Proposals
🚥 Pre-merge checks | ✅ 3 | ❌ 2
❌ Failed checks (2 warnings)#
✅ Passed checks (3 passed)
Full details: Description check
Explanation
The description explains the problem, the fix, and validation. It also includes before-and-after screenshots. However, it does not provide the required scope and approval information: there is no link to a triaged issue or maintainer approval, and no explanation of why this cross-component behavior change qualifies for an exemption.
✨ Finishing Touches
🧪 Generate unit tests (beta)
Comment `@coderabbitai help` to get the list of available commands.