Skip to content

feat: prefill the input with the ?q= prompt while provisioning (chat#1848 follow-up)#1849

Merged
sweetmantech merged 3 commits into
mainfrom
feat/q-prefill-input-autofire
Jul 4, 2026
Merged

feat: prefill the input with the ?q= prompt while provisioning (chat#1848 follow-up)#1849
sweetmantech merged 3 commits into
mainfrom
feat/q-prefill-input-autofire

Conversation

@sweetmantech

@sweetmantech sweetmantech commented Jul 4, 2026

Copy link
Copy Markdown
Collaborator

Follow-up to #1848 / #1847. The queued ?q= send fixed the 400, but the provisioning wait became dead space — nothing on screen confirms the AGENTS click landed.

What

  • Instant feedback: the input is prefilled with the ?q= prompt the moment the page renders (one-shot; never over an existing conversation or already-typed text).
  • Auto-fire on ready: when the workspace provisions (same shouldAutoSendInitialMessage gate as fix: gate ?q= auto-send on the provisioned sessionId (chat#1847) #1848), the message fires from the live input — an edit made while waiting sends the edited text; a cleared input sends nothing (opt-out). Exactly the semantics of pressing Send yourself.
  • One-shot ref guards double-sends; lib/chat/getInitialMessageText.ts extracted (SRP) with a 3-case unit suite (TDD RED→GREEN).

Full suite 83 passed; tsc no new errors vs main; prettier clean.

Verification

Preview verification (real login → prompt visible in the input during "Preparing your workspace" → auto-fires on ready → 200 + streamed response) to follow as a PR comment.

🤖 Generated with Claude Code


Summary by cubic

Prefills the chat input with the ?q= prompt during provisioning and auto-sends it when the workspace is ready. This gives instant feedback, uses the live input on send (edits respected, cleared input sends nothing), and prevents double-sends.

  • New Features

    • Prefill: On first render, set the input to the deep-link ?q= text; never overwrites existing messages or typed text.
    • Auto-fire: When ready, send from the current input under shouldAutoSendInitialMessage; respects edits, skips if cleared; one-shot refs guard against double-sends.
  • Refactors

    • Extracted useInitialMessageAutoSend to encapsulate prefill + auto-send; useVercelChat now composes it. Added getInitialMessageText (unit-tested) to read the first text part.
    • useInitialMessageAutoSend now sources auth state internally via @privy-io/react-auth and useUserProvider; hook params carry only chat-instance-scoped data.

Written for commit 1a4f98a. Summary will update on new commits.

Review in cubic

…1848 follow-up)

After #1848 the deep-link message correctly waits for the session, but
the wait is dead space: nothing on screen tells the customer their
AGENTS click worked. Prefill the input with the prompt immediately, then
auto-fire when the workspace goes ready — sending whatever is in the
input at that moment, so an edit made while waiting sends the edited
text and a cleared input sends nothing, exactly like pressing Send.

- lib/chat/getInitialMessageText.ts (SRP, unit-tested): first text part
  of the deep-link message, undefined when nothing meaningful.
- useVercelChat: one-shot prefill effect (never clobbers an existing
  conversation or typed text) + auto-fire builds the message from the
  live input; one-shot ref prevents double-sends.

TDD RED->GREEN (3-case extractor suite); full suite 83 passed; tsc no
new errors vs main; prettier clean.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@vercel

vercel Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

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

Project Deployment Actions Updated (UTC)
chat Ready Ready Preview Jul 4, 2026 5:18pm

Request Review

@cursor

cursor Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

@coderabbitai

coderabbitai Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@sweetmantech, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 8 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: b7f3078b-e7f0-4ced-9194-6f60c34d18d4

📥 Commits

Reviewing files that changed from the base of the PR and between aa49f75 and 1a4f98a.

⛔ Files ignored due to path filters (1)
  • lib/chat/__tests__/getInitialMessageText.test.ts is excluded by !**/*.test.* and included by lib/**
📒 Files selected for processing (3)
  • hooks/useInitialMessageAutoSend.ts
  • hooks/useVercelChat.ts
  • lib/chat/getInitialMessageText.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/q-prefill-input-autofire

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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f36c460970

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread hooks/useVercelChat.ts Outdated
Comment on lines +423 to +427
handleSendQueryMessages({
id: generateUUID(),
role: "user",
parts: [{ type: "text", text }],
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve attachments when auto-sending the edited prompt

When a ?q= chat is still provisioning, the input remains editable and the toolbar still allows attachments/mentions, but the new auto-fire path constructs a text-only UIMessage and bypasses the same handleSubmit logic that folds in attachments, textAttachments, mentionAttachments, and mentioned-file text context. In that scenario, a user who edits the prefilled prompt by adding a file/mention before the workspace becomes ready will have the prompt auto-sent without the selected context, unlike pressing Send after readiness.

Useful? React with 👍 / 👎.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

1 issue found across 3 files

Confidence score: 3/5

  • In hooks/useVercelChat.ts, the auto-fired ?q= flow appears to bypass the normal send pipeline, so edited input can be posted as raw text without the same mention/text/audio context handling or selected-model persistence, which can cause inconsistent chat behavior and surprising outputs for users; route ?q= submissions through the exact same send path before merging.
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="hooks/useVercelChat.ts">

<violation number="1" location="hooks/useVercelChat.ts:423">
P2: Auto-fired `?q=` sends can diverge from a normal Send: edited input is posted as raw text and skips the same pre-send pipeline (mention/text/audio context + selected-model persistence). Reusing the same send path as manual submit would keep provisioning auto-fire behavior consistent with what users see in the input.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread hooks/useVercelChat.ts Outdated
// (they opted out; send nothing), exactly as if they pressed Send.
const text = input.trim() ? input : "";
if (!text) return;
handleSendQueryMessages({

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2: Auto-fired ?q= sends can diverge from a normal Send: edited input is posted as raw text and skips the same pre-send pipeline (mention/text/audio context + selected-model persistence). Reusing the same send path as manual submit would keep provisioning auto-fire behavior consistent with what users see in the input.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At hooks/useVercelChat.ts, line 423:

<comment>Auto-fired `?q=` sends can diverge from a normal Send: edited input is posted as raw text and skips the same pre-send pipeline (mention/text/audio context + selected-model persistence). Reusing the same send path as manual submit would keep provisioning auto-fire behavior consistent with what users see in the input.</comment>

<file context>
@@ -384,31 +385,57 @@ export function useVercelChat({
+    // (they opted out; send nothing), exactly as if they pressed Send.
+    const text = input.trim() ? input : "";
+    if (!text) return;
+    handleSendQueryMessages({
+      id: generateUUID(),
+      role: "user",
</file context>

…n extension hook (OCP)

Review feedback on #1848/#1849: useVercelChat grew in both PRs, being
modified for every deep-link change instead of extended. Move the whole
?q= behavior (prefill + provisioning-gated auto-fire + one-shot guards)
into hooks/useInitialMessageAutoSend, composed like the existing
extension hooks (useChatTransport, usePersistSelectedModel,
useMessageLoader). useVercelChat now carries one hook call and is
smaller than it was before #1848 (422 lines vs 424); future deep-link
changes touch only the dedicated hook.

No behavior change: the hook is a verbatim move of the two effects over
the tested pure helpers (shouldAutoSendInitialMessage,
getInitialMessageText). Full suite 83 passed; tsc no new errors vs
main; prettier clean.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@sweetmantech

Copy link
Copy Markdown
Collaborator Author

Refactored per review feedback (f36c4609886e82d4): the entire ?q= deep-link behavior now lives in hooks/useInitialMessageAutoSend.ts (84 lines, self-contained), composed into useVercelChat as a single call — the same extension pattern as useChatTransport / usePersistSelectedModel / useMessageLoader. useVercelChat.ts is now 422 lines — smaller than before #1848 (424) and 13 lines under current main (435). Future deep-link changes (prefill rules, opt-out, gating) modify only the dedicated hook; useVercelChat is closed against them. No behavior change — verbatim move of the two effects over the tested pure helpers.

@cursor

cursor Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

1 issue found across 2 files (changes from recent commits).

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="hooks/useInitialMessageAutoSend.ts">

<violation number="1" location="hooks/useInitialMessageAutoSend.ts:68">
P0: The auto-send can silently fail when the session is already provisioned before the prefill's `setInput` commits. Move `didAutoFireRef.current = true` below the `if (!text) return` guard so the effect can fire on the next render when the prefilled text is available.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

sessionId,
});
if (!mayAutoSend || didAutoFireRef.current) return;
didAutoFireRef.current = true;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P0: The auto-send can silently fail when the session is already provisioned before the prefill's setInput commits. Move didAutoFireRef.current = true below the if (!text) return guard so the effect can fire on the next render when the prefilled text is available.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At hooks/useInitialMessageAutoSend.ts, line 68:

<comment>The auto-send can silently fail when the session is already provisioned before the prefill's `setInput` commits. Move `didAutoFireRef.current = true` below the `if (!text) return` guard so the effect can fire on the next render when the prefilled text is available.</comment>

<file context>
@@ -0,0 +1,84 @@
+      sessionId,
+    });
+    if (!mayAutoSend || didAutoFireRef.current) return;
+    didAutoFireRef.current = true;
+    const text = input.trim() ? input : "";
+    if (!text) return;
</file context>

authenticated/userId come from usePrivy/useUserProvider directly instead
of riding through params — the hook's params now carry only what is
chat-instance-scoped (initialMessages, status, messagesLength,
sessionId, input/setInput, send). Suite 83 passed; tsc clean vs main.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@cursor

cursor Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

0 issues found across 2 files (changes from recent commits).

Requires human review: Auto-approval blocked by 2 unresolved issues from previous reviews.

Re-trigger cubic

@sweetmantech sweetmantech merged commit a58a467 into main Jul 4, 2026
4 checks passed
@sweetmantech

Copy link
Copy Markdown
Collaborator Author

Preview verification — 2026-07-04 ✅

Preview https://chat-gt0ucve7m-recoup.vercel.app (head 1a4f98af — includes the OCP extraction + KISS param trim), Chrome DevTools MCP, real staff login, the exact #1847 repro URL.

check observed verdict
Instant feedback (the dead-space fix) The input carried the full AGENTS prompt immediately on page render — before login even completed, visible under the Privy modal while the status read "Preparing your workspace"
No premature send Post-login, still provisioning: prompt in input, nothing sent, Send disabled
Auto-fire on ready The instant "Workspace ready." landed: message sent, input cleared, URL flipped to canonical /sessions/5a6945a3…/chats/5adf2010…
Network order POST /api/sessions (reqid 696) → 200, then POST /api/chat (reqid 713) → 200
Single fire One chat POST despite provisioning re-renders (one-shot ref)

One observation not related to this PR: the assistant stream on the preview cut off mid-sentence with a Retry button — the send itself was a 200, onFinish fired (credits refetch reqid 717), and the truncation is the test-api backend's sandbox stream, reproducible independent of this client change (prod verified fine on #1848's identical transport path).

Behavior identical across all three commits' semantics (prefill → live-input fire → opt-out on clear). Ready for review/merge.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant