Fix commit message loading fallback#360
Conversation
🎨 Storybook previewUpdated for 6689d2b |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2b718cc40a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "Codex (@codex) review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "Codex (@codex) address that feedback".
| store.setCommitMessageSuggestion(null); | ||
| store.setEvolvePrompt(""); | ||
| resetCommitMessageDraft(); |
There was a problem hiding this comment.
Preserve the draft when commit fails
When tauriAPI.git.commit fails (for example a hook rejects the commit or git returns an error), handleCommit catches the exception and only records the error in use-git-operations.ts, so the await handleCommit({ message }) here still resolves. These reset calls therefore run on failed commits too, clearing the user's edited subject/body and stored suggestion while they remain on the commit step and need to retry.
Useful? React with 👍 / 👎.
📋 PR Overview
🔬 Coverage
|
2b718cc to
e26f997
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e26f9975af
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "Codex (@codex) review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "Codex (@codex) address that feedback".
| if (statusRef.current !== "loading") { | ||
| return; | ||
| } |
There was a problem hiding this comment.
Reset stale suggestions when lookup goes pending
When the Save/Commit step already has a generated suggestion and the underlying changeMap changes to a state whose backend lookup returns pending (for example, the user edits files after the suggestion was generated and no generated_commit_message exists for the new hashes yet), this branch exits because statusRef is still "ready". The old subject/body remain enabled and can be committed for a different set of changes instead of showing loading/fallback for the new map; useSummary.generateCommitMessage now returns pending on a null backend result, so this is the path for a missing current suggestion.
Useful? React with 👍 / 👎.
e26f997 to
267b4f5
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 267b4f5f8d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "Codex (@codex) review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "Codex (@codex) address that feedback".
| const suggestionFingerprintRef = useRef<string | null>( | ||
| commitMessageSuggestion ? changeMapFingerprintRef.current : null, | ||
| ); |
There was a problem hiding this comment.
Revalidate stored suggestions on remount
When MergeSection remounts with a non-null commitMessageSuggestion, this initializes the suggestion fingerprint to the current change map even though the store value may have been generated for an earlier map. CommitStep/ManualCommitStep unmount this component when the user clicks “Continue editing”, so if files/changeMap change while editing and the user clicks “Back to commit”, the stale global suggestion is treated as ready for the new fingerprint; if the backend lookup is pending, the statusRef.current !== "loading" path keeps the old subject/body indefinitely and enables committing it for the new changes. The suggestion needs to be cleared or revalidated on mount instead of assuming it matches the current map.
Useful? React with 👍 / 👎.
499e0ac to
9e2fc09
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9e2fc09a9a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "Codex (@codex) review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "Codex (@codex) address that feedback".
| .getState() | ||
| .setCommitMessageSuggestion(result.message); | ||
| setCommitMessageStatus("ready"); | ||
| setCommitBody(parsed.body); |
There was a problem hiding this comment.
Preserve manual one-line commits when suggestions arrive
If the user types their own subject while the lookup is still pending, a later generated suggestion does not overwrite that subject but this still unconditionally stores the generated body. Because the body is not editable, submitting after that point sends custom subject\n\n<generated body> even though the user only authored a one-line message, which can produce mismatched or unintended commit messages in the late-ready path.
Useful? React with 👍 / 👎.
9e2fc09 to
e9bcc4f
Compare
…-message # Conflicts: # apps/native/src-tauri/src/evolve/edit_nix_file.rs # apps/native/src-tauri/src/evolve/tools.rs # apps/native/src-tauri/src/evolve/tools/edit_nix_file.rs # apps/native/src-tauri/src/state/mod.rs
…-message # Conflicts: # apps/native/scripts/run-storybook-tests-ci.mjs # apps/native/src-tauri/src/evolve/tools/edit_nix_file.rs
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0bb8fbfeb0
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "Codex (@codex) review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "Codex (@codex) address that feedback".
| staleTimer = setTimeout(() => { | ||
| showFallback("fallback"); | ||
| }, STALE_COMMIT_MESSAGE_MS); |
There was a problem hiding this comment.
Cancel stale fallback timers when suggestions arrive
When generateCommitMessage() returns pending, this schedules an 8-second fallback that is not cancelled if commitMessageSuggestion is populated before the timeout fires. In that case the second effect accepts the real suggestion and marks the draft ready, but this timer still calls showFallback("fallback") later and overwrites the generated subject/body with the fallback text for the same change map. Guard the timeout against a non-loading status or clear it when a suggestion is accepted.
Useful? React with 👍 / 👎.
Juanpe Bolívar (arximboldi)
left a comment
There was a problem hiding this comment.
As mentioned in the inner comment, this is too complex, I can't even understand what the expected behavior is from looking at the code, even less the correctness of the implementation. I suspect there is a problem of design (missing rationalization of the expected behavior) and in any case the implementation should be refactored and simplified to make it intelligible and to properly represent such specification.
| import { useEffect } from "react"; | ||
| import { useEffect, useRef, useState } from "react"; | ||
|
|
||
| const STALE_COMMIT_MESSAGE_MS = 8_000; |
There was a problem hiding this comment.
What's this? This needs a comment.
| return hashes.sort().join("\0"); | ||
| } | ||
|
|
||
| export function MergeSection() { |
There was a problem hiding this comment.
It is impossible for me to understand for me the correctness of this component now, there are 3 different useState plus 8 different useRef, massive useEffect with all kinds of asynchrnous ping-pong, and no comments. Even Claude is struggling to follow and tell me what it's doing, and only the tests are difficult to understand.
I think this requires extracting the logic parts into a hook, for example, a useCommitMessageDraft(changeMap) hook returning { subject, body, status, setSubject, reset } that makes all the commit message dance testable and specifiable in separately from the UI. It should also be documented.
Summary
Fixes the Save/Commit step getting stuck on
Loading...when the backend has no stored generated commit message yet.generated_commit_messageas expected pending state instead of a backend error.Test Plan
bun run test:unit src/components/widget/layout/merge-section.test.tsxbun run test:unitcargo test --manifest-path apps/native/src-tauri/Cargo.toml summarize::pipelines::commit_messagecargo test --manifest-path apps/native/src-tauri/Cargo.tomlbun run buildbunx oxlint apps/native/src/components/widget/layout/merge-section.tsx apps/native/src/components/widget/layout/merge-section.test.tsx apps/native/src/hooks/use-summary.ts apps/native/src/ipc/api.tsgit diff --checkbun run test:wdio:smokepassed earlier in this worktree before the final empty-submit guard change.generated_commit_message = NULL; the live nixmac app reached Save step and showed fallback subject/helper text instead of staying onLoading....$claude-reviewOpus 4.8 code review: no blocking issues; accepted/fixed the empty-submit finding.Docs