Skip to content
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,7 @@ function runtimeEventToActivities(
kind: "tool.updated",
summary: event.payload.title ?? "Tool updated",
payload: {
...(event.itemId ? { itemId: event.itemId } : {}),
itemType: event.payload.itemType,
...(event.payload.status ? { status: event.payload.status } : {}),
...(event.payload.detail ? { detail: truncateDetail(event.payload.detail) } : {}),
Expand All @@ -568,8 +569,9 @@ function runtimeEventToActivities(
kind: "tool.completed",
summary: event.payload.title ?? "Tool",
payload: {
...(event.itemId ? { itemId: event.itemId } : {}),
itemType: event.payload.itemType,
...(event.payload.detail ? { detail: truncateDetail(event.payload.detail) } : {}),
...(event.payload.detail ? { detail: event.payload.detail } : {}),
...(event.payload.data !== undefined ? { data: event.payload.data } : {}),
},
turnId: toTurnId(event.turnId) ?? null,
Expand All @@ -588,10 +590,11 @@ function runtimeEventToActivities(
createdAt: event.createdAt,
tone: "tool",
kind: "tool.started",
summary: `${event.payload.title ?? "Tool"} started`,
summary: event.payload.title ?? "Tool started",
payload: {
...(event.itemId ? { itemId: event.itemId } : {}),
itemType: event.payload.itemType,
...(event.payload.detail ? { detail: truncateDetail(event.payload.detail) } : {}),
...(event.payload.detail ? { detail: event.payload.detail } : {}),
Comment thread
cursor[bot] marked this conversation as resolved.
},
turnId: toTurnId(event.turnId) ?? null,
...maybeSequence,
Expand Down
7 changes: 4 additions & 3 deletions apps/server/src/provider/Layers/CodexAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ function toCanonicalItemType(raw: string | undefined | null): CanonicalItemType
return "unknown";
}

function itemTitle(itemType: CanonicalItemType): string | undefined {
function itemTitle(itemType: CanonicalItemType, started = false): string | undefined {
switch (itemType) {
case "assistant_message":
return "Assistant message";
Expand All @@ -246,7 +246,7 @@ function itemTitle(itemType: CanonicalItemType): string | undefined {
case "plan":
return "Plan";
case "command_execution":
return "Ran command";
return started ? "Running command" : "Ran command";
case "file_change":
return "File change";
case "mcp_tool_call":
Expand Down Expand Up @@ -469,14 +469,15 @@ function mapItemLifecycle(
: lifecycle === "item.completed"
? "completed"
: undefined;
const title = itemTitle(itemType, lifecycle === "item.started");
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.

Updated commands prematurely labeled "Ran command" while still running

Medium Severity

itemTitle receives started = true only when lifecycle === "item.started". For item.updated events — which fire while a command is still executing — started is false, so the title becomes "Ran command". When merged with the tool.started entry, the label prematurely changes from "Running command" to "Ran command", undermining the PR's core feature of indicating running state.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 979f8c0. Configure here.


return {
...runtimeEventBase(event, canonicalThreadId),
type: lifecycle,
payload: {
itemType,
...(status ? { status } : {}),
...(itemTitle(itemType) ? { title: itemTitle(itemType) } : {}),
...(title ? { title } : {}),
...(detail ? { detail } : {}),
...(event.payload !== undefined ? { data: event.payload } : {}),
},
Expand Down
52 changes: 41 additions & 11 deletions apps/web/src/session-logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ export interface WorkLogEntry {
tone: "thinking" | "tool" | "info" | "error";
toolTitle?: string;
itemType?: ToolLifecycleItemType;
itemId?: string;
requestKind?: PendingApproval["requestKind"];
collapseKey?: string;
}

interface DerivedWorkLogEntry extends WorkLogEntry {
Expand Down Expand Up @@ -487,14 +489,13 @@ export function deriveWorkLogEntries(
const ordered = [...activities].toSorted(compareActivitiesByOrder);
const entries = ordered
.filter((activity) => (latestTurnId ? activity.turnId === latestTurnId : true))
.filter((activity) => activity.kind !== "tool.started")
.filter((activity) => activity.kind !== "task.started")
.filter((activity) => activity.kind !== "context-window.updated")
.filter((activity) => activity.summary !== "Checkpoint captured")
.filter((activity) => !isPlanBoundaryToolActivity(activity))
.map(toDerivedWorkLogEntry);
return collapseDerivedWorkLogEntries(entries).map(
({ activityKind: _activityKind, collapseKey: _collapseKey, ...entry }) => entry,
({ activityKind: _activityKind, ...entry }) => entry,
);
}

Expand Down Expand Up @@ -553,6 +554,7 @@ function toDerivedWorkLogEntry(activity: OrchestrationThreadActivity): DerivedWo
activityKind: activity.kind,
};
const itemType = extractWorkLogItemType(payload);
const itemId = extractWorkLogItemId(payload);
const requestKind = extractWorkLogRequestKind(payload);
if (detail) {
entry.detail = detail;
Expand All @@ -572,6 +574,9 @@ function toDerivedWorkLogEntry(activity: OrchestrationThreadActivity): DerivedWo
if (itemType) {
entry.itemType = itemType;
}
if (itemId) {
entry.itemId = itemId;
}
if (requestKind) {
entry.requestKind = requestKind;
}
Expand All @@ -589,13 +594,28 @@ function collapseDerivedWorkLogEntries(
entries: ReadonlyArray<DerivedWorkLogEntry>,
): DerivedWorkLogEntry[] {
const collapsed: DerivedWorkLogEntry[] = [];
const openLifecycleRowIndexByCollapseKey = new Map<string, number>();
for (const entry of entries) {
const previous = collapsed.at(-1);
if (previous && shouldCollapseToolLifecycleEntries(previous, entry)) {
collapsed[collapsed.length - 1] = mergeDerivedWorkLogEntries(previous, entry);
continue;
const collapseKey = entry.collapseKey;
if (collapseKey) {
const openIndex = openLifecycleRowIndexByCollapseKey.get(collapseKey);
if (openIndex !== undefined) {
const previous = collapsed[openIndex];
if (previous && shouldCollapseToolLifecycleEntries(previous, entry)) {
collapsed[openIndex] = mergeDerivedWorkLogEntries(previous, entry);
if (entry.activityKind === "tool.completed") {
openLifecycleRowIndexByCollapseKey.delete(collapseKey);
}
continue;
}
}
}

collapsed.push(entry);
if (collapseKey && (entry.activityKind === "tool.started" || entry.activityKind === "tool.updated")) {
openLifecycleRowIndexByCollapseKey.set(collapseKey, collapsed.length - 1);
continue;
}
}
return collapsed;
}
Expand All @@ -604,7 +624,7 @@ function shouldCollapseToolLifecycleEntries(
previous: DerivedWorkLogEntry,
next: DerivedWorkLogEntry,
): boolean {
if (previous.activityKind !== "tool.updated" && previous.activityKind !== "tool.completed") {
if (previous.activityKind !== "tool.started" && previous.activityKind !== "tool.updated" && previous.activityKind !== "tool.completed") {
return false;
}
if (next.activityKind !== "tool.updated" && next.activityKind !== "tool.completed") {
Expand Down Expand Up @@ -641,6 +661,8 @@ function mergeDerivedWorkLogEntries(
return {
...previous,
...next,
id: previous.id,
createdAt: previous.createdAt,
...(detail ? { detail } : {}),
...(command ? { command } : {}),
...(rawCommand ? { rawCommand } : {}),
Expand All @@ -665,19 +687,23 @@ function mergeChangedFiles(
}

function deriveToolLifecycleCollapseKey(entry: DerivedWorkLogEntry): string | undefined {
if (entry.activityKind !== "tool.updated" && entry.activityKind !== "tool.completed") {
if (entry.activityKind !== "tool.started" && entry.activityKind !== "tool.updated" && entry.activityKind !== "tool.completed") {
return undefined;
}
if (entry.toolCallId) {
return `tool:${entry.toolCallId}`;
}
const itemId = entry.itemId?.trim() ?? "";
if (itemId.length > 0) {
return itemId;
}
const normalizedLabel = normalizeCompactToolLabel(entry.toolTitle ?? entry.label);
const detail = entry.detail?.trim() ?? "";
const commandOrDetail = (entry.command ?? entry.detail)?.trim() ?? "";
const itemType = entry.itemType ?? "";
if (normalizedLabel.length === 0 && detail.length === 0 && itemType.length === 0) {
if (normalizedLabel.length === 0 && commandOrDetail.length === 0 && itemType.length === 0) {
return undefined;
}
return [itemType, normalizedLabel, detail].join("\u001f");
return [itemType, normalizedLabel, commandOrDetail].join("\u001f");
Comment thread
Minigamer42 marked this conversation as resolved.
}

function normalizeCompactToolLabel(value: string): string {
Expand Down Expand Up @@ -1030,6 +1056,10 @@ function extractWorkLogItemType(
return undefined;
}

function extractWorkLogItemId(payload: Record<string, unknown> | null): string | undefined {
return typeof payload?.itemId === "string" && payload.itemId.length > 0 ? payload.itemId : undefined;
}

function extractWorkLogRequestKind(
payload: Record<string, unknown> | null,
): WorkLogEntry["requestKind"] | undefined {
Expand Down
Loading