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
6 changes: 6 additions & 0 deletions server/app/domains/chat/api/history_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,12 @@ async def update_chat_history(
raise HTTPException(status_code=403, detail="You are not allowed to update this chat history")

update_data = data.model_dump(exclude_unset=True)
# The summary column is length-bounded; clamp defensively so an
# over-long value from any client truncates instead of failing the
# whole update (which would also discard the status change).
if isinstance(update_data.get("summary"), str):
summary_limit = ChatHistory.summary.type.length
update_data["summary"] = update_data["summary"][:summary_limit]
history.update_fields(update_data)
if "project_name" in update_data:
_sync_project_display_name(
Expand Down
18 changes: 15 additions & 3 deletions src/store/chatStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ import { legacySpaceIdForUser, useSpaceStore } from './spaceStore';
const API_CODE_TRIAL_LIMIT = '22';
const PROJECT_CONTEXT_MAX_CHARS = 24_000;
const PROJECT_CONTEXT_MAX_RUNS = 8;
// chat_history.summary is a bounded database column; an over-long value
// makes the whole history update fail server-side, which also discards the
// status change carried by the same request (a completed run then stays
// "ongoing"). Clamp before sending; the full text still lives in the run's
// end step.
const MAX_CHAT_HISTORY_SUMMARY_LENGTH = 1024;
const clampHistorySummary = (value: string | undefined | null): string =>
(value ?? '').slice(0, MAX_CHAT_HISTORY_SUMMARY_LENGTH);

type ConfirmedUserPromptSources = {
lastMessageContent?: unknown;
Expand Down Expand Up @@ -2367,7 +2375,9 @@ const chatStore = (initial?: Partial<ChatStore>) =>
agentMessages.data!.summary_task?.split('|')[0] || '';
const obj = {
project_name: projectName,
summary: agentMessages.data!.summary_task?.split('|')[1] || '',
summary: clampHistorySummary(
agentMessages.data!.summary_task?.split('|')[1]
),
status: 1,
tokens: getTokens(currentTaskId),
};
Expand Down Expand Up @@ -2750,7 +2760,9 @@ const chatStore = (initial?: Partial<ChatStore>) =>
tasks[currentTaskId].summaryTask.split('|')[0];
const obj = {
project_name: projectName,
summary: tasks[currentTaskId].summaryTask.split('|')[1],
summary: clampHistorySummary(
tasks[currentTaskId].summaryTask.split('|')[1]
),
status: 1,
tokens: getTokens(currentTaskId),
};
Expand Down Expand Up @@ -3618,7 +3630,7 @@ const chatStore = (initial?: Partial<ChatStore>) =>
const projectName = parts[0] || '';
const obj = {
project_name: projectName,
summary: completionSummary,
summary: clampHistorySummary(completionSummary),
status: wasStoppedByUser ? 1 : 2,
tokens: getTokens(currentTaskId),
};
Expand Down