Skip to content

fix(editor): Restore Instance AI draft when thread creation fails - #37874

Draft
Ryner01 wants to merge 1 commit into
masterfrom
ins-579-instance-ai-input-field-loses-all-text-if-the-request-fails
Draft

fix(editor): Restore Instance AI draft when thread creation fails#37874
Ryner01 wants to merge 1 commit into
masterfrom
ins-579-instance-ai-input-field-loses-all-text-if-the-request-fails

Conversation

@Ryner01

@Ryner01 Ryner01 commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Summary

Restore the submitted Instance AI draft when thread creation fails.

How to test

Run pnpm test src/features/ai/instanceAi/__tests__/InstanceAiEmptyView.test.ts from packages/frontend/editor-ui.

Related Linear tickets, Github issues, and Community forum posts

https://linear.app/n8n/issue/INS-579

Review / Merge checklist

  • I have seen this code, I have run this code, and I take responsibility for this code.
  • PR title and summary are descriptive. (conventions)
  • Docs updated or follow-up ticket created.
  • Tests included.
  • PR Labeled with Backport to Beta, Backport to Stable, or Backport to v1 (if the PR is an urgent fix that needs to be backported)

🤖 PR Summary generated by AI

Review in cubic

@n8n-assistant

n8n-assistant Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

PR review overview

Based on ownership of the 2 changed files in this PR:

Ownership Files owned Share Source code Test files Misc
@n8n-io/ai 2 100% +14 / -10 +18 / -3 +0 / -0
Total 2 100% +14 / -10 +18 / -3 +0 / -0

@codecov

codecov Bot commented Sep 4, 2026

Copy link
Copy Markdown

Bundle Report

Changes will increase total bundle size by 179 bytes (0.0%) ⬆️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
editor-ui-esm 63.31MB 179 bytes (0.0%) ⬆️

Affected Assets, Files, and Routes:

view changes for bundle: editor-ui-esm

Assets Changed:

Asset Name Size Change Total Size Change (%)
assets/InstanceAiEmptyView-*.js 179 bytes 463.77kB 0.04%

Files in assets/InstanceAiEmptyView-*.js:

  • ./src/features/ai/instanceAi/InstanceAiEmptyView.vue → Total Size: 355 bytes

@codecov

codecov Bot commented Sep 4, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 71.42857% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...src/features/ai/instanceAi/InstanceAiEmptyView.vue 71.42% 0 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

@n8n-assistant n8n-assistant Bot added the n8n team Authored by the n8n team label Sep 4, 2026

@cubic-dev-ai cubic-dev-ai 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.

2 issues found across 2 files

Confidence score: 3/5

  • InstanceAiEmptyView.vue can fail to restore submitted text when an attachment is staged before syncThread rejects, because isDirty() blocks the helper; preserve the text-only submission in this race, as tracked by INS-579.
  • InstanceAiEmptyView.vue can restore a stale submission into the active composer when the selected project changes during pending syncThread() or sendMessage() work; guard the continuation against the changed project or stale request before restoring content.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="packages/frontend/editor-ui/src/features/ai/instanceAi/InstanceAiEmptyView.vue">

<violation number="1" location="packages/frontend/editor-ui/src/features/ai/instanceAi/InstanceAiEmptyView.vue:464">
P2: Custom agent: **Frontend**

When the selected project changes while `syncThread()` or `sendMessage()` is pending, this continuation restores the old submission into the currently active composer without checking its originating project or request. Capture and revalidate the originating project/component or request sequence before calling `restoreDraft` and focusing the input.</violation>

<violation number="2" location="packages/frontend/editor-ui/src/features/ai/instanceAi/InstanceAiEmptyView.vue:468">
P2: When a text-only submit is followed by staging an attachment before `syncThread` rejects, `isDirty()` prevents this helper from restoring the submitted text. According to linked Linear issue INS-579, preserve that text alongside newly staged attachments, or distinguish text edits from attachment state before applying the dirty guard.</violation>
</file>

Shadow auto-approve: would not auto-approve because issues were found.

Fix all with cubic | Re-trigger cubic

void nextTick(() => {
// The input supplies the callback only when the draft has attachments.
// Restore text directly for a text-only draft.
if (!restoreDraft?.()) {

@cubic-dev-ai cubic-dev-ai Bot Sep 4, 2026

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.

P2: When a text-only submit is followed by staging an attachment before syncThread rejects, isDirty() prevents this helper from restoring the submitted text. According to linked Linear issue INS-579, preserve that text alongside newly staged attachments, or distinguish text edits from attachment state before applying the dirty guard.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/frontend/editor-ui/src/features/ai/instanceAi/InstanceAiEmptyView.vue, line 468:

<comment>When a text-only submit is followed by staging an attachment before `syncThread` rejects, `isDirty()` prevents this helper from restoring the submitted text. According to linked Linear issue INS-579, preserve that text alongside newly staged attachments, or distinguish text edits from attachment state before applying the dirty guard.</comment>

<file context>
@@ -461,6 +461,18 @@ onMounted(() => {
+	void nextTick(() => {
+		// The input supplies the callback only when the draft has attachments.
+		// Restore text directly for a text-only draft.
+		if (!restoreDraft?.()) {
+			const input = chatInputRef.value;
+			if (input && !input.isDirty()) input.setText(message);
</file context>
Fix with cubic


onUnmounted(clearPersonalizedPromptMetadataTimeout);

function restoreDraftAfterFailedSubmit(message: string, restoreDraft?: () => boolean) {

@cubic-dev-ai cubic-dev-ai Bot Sep 4, 2026

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.

P2: Custom agent: Frontend

When the selected project changes while syncThread() or sendMessage() is pending, this continuation restores the old submission into the currently active composer without checking its originating project or request. Capture and revalidate the originating project/component or request sequence before calling restoreDraft and focusing the input.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/frontend/editor-ui/src/features/ai/instanceAi/InstanceAiEmptyView.vue, line 464:

<comment>When the selected project changes while `syncThread()` or `sendMessage()` is pending, this continuation restores the old submission into the currently active composer without checking its originating project or request. Capture and revalidate the originating project/component or request sequence before calling `restoreDraft` and focusing the input.</comment>

<file context>
@@ -461,6 +461,18 @@ onMounted(() => {
 
 onUnmounted(clearPersonalizedPromptMetadataTimeout);
 
+function restoreDraftAfterFailedSubmit(message: string, restoreDraft?: () => boolean) {
+	void nextTick(() => {
+		// The input supplies the callback only when the draft has attachments.
</file context>
Fix with cubic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed n8n team Authored by the n8n team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant