Skip to content

[5246] fix(frontend): keep the agent chat draft when committing a revision - #5250

Merged
ardaerzin merged 1 commit into
big-agentsfrom
fe-fix/5246-agent-commit-clears-draft
Jul 12, 2026
Merged

ardaerzin merged 1 commit into
big-agentsfrom
fe-fix/5246-agent-commit-clears-draft

Conversation

@ardaerzin

Copy link
Copy Markdown
Contributor

What

Fixes #5246 — committing a new revision in the agent playground clears the message the user is currently typing.

Root cause

The composer draft is stored per session (composerDraftBySession[sessionId]), a key that is stable across commits, and AgentConversation stays mounted through a commit — only its entityId prop swaps (old revision → new revision). So the draft loss was not a remount.

The culprit is a reset effect that runs on every entityId change:

// AgentConversation.tsx
useEffect(() => {
    stripProvenance.clear()
}, [entityId, stripProvenance.clear])

Its intent is only to reset the template provenance chip so a template name picked against the old revision doesn't leak into the new one. But clear() does more than that — it also runs setText("") on the composer, emptying the Lexical editor:

// useTemplateProvenance.tsx
const clear = useCallback(() => {
    apiRef.current.setText("")   // ← wipes the in-progress draft
    clearProvenance()            // ← drops the chip
}, [clearProvenance])

So: commit → entityId swaps → effect fires → clear() → the user's draft is nuked. The agent's own commit_revision tool takes the same switchEntity path, so it blanked the box mid-conversation too.

Fix

The hook already had the right primitive — clearProvenance() ("Drop provenance without touching composer text") — it just wasn't exposed on the public API. Two small edits:

  1. Expose clearProvenance from useTemplateProvenance (return + type).
  2. The revision-change effect now calls stripProvenance.clearProvenance() instead of clear().

This preserves the effect's real purpose (reset the template chip on revision swap) while leaving the in-progress draft intact. The legitimate clear() calls on the post-send / post-commit paths (where the composer should empty) are unchanged.

Testing

  • Verified manually in EE: type a draft in the agent chat composer, commit a new version → draft now survives (was previously wiped).
  • Confirmed a normal send still clears the composer, and template pick/clear still works.

…ision

The revision-change effect in AgentConversation called
stripProvenance.clear(), which empties the composer text as well as the
template chip. A commit swaps the panel's entityId (old revision -> new
revision), so the effect fired and wiped whatever the user was typing.

Use the existing clearProvenance() primitive (drops the chip only) for
the revision swap, leaving the in-progress draft intact. clear() is still
used on the legitimate post-send/commit paths where the text should go.
@dosubot dosubot Bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Jul 12, 2026
@vercel

vercel Bot commented Jul 12, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
agenta-documentation Ready Ready Preview, Comment Jul 12, 2026 1:46pm

Request Review

@dosubot dosubot Bot added bug report Something isn't working frontend labels Jul 12, 2026
@coderabbitai

coderabbitai Bot commented Jul 12, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes
    • Preserved composer drafts when switching agent entities.
    • Template chips and provenance now reset independently from composer text.
    • Improved template state handling during agent revisions.

Walkthrough

The template provenance hook now exposes a provenance-only clearing callback. Agent conversation entity changes use it to remove the template chip while preserving the composer draft.

Changes

Template provenance reset

Layer / File(s) Summary
Add and use provenance-only clearing
web/oss/src/components/TemplateStrip/hooks/useTemplateProvenance.tsx, web/oss/src/components/AgentChatSlice/AgentConversation.tsx
useTemplateProvenance returns clearProvenance(), and entity changes invoke it instead of clearing the composer state.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main fix: preserving the agent chat draft when committing a revision.
Description check ✅ Passed The description directly explains the draft-clearing bug and the intended fix in the affected frontend components.
Linked Issues check ✅ Passed The changes expose clearProvenance and use it on revision swaps, which preserves the draft as required by #5246.
Out of Scope Changes check ✅ Passed The edits stay focused on the draft-preservation bug and the needed hook API change, with no unrelated scope added.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fe-fix/5246-agent-commit-clears-draft

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@ardaerzin

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 12, 2026 •

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
web/oss/src/components/TemplateStrip/hooks/useTemplateProvenance.tsx (1)

36-38: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Add regression coverage for the two clearing behaviors.

Verify that clearProvenance() removes the selected template without calling composerApi.setText, while clear() still clears both provenance and composer text. This directly protects the draft-preservation fix.

Also applies to: 128-128

web/oss/src/components/AgentChatSlice/AgentConversation.tsx (1)

622-626: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Add an entity-change regression test.

Mount the conversation with a non-empty draft and selected provenance, change entityId, then assert that the draft remains while the provenance selection is cleared. This validates the hook/caller contract behind issue #5246.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: d4ac6edb-e065-4ee0-ad21-e4f244707b0c

📥 Commits

Reviewing files that changed from the base of the PR and between a8257c9 and 6665530.

📒 Files selected for processing (2)
  • web/oss/src/components/AgentChatSlice/AgentConversation.tsx
  • web/oss/src/components/TemplateStrip/hooks/useTemplateProvenance.tsx

@ardaerzin
ardaerzin merged commit 910c20c into big-agents Jul 12, 2026
23 checks passed

This branch was successfully deployed

1 active deployment
Preview — 66655302 Deployed Jul 12, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug report Something isn't working frontend size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant