Skip to content

Commit b1ddf4f

Browse files
Im An AIclauderyaneggz
authored
FROM feat/771-model-select-validation TO development (#779)
* chore: scaffold fix for issue #771 model select validation * docs: add PRD and ralph prd.json for issue #771 model select validation fix * Add PRD for model select bug fix (#771) and cloudflared config * feat: US-001 - Wire SelectModel value into react-hook-form SelectModel's onModelSelected callback now passes the selected model value, allowing agent-create-form to sync it to react-hook-form via form.setValue. This fixes form validation errors when selecting a model. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: im-an-ai-agent <im.an.ai.agent@gmail.com> * feat: US-002 - Fix model pre-population on assistant edit page Sync ChatContext model state when loading agent data so SelectModel displays the agent's saved model. ChatContext and AgentContext each have separate useModel() instances; the fix bridges them by calling setModel from ChatContext in the agent data sync useEffect. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: im-an-ai-agent <im.an.ai.agent@gmail.com> * chore: finish iteration 1 * Remove .fix-771 * frontned build fix --------- Signed-off-by: im-an-ai-agent <im.an.ai.agent@gmail.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: ryaneggz <kre8mymedia@gmail.com>
1 parent ded1041 commit b1ddf4f

7 files changed

Lines changed: 152 additions & 131 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,5 @@
3030
.cursor/ralph-config.json
3131
**/prd.json
3232
**/progress.txt
33-
**/.last-branch
33+
**/.last-branch
34+
**/.cloudflared/

.ralph/prd.json

Lines changed: 0 additions & 68 deletions
This file was deleted.

.ralph/progress.txt

Lines changed: 0 additions & 59 deletions
This file was deleted.

frontend/src/components/forms/agents/agent-create-form.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export function AgentCreateForm() {
7878
isAgentSelected,
7979
updateQueryStateModel,
8080
} = useAgentContext();
81-
const { toBackendFormat } = useChatContext();
81+
const { toBackendFormat, setModel } = useChatContext();
8282
const [isEditing, setIsEditing] = useState(!agentId);
8383
const [originalAgent, setOriginalAgent] = useState<Agent | null>(null);
8484
const [isFullscreenOpen, setIsFullscreenOpen] = useState(false);
@@ -257,6 +257,11 @@ export function AgentCreateForm() {
257257
form.setValue("model", agent.model);
258258
form.setValue("public", agent.public || false);
259259

260+
// Sync ChatContext model so SelectModel displays the agent's saved model
261+
if (agent.model) {
262+
setModel(agent.model);
263+
}
264+
260265
// Determine mode and set values
261266
if (
262267
(agent.instructions && agent.instructions.length > 0) ||
@@ -677,7 +682,11 @@ export function AgentCreateForm() {
677682
<FormControl>
678683
<SelectModel
679684
disabled={!isEditing}
680-
onModelSelected={updateQueryStateModel}
685+
onChange={(value) => {
686+
setModel(value);
687+
form.setValue("model", value);
688+
updateQueryStateModel(value);
689+
}}
681690
/>
682691
</FormControl>
683692
<FormMessage />

frontend/src/pages/agents/create.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ import { SidebarTrigger } from "@/components/ui/sidebar";
1313

1414
function AgentCreatePage() {
1515
const { agent, setAgent, useEffectGetAgents } = useAgentContext();
16-
const { useListThreadsEffect, messages } = useChatContext();
16+
const { useListThreadsEffect, messages, useModelsEffect } = useChatContext();
1717
const [activeTab, setActiveTab] = useQueryState("tab");
1818
const [, setSearchParams] = useSearchParams();
1919

2020
useEffectGetAgents();
21+
useModelsEffect();
2122

2223
const handleTabChange = (value: string) => {
2324
setActiveTab(value);

tasks/prd-model-select-bug-fix.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# PRD: Fix Model Select on Assistant Create/Edit Pages
2+
3+
## Introduction
4+
5+
The model select component on the assistant create and edit pages is preventing form submission. After merging PR #767, users can no longer create or edit assistants because selecting a model triggers a validation error ("Model must be at least N characters"). This is a regression bug that blocks core functionality.
6+
7+
## Goals
8+
9+
- Fix the model select validation so assistants can be created and edited successfully
10+
- Ensure the selected model value is correctly passed to the form state
11+
- Maintain existing model selection UX without regression
12+
13+
## User Stories
14+
15+
### US-001: Investigate model select form binding
16+
**Description:** As a developer, I need to understand why the model select value isn't satisfying form validation so I can identify the root cause.
17+
18+
**Acceptance Criteria:**
19+
- [ ] Identify the component(s) responsible for model selection on assistant create/edit pages
20+
- [ ] Determine what changed in PR #767 that caused the regression
21+
- [ ] Document the root cause (e.g., value format mismatch, missing onChange handler, schema change)
22+
23+
### US-002: Fix model select form submission on assistant create
24+
**Description:** As a user, I want to select a model and successfully create an assistant so I can use the platform.
25+
26+
**Acceptance Criteria:**
27+
- [ ] Navigate to `/assistant/create`, fill in form details, select a model, and click save
28+
- [ ] Form submits successfully without validation errors
29+
- [ ] Created assistant has the correct model assigned
30+
- [ ] Typecheck/lint passes
31+
- [ ] Verify in browser using agent-browser skill
32+
33+
### US-003: Fix model select form submission on assistant edit
34+
**Description:** As a user, I want to edit an existing assistant's model and save successfully.
35+
36+
**Acceptance Criteria:**
37+
- [ ] Navigate to an existing assistant's edit page
38+
- [ ] Current model is shown as selected
39+
- [ ] Change the model and save — no validation errors
40+
- [ ] Updated assistant reflects the new model
41+
- [ ] Typecheck/lint passes
42+
- [ ] Verify in browser using agent-browser skill
43+
44+
### US-004: Verify no regression on other form fields
45+
**Description:** As a user, I want all other assistant form fields to continue working after the fix.
46+
47+
**Acceptance Criteria:**
48+
- [ ] All other fields on create/edit pages submit correctly
49+
- [ ] No new console errors or warnings
50+
- [ ] Typecheck/lint passes
51+
52+
## Functional Requirements
53+
54+
- FR-1: Model select component must pass the selected value in the format expected by form validation schema
55+
- FR-2: Form validation must accept valid model selections without character-length errors
56+
- FR-3: Model select must work on both `/assistant/create` and `/assistant/[id]/edit` pages
57+
- FR-4: Previously saved assistants must display their current model correctly when editing
58+
59+
## Non-Goals
60+
61+
- No changes to the list of available models
62+
- No redesign of the model select UI
63+
- No changes to backend model validation
64+
65+
## Technical Considerations
66+
67+
- Regression introduced by PR #767 — review that diff for changes to model select or form schema
68+
- Check if the model select component is passing an object vs a string value
69+
- Check form validation schema (likely Zod) for model field constraints
70+
- Assistant create and edit pages are in the `@frontend` package
71+
72+
## Success Metrics
73+
74+
- Users can create and edit assistants with any available model without validation errors
75+
- Zero regression on existing assistant form functionality
76+
77+
## Open Questions
78+
79+
- Did PR #767 change the model select component itself, the form schema, or both?
80+
- Are there any other select components affected by the same issue?
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# PRD: Fix Model Select Validation on Assistant Create/Edit (#771)
2+
3+
## Introduction
4+
5+
The ModelSelect component on the assistant create and edit pages does not sync its selected value back to the react-hook-form field, causing a validation error ("Model must be at least 2 characters") that prevents form submission. This broke after merging PR #767.
6+
7+
## Goals
8+
9+
- Fix model selection so it writes to the form field and passes validation
10+
- Ensure both create and edit flows work end-to-end
11+
- Maintain backward compatibility with all other SelectModel usages (chat, etc.)
12+
13+
## User Stories
14+
15+
### US-001: Wire SelectModel value into react-hook-form
16+
**Description:** As a user, I want to select a model from the dropdown on the assistant create page and have the form accept my selection without validation errors.
17+
18+
**Acceptance Criteria:**
19+
- [ ] When a model is selected via SelectModel, the form's `model` field is updated with the selected value
20+
- [ ] Form validation passes after selecting a model
21+
- [ ] Clicking Save after filling all required fields (including model) successfully creates the assistant
22+
- [ ] Typecheck passes
23+
- [ ] Verify in browser using agent-browser skill: navigate to `/assistant/create`, fill form, select model, submit succeeds
24+
25+
### US-002: Fix model pre-population on assistant edit page
26+
**Description:** As a user editing an existing assistant, I want to see the currently configured model pre-selected and be able to change it without validation errors.
27+
28+
**Acceptance Criteria:**
29+
- [ ] When editing an assistant, the SelectModel dropdown shows the assistant's current model as selected
30+
- [ ] The form's `model` field is populated with the existing model value on load
31+
- [ ] Changing the model and saving persists the new selection
32+
- [ ] Typecheck passes
33+
- [ ] Verify in browser using agent-browser skill: navigate to an existing assistant's edit page, verify model shown, change it, save succeeds
34+
35+
## Functional Requirements
36+
37+
- FR-1: SelectModel must accept a callback or ref that writes the selected value into the parent form's field (e.g., via `form.setValue("model", value)` or a controlled `value`/`onChange` prop pattern)
38+
- FR-2: The `agent-create-form.tsx` FormField for `model` must sync SelectModel's selection to react-hook-form state
39+
- FR-3: On edit, `form.setValue("model", agent.model)` must run on load so the field is pre-populated
40+
41+
## Non-Goals
42+
43+
- No changes to the model list or model fetching logic
44+
- No changes to the assistant API endpoints
45+
- No refactoring of SelectModel for standalone/non-context usage (that's #772)
46+
47+
## Technical Considerations
48+
49+
- `SelectModel` currently uses `useChatContext()` internally for state — the fix needs to bridge that context state to the form field
50+
- Simplest approach: add an `onChange` callback prop to `SelectModel` that fires with the selected value, and use it in the form to call `form.setValue("model", selectedValue)`
51+
- The existing `onModelSelected` callback has no arguments — either extend it or add a new prop
52+
- Check that the fix works for both create (empty initial) and edit (pre-populated) flows
53+
54+
## Success Metrics
55+
56+
- Users can create and edit assistants with model selection without validation errors
57+
- No regressions in chat model selector behavior

0 commit comments

Comments
 (0)