Skip to content

Commit 796225e

Browse files
committed
clamp chat history summary to the column length so completion status is saved
1 parent b5ae10c commit 796225e

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

server/app/domains/chat/api/history_controller.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,10 @@ async def update_chat_history(
179179
raise HTTPException(status_code=403, detail="You are not allowed to update this chat history")
180180

181181
update_data = data.model_dump(exclude_unset=True)
182+
# Clamp summary to the column length so an over-long value cannot fail
183+
# the UPDATE and roll back the accompanying status change.
184+
if update_data.get("summary"):
185+
update_data["summary"] = update_data["summary"][:1024]
182186
history.update_fields(update_data)
183187
if "project_name" in update_data:
184188
_sync_project_display_name(

src/store/chatStore.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,11 @@ async function uploadTaskFiles(
627627
return results;
628628
}
629629

630+
/** Max length the server stores for a chat history summary; longer values
631+
* are rejected by the database, which would roll back the status update sent
632+
* with it. The full text is preserved in the task's end step. */
633+
const MAX_CHAT_HISTORY_SUMMARY_LENGTH = 1024;
634+
630635
export interface StartTaskOptions {
631636
preserveTaskId?: boolean;
632637
skipHistoryCreate?: boolean;
@@ -2367,7 +2372,9 @@ const chatStore = (initial?: Partial<ChatStore>) =>
23672372
agentMessages.data!.summary_task?.split('|')[0] || '';
23682373
const obj = {
23692374
project_name: projectName,
2370-
summary: agentMessages.data!.summary_task?.split('|')[1] || '',
2375+
summary: (
2376+
agentMessages.data!.summary_task?.split('|')[1] || ''
2377+
).slice(0, MAX_CHAT_HISTORY_SUMMARY_LENGTH),
23712378
status: 1,
23722379
tokens: getTokens(currentTaskId),
23732380
};
@@ -2750,7 +2757,9 @@ const chatStore = (initial?: Partial<ChatStore>) =>
27502757
tasks[currentTaskId].summaryTask.split('|')[0];
27512758
const obj = {
27522759
project_name: projectName,
2753-
summary: tasks[currentTaskId].summaryTask.split('|')[1],
2760+
summary: (
2761+
tasks[currentTaskId].summaryTask.split('|')[1] || ''
2762+
).slice(0, MAX_CHAT_HISTORY_SUMMARY_LENGTH),
27542763
status: 1,
27552764
tokens: getTokens(currentTaskId),
27562765
};
@@ -3618,7 +3627,10 @@ const chatStore = (initial?: Partial<ChatStore>) =>
36183627
const projectName = parts[0] || '';
36193628
const obj = {
36203629
project_name: projectName,
3621-
summary: completionSummary,
3630+
summary: completionSummary.slice(
3631+
0,
3632+
MAX_CHAT_HISTORY_SUMMARY_LENGTH
3633+
),
36223634
status: wasStoppedByUser ? 1 : 2,
36233635
tokens: getTokens(currentTaskId),
36243636
};

0 commit comments

Comments
 (0)