Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions app/[owner]/[repo]/[postNumber]/comment-thread.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ function CommentItem({

const { postNumber } = useParams<{ postNumber: string }>()

// Check if this is a build mode comment (only relevant for LLM comments)
const isBuildMode =
author.isLlm &&
(comment.content as AgentUIMessage[]).some((m) => m.metadata?.mode === "build")
Copy link
Contributor

Choose a reason for hiding this comment

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

Build mode indicator fails to display for subsequent messages in multi-turn conversations because mode metadata is only added to the first message of the first step

View Details
📝 Patch Details
diff --git a/agent/response-agent.ts b/agent/response-agent.ts
index 2f8d0d1..a61fc52 100644
--- a/agent/response-agent.ts
+++ b/agent/response-agent.ts
@@ -366,7 +366,7 @@ async function streamTextStep({
               ...m,
               id: nanoid(),
               metadata:
-                isFirstStep && index === 0 && mode === "build" ? { mode } : {},
+                mode === "build" ? { mode } : {},
             } satisfies AgentUIMessage
           })
         )

Analysis

Bug Explanation

In agent/response-agent.ts around line 367, the code conditionally adds mode metadata only when three conditions are met simultaneously:

  • isFirstStep && index === 0 && mode === "build"

The problem manifests in two scenarios:

Scenario 1: Multiple messages in first step
When the AI generates multiple messages (e.g., text + tool use), only the first message (index === 0) gets the mode metadata. Subsequent messages in the same first step won't have it.

Scenario 2: Multi-turn conversations
When stepCount > 0 (happens in the while loop in responseAgent lines 71-86), isFirstStep = newMessages.length === 0 becomes false. This means NO messages in steps 2 and beyond receive the mode metadata, even though they were generated in build mode.

In comment-thread.tsx line 84, the code checks:

const isBuildMode =
  author.isLlm &&
  (comment.content as AgentUIMessage[]).some((m) => m.metadata?.mode === "build")

This check uses .some(), which needs at least ONE message with the mode metadata. The current logic in response-agent makes this unreliable because:

  • First step, second+ messages: Won't have mode metadata
  • Any messages in steps 2+: Won't have mode metadata

Result: The build mode indicator "(build)" fails to display for real-world multi-turn conversations or when the first response generates multiple messages.

The Fix

Changed line 367 in agent/response-agent.ts from:

metadata: isFirstStep && index === 0 && mode === "build" ? { mode } : {}

To:

metadata: mode === "build" ? { mode } : {}

This ensures that EVERY message generated when mode="build" receives the mode metadata, regardless of step number or message index. Now the .some() check in comment-thread.tsx will reliably find the build mode indication, guaranteeing the indicator displays correctly in all cases.

The fix is minimal, non-breaking, and doesn't require database migrations because it only changes how existing metadata is populated.


const actionLabel = isRootComment ? "posted" : "commented"

const header = (
Expand All @@ -95,6 +100,9 @@ function CommentItem({
<UserAvatar src={author.image} username={author.username} />

{author.name}
{isBuildMode && (
<span className="font-normal text-muted-foreground">(build)</span>
)}
</Link>
<span className="hidden sm:inline">&nbsp;</span>
<span className="mr-1.5 text-muted-foreground text-sm">
Expand Down