Skip to content

Conversation

@dingdinglz
Copy link

@dingdinglz dingdinglz commented Oct 14, 2025

Description

maxOutputTokens set but never used

Type of Change

  • Bug fix
  • New feature
  • Documentation
  • Refactor
  • Other (please describe):

Important

Fix missing maxOutputTokens parameter in streamText call in createRootAgentStream in root.ts.

  • Bug Fix:
    • Add maxOutputTokens: modelConfig.maxOutputTokens to streamText call in createRootAgentStream in root.ts to ensure token limit is applied.

This description was created by Ellipsis for 7e42a07. You can customize this summary. It will automatically update as commits are pushed.

Summary by CodeRabbit

  • New Features

    • Added configurable maximum output length for AI responses so streamed replies respect the selected model’s cap, improving predictability and cost control.
  • Bug Fixes / UX

    • Tool actions invoked from chat now complete before subsequent UI updates, improving error reporting and making state updates and message ordering more predictable.

@vercel
Copy link

vercel bot commented Oct 14, 2025

@dingdinglz is attempting to deploy a commit to the Onlook Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link

coderabbitai bot commented Oct 14, 2025

Walkthrough

Adds a maxOutputTokens argument to the root stream call and changes a chat tool-call handler from fire-and-forget to awaiting the tool call completion, altering execution ordering and error propagation.

Changes

Cohort / File(s) Summary
Root agent streaming config
packages/ai/src/agents/root.ts
Passes maxOutputTokens (from modelConfig.maxOutputTokens) into streamText within createRootAgentStream.
Chat tool-call handling
apps/web/client/src/app/project/[id]/_hooks/use-chat/index.tsx
Replaces a non-blocking void fire-and-forget tool invocation with an awaited call in onToolCall, making the handler wait for completion before continuing and preserving the subsequent state-reset logic.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Caller
  participant RootAgent
  participant TextStreamer as streamText

  Caller->>RootAgent: createRootAgentStream(modelConfig)
  Note right of RootAgent: reads modelConfig.maxOutputTokens
  RootAgent->>TextStreamer: streamText({... , maxOutputTokens})
  TextStreamer-->>RootAgent: Streamed text chunks
  RootAgent-->>Caller: Forward streamed output
Loading
sequenceDiagram
  autonumber
  participant UI
  participant useChatHook as Hook
  participant Tool

  UI->>Hook: onToolCall(params)
  Note right of Hook #DDEBF7: previously used `void Tool.call()` (fire-and-forget)
  Hook->>Tool: await Tool.call(params)
  Tool-->>Hook: result / error
  Hook-->>UI: update isExecutingToolCall = false (after completion)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • feat: reduce agent overhead #2953 — Adjusts createRootAgentStream to pass modelConfig.maxOutputTokens into streaming and also makes related use-chat tool calls synchronous; strongly related to the root streaming and tool-call flow changes.
  • fix: add tool result non-blocking #2846 — Changes chat onToolCall behavior (fire-and-forget vs awaited), directly related to the synchronous tool-call adjustment in this diff.

Poem

I nibble code and count the hops,
Tokens tucked in tidy crops.
I wait a beat for tools to say,
Then scamper on my streaming way.
A little hop, a tidy stream—🐇

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The pull request title "fix: maxTokens not used" directly and accurately summarizes the main change in the pull request. The raw summary confirms that maxOutputTokens was added to the streamText call in createRootAgentStream, which aligns perfectly with the stated problem that "maxTokens [was] not used." The title is concise, clear, and specific enough for a teammate to understand the core fix from the commit history.
Description Check ✅ Passed The pull request description provides a concise explanation of the bug ("maxOutputTokens set but never used") and correctly identifies the Type of Change as a bug fix. While the description is minimal and omits some template sections like Related Issues, Testing, and Additional Notes, it clearly communicates the core issue and solution without being vague or off-topic. For a straightforward bug fix of this scope, the provided information is sufficient to understand the change, and the missing sections may be non-critical in this context.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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 and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
apps/web/client/src/app/project/[id]/_hooks/use-chat/index.tsx (1)

57-62: Simplify redundant await + .then() pattern and add error handling for cleanup.

The pattern await promise.then(callback) is unconventional and less readable than standard approaches. Additionally, if handleToolCall throws an error (despite its internal try-catch), setIsExecutingToolCall(false) may not execute, potentially leaving the UI in a stuck state.

Apply this diff to simplify the pattern and ensure cleanup always runs:

 onToolCall: async (toolCall) => {
     setIsExecutingToolCall(true);
-    await handleToolCall(toolCall.toolCall, editorEngine, addToolResult).then(() => {
+    try {
+        await handleToolCall(toolCall.toolCall, editorEngine, addToolResult);
+    } finally {
         setIsExecutingToolCall(false);
-    });
+    }
 },
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7e42a07 and 834272a.

📒 Files selected for processing (1)
  • apps/web/client/src/app/project/[id]/_hooks/use-chat/index.tsx (1 hunks)
🧰 Additional context used
📓 Path-based instructions (6)
apps/web/client/src/app/**/*.tsx

📄 CodeRabbit inference engine (AGENTS.md)

apps/web/client/src/app/**/*.tsx: Default to Server Components; add 'use client' when using events, state/effects, browser APIs, or client‑only libraries
Do not use process.env in client code; import env from @/env instead

Avoid hardcoded user-facing text; use next-intl messages/hooks

Files:

  • apps/web/client/src/app/project/[id]/_hooks/use-chat/index.tsx
apps/web/client/src/**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

apps/web/client/src/**/*.{ts,tsx}: Use path aliases @/* and ~/* for imports that map to apps/web/client/src/*
Avoid hardcoded user-facing text; use next-intl messages/hooks instead

Use path aliases @/* and ~/* for imports mapping to src/*

Files:

  • apps/web/client/src/app/project/[id]/_hooks/use-chat/index.tsx
apps/web/client/src/**/*.tsx

📄 CodeRabbit inference engine (AGENTS.md)

apps/web/client/src/**/*.tsx: Create MobX store instances with useState(() => new Store()) for stable references across renders
Keep the active MobX store in a useRef and perform async cleanup with setTimeout(() => storeRef.current?.clear(), 0) to avoid route-change races
Avoid useMemo for creating MobX store instances
Avoid putting the MobX store instance in effect dependency arrays if it causes loops; split concerns by domain

apps/web/client/src/**/*.tsx: Create MobX store instances with useState(() => new Store()) for stable identities across renders
Keep the active MobX store in a useRef and clean up asynchronously with setTimeout(() => storeRef.current?.clear(), 0)
Do not use useMemo to create MobX stores
Avoid placing MobX store instances in effect dependency arrays if it causes loops; split concerns instead
observer components must be client components; place a single client boundary at the feature entry; child observers need not repeat 'use client'

Files:

  • apps/web/client/src/app/project/[id]/_hooks/use-chat/index.tsx
**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Do not use the any type unless necessary

Files:

  • apps/web/client/src/app/project/[id]/_hooks/use-chat/index.tsx
apps/web/client/src/app/**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

Default to Server Components; add 'use client' only when using events, state/effects, browser APIs, or client-only libs

Files:

  • apps/web/client/src/app/project/[id]/_hooks/use-chat/index.tsx
{apps,packages}/**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

Avoid using the any type unless absolutely necessary

Files:

  • apps/web/client/src/app/project/[id]/_hooks/use-chat/index.tsx
🧬 Code graph analysis (1)
apps/web/client/src/app/project/[id]/_hooks/use-chat/index.tsx (1)
apps/web/client/src/components/tools/tools.ts (1)
  • handleToolCall (6-37)

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