fix(agents): normalize agent handoff prompt values to ensure default instructions#12707
fix(agents): normalize agent handoff prompt values to ensure default instructions#12707xxsLuna wants to merge 3 commits intodanny-avila:devfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes an agents handoff bug where clearing handoff fields in the UI produced empty strings ("") that prevented backend defaults (e.g., default promptKey = "instructions") from being applied.
Changes:
- Backend: Normalize
""→undefinedforgraphEdgeSchemafields (description,prompt,promptKey) via Zod transforms. - Frontend: Normalize cleared handoff inputs to
undefinedinAgentHandoffs.tsxchange handlers.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| packages/api/src/agents/validation.ts | Adds Zod transforms to treat empty-string edge fields as unset so backend defaulting works. |
| client/src/components/SidePanel/Agents/Advanced/AgentHandoffs.tsx | Normalizes cleared handoff form inputs to undefined before saving edges. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| placeholder={localize('com_ui_agent_handoff_prompt_placeholder')} | ||
| value={typeof edge.prompt === 'string' ? edge.prompt : ''} | ||
| onChange={(e) => updateHandoffDetailsAt(idx, { prompt: e.target.value })} | ||
| onChange={(e) => updateHandoffDetailsAt(idx, { prompt: e.target.value?.trim() || undefined })} |
There was a problem hiding this comment.
The prompt textarea handler calls .trim() before saving. That changes user-authored prompt content (e.g., leading/trailing newlines/spaces used for formatting) rather than just normalizing an “empty” value. Consider preserving the raw textarea value and only mapping an empty string to undefined (or use a dedicated empty-string check) so prompt content isn’t mutated.
| onChange={(e) => updateHandoffDetailsAt(idx, { prompt: e.target.value?.trim() || undefined })} | |
| onChange={(e) => | |
| updateHandoffDetailsAt(idx, { | |
| prompt: e.target.value === '' ? undefined : e.target.value, | |
| }) | |
| } |
| description: z.string().optional().transform((v) => (v === '' ? undefined : v)), | ||
| edgeType: z.enum(['handoff', 'direct']).optional(), | ||
| prompt: z.union([z.string(), z.function()]).optional(), | ||
| prompt: z.union([z.string(), z.function()]).optional().transform((v) => (v === '' ? undefined : v)), | ||
| excludeResults: z.boolean().optional(), | ||
| promptKey: z.string().optional(), | ||
| promptKey: z.string().optional().transform((v) => (v === '' ? undefined : v)), |
There was a problem hiding this comment.
There’s no regression test covering the new empty-string normalization for edge fields (description/prompt/promptKey). Adding a unit test that parses an agent update payload containing edges: [{..., promptKey: ''}] and asserts the parsed result omits/undefines those fields would help prevent this bug from reappearing (and ensures the schema+controller pipeline behaves as intended).
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c2d8618037
ℹ️ 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 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 address that feedback".
|
Please address ESLint issues and Codex review comment |
5ba697b to
9927c6a
Compare
|
I've addressed the ESLint (Prettier) issues and the Codex review feedback (preserving whitespace in the prompt). Please review the updated changes. Thank you! |
Summary
This PR fixes a bug where clearing handoff configuration fields in the UI would send empty strings (
"") to the backend, preventing default values (like'instructions') from being applied.Changes
.transform()tographEdgeSchemainpackages/api/src/agents/validation.tsto convert empty strings toundefined.AgentHandoffs.tsxcomponents to normalize empty inputs toundefinedon change.This ensures that the agent orchestration logic correctly identifies handoff instructions even when the configuration has been edited and cleared.
Closes #12706