-
Notifications
You must be signed in to change notification settings - Fork 91
agents: show draft cards only for drafts that exist on disk #176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
morgmart
wants to merge
5
commits into
main
Choose a base branch
from
fix/stale-agent-draft-delete
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e65fe04
fix(agents): show draft cards only for drafts that exist on disk
morgmart 42acd67
fix(agents): close the two draft-lifecycle races found in review
morgmart b3df0aa
fix(agents): close the last async gap before discard; sequence promot…
morgmart f426094
fix(agents): start the next builder before deleting an untouched draft
morgmart 88f9339
fix(agents): restore discard-then-start order for New agent from the …
morgmart File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,7 +17,7 @@ import type { ChatSession } from "@/features/chat/stores/chatSessionStore"; | |
| import { useChatSessionStore } from "@/features/chat/stores/chatSessionStore"; | ||
| import { | ||
| agentSourceToPersona, | ||
| listPersonas, | ||
| listAgentGallery, | ||
| type AgentSourceEntry, | ||
| } from "@/shared/api/agents"; | ||
|
|
||
|
|
@@ -51,37 +51,48 @@ export function AgentBuilderCapability({ | |
| const { t } = useTranslation("agents"); | ||
| const patchSession = useChatSessionStore((state) => state.patchSession); | ||
|
|
||
| const refreshPersonas = useCallback(async () => { | ||
| const personas = await listPersonas(); | ||
| useAgentStore.getState().setPersonas(personas); | ||
| }, []); | ||
|
|
||
| const completeBuilder = useCallback( | ||
| (source: AgentSourceEntry, refreshErrorMessage: string) => { | ||
| clearBuilderSessionState(session.id); | ||
|
|
||
| // Promotion is the durable source of truth. Seed the store immediately | ||
| // so the destination profile exists even if the follow-up disk refresh | ||
| // fails or has not observed the promoted source yet. | ||
| // fails or has not observed the promoted source yet. Running the writes | ||
| // as a gallery mutation fences out any disk refresh that started before | ||
| // the promotion and would otherwise repaint the draft card. | ||
| const promotedPersona = agentSourceToPersona(source); | ||
| const agentStore = useAgentStore.getState(); | ||
| const existingPersona = agentStore.personas.find( | ||
| (persona) => persona.id === promotedPersona.id, | ||
| ); | ||
| if (existingPersona) { | ||
| agentStore.updatePersona(promotedPersona.id, promotedPersona); | ||
| } else { | ||
| agentStore.addPersona(promotedPersona); | ||
| } | ||
| const seeded = agentStore.mutateGallery(() => { | ||
| const current = useAgentStore.getState(); | ||
| const existingPersona = current.personas.find( | ||
| (persona) => persona.id === promotedPersona.id, | ||
| ); | ||
| if (existingPersona) { | ||
| current.updatePersona(promotedPersona.id, promotedPersona); | ||
| } else { | ||
| current.addPersona(promotedPersona); | ||
| } | ||
| // The draft just became this agent; drop its card without waiting | ||
| // for the disk refresh so the gallery never shows both at once. | ||
| for (const draft of current.draftSources) { | ||
| if (draft.properties?.builderSessionId === session.id) { | ||
| current.removeDraftSource(draft.path); | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| onDraftPromoted?.(source); | ||
| onAgentBuilderCompleted?.(promotedPersona.id); | ||
|
|
||
| void refreshPersonas().catch((error) => { | ||
| console.error(refreshErrorMessage, error); | ||
| }); | ||
| // The refresh must start after the mutation releases the fence, or the | ||
| // fence would (correctly) reject it as having begun mid-mutation. | ||
| void seeded | ||
| .then(() => agentStore.refreshGallery(listAgentGallery)) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤖 |
||
| .catch((error) => { | ||
| console.error(refreshErrorMessage, error); | ||
| }); | ||
| }, | ||
| [onAgentBuilderCompleted, onDraftPromoted, refreshPersonas, session.id], | ||
| [onAgentBuilderCompleted, onDraftPromoted, session.id], | ||
| ); | ||
|
|
||
| const handleDraftPromoted = useCallback( | ||
|
|
||
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤖 An orphan draft reopened without its original chat gets a new session ID while its frontmatter can retain the vanished ID. Promotion then misses the original draft in this loop, so the store temporarily retains both it and the promoted persona—and retains it indefinitely if refresh fails. The optimistic removal is keyed only by the current session ID rather than the promoted draft path.