🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
fix(agent): show a clearer 8-hour write-lock notice in the assistant (#16143)
Lysander Kiesel8b81b3e8d1e4
diff --git a/packages/shared/src/in-app-agent/constants.ts b/packages/shared/src/in-app-agent/constants.tsindex afd07f4f39..d8b6881248 100644--- a/packages/shared/src/in-app-agent/constants.ts+++ b/packages/shared/src/in-app-agent/constants.ts@@ -17,6 +17,12 @@ export const IN_APP_AGENT_MCP_TOOL_OVERRIDE_HEADER =export const IN_APP_AGENT_LOCAL_SANDBOX_IMAGE ="langfuse-in-app-agent-sandbox:latest";+export const IN_APP_AGENT_SANDBOX_CONVERSATION_WRITE_LOCK_MESSAGE =+ "This conversation has reached the 8-hour limit. Please start a new conversation.";++export const IN_APP_AGENT_GENERIC_ERROR_MESSAGE =+ "An error occurred. Please try again or start a new conversation.";+// Observation ids stay equal to the per-turn run id so persisted messages,// feedback, and traced generations all point at the same Langfuse observation.export const getInAppAgentInstrumentationObservationId = (runId: string) =>diff --git a/web/src/__tests__/server/in-app-agent-background-run.servertest.ts b/web/src/__tests__/server/in-app-agent-background-run.servertest.tsindex 873f503b59..a9df553ae7 100644--- a/web/src/__tests__/server/in-app-agent-background-run.servertest.ts+++ b/web/src/__tests__/server/in-app-agent-background-run.servertest.ts@@ -21,6 +21,7 @@ import {createInAppAgentConversationId,createInAppAgentRunId,IN_APP_AGENT_APPROVAL_DECISION_EVENT_NAME,+ IN_APP_AGENT_SANDBOX_CONVERSATION_WRITE_LOCK_MESSAGE,} from "@langfuse/shared/in-app-agent";import { ensureOwnedConversation } from "@langfuse/shared/in-app-agent/server/persistence";import { env as sharedEnv } from "@langfuse/shared/src/env";@@ -808,8 +809,7 @@ describe("in-app agent background runs", () => {}),).rejects.toMatchObject({code: "PRECONDITION_FAILED",- message:- "Sandbox-enabled conversations become read-only after 8 hours. Start a new conversation to continue.",+ message: IN_APP_AGENT_SANDBOX_CONVERSATION_WRITE_LOCK_MESSAGE,});await expect(diff --git a/web/src/features/in-app-agent/components/ControlledInAppAgentWindow.tsx b/web/src/features/in-app-agent/components/ControlledInAppAgentWindow.tsxindex e5b509ea78..272060c42d 100644--- a/web/src/features/in-app-agent/components/ControlledInAppAgentWindow.tsx+++ b/web/src/features/in-app-agent/components/ControlledInAppAgentWindow.tsx@@ -23,9 +23,6 @@ import {import { InAppAgentRunStatus } from "@langfuse/shared";import { isUnsettledInAppAgentRunStatus } from "@langfuse/shared/in-app-agent";-const SANDBOX_CONVERSATION_WRITE_LOCK_MESSAGE =- "Sandbox-enabled conversations become read-only after 8 hours. Start a new conversation to continue.";-function getBackgroundRunNotice(run: BackgroundExecutionRunView | null,): string | null {@@ -110,7 +107,10 @@ export function ControlledInAppAgentWindow(shouldFlush: error !== null || isCancellingRun || shouldFlushCancelledRun,});const windowExecutionUi: InAppAgentWindowExecutionUi = {- notice: getBackgroundRunNotice(execution.run),+ notice:+ selectedConversationIsWriteLocked || error?.type === "write_lock"+ ? null+ : getBackgroundRunNotice(execution.run),stop:execution.run && isCancellableBackgroundRun(execution.run.status)? {@@ -124,9 +124,12 @@ export function ControlledInAppAgentWindow(};// Only a read-only conversation disables the composer outright. An assistant// turn -- including one paused on an approval -- blocks submission but leaves- // the draft editable.+ // the draft editable. A server write-lock rejection is treated the same as+ // the cached flag, so a stale conversation query cannot leave the composer open.const isConversationInteractionDisabled =- selectedConversationIsWriteLocked || isSelectedConversationHydrating;+ selectedConversationIsWriteLocked ||+ isSelectedConversationHydrating ||+ error?.type === "write_lock";const isAssistantTurnInProgress =isRunning ||isAnimating ||@@ -154,10 +157,7 @@ export function ControlledInAppAgentWindow((pendingToolApprovals.length > 0 ||displayedPendingToolApprovals.length > 0);const displayError = selectedConversationIsWriteLocked- ? ({- type: "generic",- message: SANDBOX_CONVERSATION_WRITE_LOCK_MESSAGE,- } as const)+ ? ({ type: "write_lock" } as const): error;const screenContextDescription = useMemo(() => getInAppAgentScreenContextDescription(router.asPath),@@ -205,7 +205,9 @@ export function ControlledInAppAgentWindow(isExpanded={props.isExpanded}isConversationInteractionDisabled={isConversationInteractionDisabled}isSelectedConversationHydrating={isSelectedConversationHydrating}- disablePendingToolApprovalActions={selectedConversationIsWriteLocked}+ disablePendingToolApprovalActions={+ selectedConversationIsWriteLocked || error?.type === "write_lock"+ }messages={drawerMessages}quickActionContext={quickActionContext}focusedQuickActions={focusedQuickActions}diff --git a/web/src/features/in-app-agent/components/InAppAgentWindow.clienttest.tsx b/web/src/features/in-app-agent/components/InAppAgentWindow.clienttest.tsxindex c084dcf4f7..11d5670d01 100644--- a/web/src/features/in-app-agent/components/InAppAgentWindow.clienttest.tsx+++ b/web/src/features/in-app-agent/components/InAppAgentWindow.clienttest.tsx@@ -7,12 +7,14 @@ import {} from "@testing-library/react";import { ScanSearch } from "lucide-react";import { InAppAgentRunStatus } from "@langfuse/shared";+import { IN_APP_AGENT_SANDBOX_CONVERSATION_WRITE_LOCK_MESSAGE } from "@langfuse/shared/in-app-agent";import { TooltipProvider } from "@/src/components/ui/tooltip";import {InAppAgentWindow,type InAppAgentWindowProps,} from "./InAppAgentWindow";import { ControlledInAppAgentWindow } from "./ControlledInAppAgentWindow";+import type { InAppAgentError } from "./utils/utils";const capture = vi.fn();const controlledAgent = vi.hoisted(() => ({@@ -20,7 +22,7 @@ const controlledAgent = vi.hoisted(() => ({conversations: [] as Array<{ id: string; title: string | null }>,activityByConversationId: new Map<string, { state: string }>(),attentionCount: 0,- error: null,+ error: null as InAppAgentError | null,hasMoreConversations: false,isLoadingMoreConversations: false,isRunning: true,@@ -46,6 +48,7 @@ const controlledAgent = vi.hoisted(() => ({selectedConversationId: undefined,selectedConversationTitle: null,selectedConversationIsWriteLocked: false,+ selectConversation: vi.fn(),submit: vi.fn(),submitFeedback: vi.fn(),},@@ -298,6 +301,12 @@ describe("ControlledInAppAgentWindow composer", () => {controlledAgent.value.isSubmitting = false;controlledAgent.value.pendingToolApprovals = [];controlledAgent.value.selectedConversationIsWriteLocked = false;+ controlledAgent.value.selectConversation = vi.fn();+ controlledAgent.value.execution = {+ run: null,+ isCancelling: false,+ cancel: vi.fn(),+ };});it("keeps a draft editable but prevents submitting it while an assistant turn is active", () => {@@ -362,9 +371,19 @@ describe("ControlledInAppAgentWindow composer", () => {).toBeEnabled();});- it("lets you leave a read-only conversation", () => {+ it("hides a failed-run notice when the conversation is write-locked", () => {controlledAgent.value.isRunning = false;controlledAgent.value.selectedConversationIsWriteLocked = true;+ controlledAgent.value.execution = {+ run: {+ id: "run-1",+ status: InAppAgentRunStatus.FAILED,+ errorCode: null,+ cancelRequested: false,+ },+ isCancelling: false,+ cancel: vi.fn(),+ };render(<TooltipProvider>@@ -378,14 +397,35 @@ describe("ControlledInAppAgentWindow composer", () => {);expect(- screen.getByRole("textbox", { name: "Message the assistant" }),- ).toBeDisabled();+ screen.getByText(IN_APP_AGENT_SANDBOX_CONVERSATION_WRITE_LOCK_MESSAGE),+ ).toBeInTheDocument();expect(- screen.getByRole("button", { name: "Start new conversation" }),- ).toBeEnabled();+ screen.queryByText("The run failed. Try again."),+ ).not.toBeInTheDocument();+ });++ it("locks the composer when a write-lock rejection arrives before the cached flag", () => {+ controlledAgent.value.isRunning = false;+ controlledAgent.value.selectedConversationIsWriteLocked = false;+ controlledAgent.value.error = { type: "write_lock" };++ render(+ <TooltipProvider>+ <ControlledInAppAgentWindow+ isExpanded={false}+ onClose={vi.fn()}+ onDeleteConversation={vi.fn()}+ onExpandedChange={vi.fn()}+ />+ </TooltipProvider>,+ );+expect(- screen.getByRole("button", { name: /^Conversation history/ }),- ).toBeEnabled();+ screen.getByText(IN_APP_AGENT_SANDBOX_CONVERSATION_WRITE_LOCK_MESSAGE),+ ).toBeInTheDocument();+ expect(+ screen.getByRole("textbox", { name: "Message the assistant" }),+ ).toBeDisabled();});});diff --git a/web/src/features/in-app-agent/components/InAppAgentWindow.stories.tsx b/web/src/features/in-app-agent/components/InAppAgentWindow.stories.tsxindex 743984ab60..870c0a8aba 100644--- a/web/src/features/in-app-agent/components/InAppAgentWindow.stories.tsx+++ b/web/src/features/in-app-agent/components/InAppAgentWindow.stories.tsx@@ -1,7 +1,11 @@import preview from "../../../../.storybook/preview";import { type ReactNode, useEffect, useRef, useState } from "react";import { expect, fn, screen, userEvent, waitFor, within } from "storybook/test";-import type { AgUiMessage } from "@langfuse/shared/in-app-agent";+import {+ IN_APP_AGENT_GENERIC_ERROR_MESSAGE,+ IN_APP_AGENT_SANDBOX_CONVERSATION_WRITE_LOCK_MESSAGE,+ type AgUiMessage,+} from "@langfuse/shared/in-app-agent";import {InAppAgentWindow,type InAppAgentWindowMessage,@@ -1402,7 +1406,7 @@ export const Error = meta.story({args: {error: {type: "generic",- message: "Assistant is not enabled for this user",+ message: "Internal sandbox bridge timeout",},messages: [{@@ -1415,6 +1419,55 @@ export const Error = meta.story({},],},+ play: async ({ canvasElement }) => {+ const canvas = within(canvasElement);+ const alert = canvas.getByRole("alert");++ await expect(alert).toHaveTextContent(IN_APP_AGENT_GENERIC_ERROR_MESSAGE);+ await expect(alert).not.toHaveTextContent(+ "Internal sandbox bridge timeout",+ );+ await expect(+ canvas.getByRole("textbox", { name: "Message the assistant" }),+ ).toBeEnabled();+ await expect(within(alert).queryByRole("button")).not.toBeInTheDocument();+ },+});++export const WriteLocked = meta.story({+ args: {+ error: { type: "write_lock" },+ isConversationInteractionDisabled: true,+ selectedConversationId: "conversation-1",+ messages: [+ {+ id: "user-1",+ role: "user",+ content: {+ type: "text",+ text: "Help me inspect this trace.",+ },+ },+ ],+ },+ play: async ({ canvasElement }) => {+ const canvas = within(canvasElement);+ const alert = canvas.getByRole("alert");++ await expect(alert).toHaveTextContent(+ IN_APP_AGENT_SANDBOX_CONVERSATION_WRITE_LOCK_MESSAGE,+ );+ await expect(+ canvas.getByRole("textbox", { name: "Message the assistant" }),+ ).toBeDisabled();+ await expect(+ canvas.getByRole("button", { name: /^Conversation history/ }),+ ).toBeEnabled();+ await expect(within(alert).queryByRole("button")).not.toBeInTheDocument();+ await expect(+ canvas.getByRole("button", { name: "Start new conversation" }),+ ).toBeEnabled();+ },});/**diff --git a/web/src/features/in-app-agent/components/InAppAgentWindow.tsx b/web/src/features/in-app-agent/components/InAppAgentWindow.tsxindex 94750dbefb..8ecaaa3ea3 100644--- a/web/src/features/in-app-agent/components/InAppAgentWindow.tsx+++ b/web/src/features/in-app-agent/components/InAppAgentWindow.tsx@@ -22,6 +22,7 @@ import {Plus,SendHorizontal,Square,+ TriangleAlert,Trash2,X,} from "lucide-react";@@ -47,9 +48,11 @@ import {type InAppAgentMessageContent,type InAppAgentMessageRole,} from "./InAppAgentMessage";-import type {- InAppAgentMessageFeedbackValue,- InAppAgentMessageSource,+import {+ IN_APP_AGENT_GENERIC_ERROR_MESSAGE,+ IN_APP_AGENT_SANDBOX_CONVERSATION_WRITE_LOCK_MESSAGE,+ type InAppAgentMessageFeedbackValue,+ type InAppAgentMessageSource,} from "@langfuse/shared/in-app-agent";import { deduplicateBy } from "@/src/utils/arrays";import type { InAppAgentScreenContextDescription } from "@/src/features/in-app-agent/context";@@ -914,22 +917,40 @@ function InAppAgentRateLimitError({);}-function InAppAgentGenericError({- error,+function InAppAgentIssueNotice({isExpanded,+ variant,}: {- error: Extract<InAppAgentError, { type: "generic" }>;isExpanded: boolean;+ variant: "error" | "write_lock";}) {+ const isWriteLock = variant === "write_lock";+return (- <div- role="alert"- className={cn(- "border-destructive/40 dark:bg-destructive dark:border-destructive-foreground/20 bg-destructive/10 dark:text-destructive-foreground text-destructive rounded-lg border px-2 py-1",- isExpanded ? "text-sm" : "text-xs",- )}- >- {error.message}+ <div className="shrink-0 px-2 pb-2">+ <div className={cn(isExpanded && "mx-auto max-w-3xl")}>+ <p+ role="alert"+ className={cn(+ "flex w-full items-center gap-2 rounded-lg border px-2 py-1",+ isWriteLock+ ? "border-border bg-muted/60 text-foreground"+ : "border-destructive/40 bg-destructive/10 text-destructive",+ isExpanded ? "text-sm" : "text-xs",+ )}+ >+ {isWriteLock ? (+ <TriangleAlert aria-hidden="true" className="size-3 shrink-0" />+ ) : (+ <Info aria-hidden="true" className="size-3 shrink-0" />+ )}+ <span className="min-w-0 flex-1">+ {isWriteLock+ ? IN_APP_AGENT_SANDBOX_CONVERSATION_WRITE_LOCK_MESSAGE+ : IN_APP_AGENT_GENERIC_ERROR_MESSAGE}+ </span>+ </p>+ </div></div>);}@@ -1451,10 +1472,6 @@ export function InAppAgentWindow(props: InAppAgentWindowProps) {);})}</ol>-- {error?.type === "generic" && (- <InAppAgentGenericError error={error} isExpanded={isExpanded} />- )}</div></ConversationScroller>{pendingToolCalls.length > 0 ? (@@ -1504,6 +1521,12 @@ export function InAppAgentWindow(props: InAppAgentWindowProps) {</div></div>) : null}+ {(error?.type === "generic" || error?.type === "write_lock") && (+ <InAppAgentIssueNotice+ isExpanded={isExpanded}+ variant={error.type === "write_lock" ? "write_lock" : "error"}+ />+ )}{backgroundHint.isVisible && props.onClose ? (<InAppAgentBackgroundHintisExpanded={isExpanded}diff --git a/web/src/features/in-app-agent/components/InAppAiAgentProvider.tsx b/web/src/features/in-app-agent/components/InAppAiAgentProvider.tsxindex 4cad2cce5f..8e593709d4 100644--- a/web/src/features/in-app-agent/components/InAppAiAgentProvider.tsx+++ b/web/src/features/in-app-agent/components/InAppAiAgentProvider.tsx@@ -19,8 +19,8 @@ import useSessionStorage from "@/src/components/useSessionStorage";import {createInAppAgentConversationId,createInAppAgentMessageId,+ IN_APP_AGENT_REDIRECT_TOOL_NAME,} from "@langfuse/shared/in-app-agent";-import { IN_APP_AGENT_REDIRECT_TOOL_NAME } from "@langfuse/shared/in-app-agent";import {AgUiMessageSchema,dropEmptyAssistantMessages,@@ -86,8 +86,6 @@ const SELECTED_CONVERSATION_STORAGE_KEY_PREFIX ="langfuse:in-app-ai-agent-selected-conversation";const OPEN_STORAGE_KEY_PREFIX = "langfuse:in-app-ai-agent-open";const FEEDBACK_STORAGE_KEY_PREFIX = "langfuse:in-app-ai-agent-feedback";-const SANDBOX_CONVERSATION_WRITE_LOCK_MESSAGE =- "Sandbox-enabled conversations become read-only after 8 hours. Start a new conversation to continue.";const EMPTY_MESSAGES: AgUiMessage[] = [];const EMPTY_BACKGROUND_VIEW: BackgroundExecutionView = {messages: EMPTY_MESSAGES,@@ -1078,10 +1076,7 @@ function InAppAiAgentProviderInner({}if (!startsNewConversation && selectedConversationIsWriteLocked) {- setError({- type: "generic",- message: SANDBOX_CONVERSATION_WRITE_LOCK_MESSAGE,- });+ setError({ type: "write_lock" });return false;}@@ -1403,10 +1398,7 @@ function InAppAiAgentProviderInner({approvalScope: "once" | "conversation" = "once",) => {if (selectedConversationIsWriteLocked) {- setError({- type: "generic",- message: SANDBOX_CONVERSATION_WRITE_LOCK_MESSAGE,- });+ setError({ type: "write_lock" });return;}diff --git a/web/src/features/in-app-agent/components/utils/utils.clienttest.ts b/web/src/features/in-app-agent/components/utils/utils.clienttest.tsindex b4b9dcfe70..f357057f23 100644--- a/web/src/features/in-app-agent/components/utils/utils.clienttest.ts+++ b/web/src/features/in-app-agent/components/utils/utils.clienttest.ts@@ -1,5 +1,8 @@import type { AgUiMessage } from "@langfuse/shared/in-app-agent";-import { IN_APP_AGENT_REDIRECT_TOOL_NAME } from "@langfuse/shared/in-app-agent";+import {+ IN_APP_AGENT_REDIRECT_TOOL_NAME,+ IN_APP_AGENT_SANDBOX_CONVERSATION_WRITE_LOCK_MESSAGE,+} from "@langfuse/shared/in-app-agent";import {IN_APP_AGENT_LANGFUSE_MCP_TOOL_NAMES,IN_APP_AGENT_SANDBOX_TOOL_NAMES,@@ -242,6 +245,15 @@ describe("getInAppAgentError", () => {});});+ it("maps a write-lock rejection to the write-lock notice", () => {+ expect(+ getInAppAgentError(+ { message: IN_APP_AGENT_SANDBOX_CONVERSATION_WRITE_LOCK_MESSAGE },+ now,+ ),+ ).toEqual({ type: "write_lock" });+ });+it("does not classify malformed embedded JSON as a rate limit", () => {const message = 'Failed to initialize Langfuse MCP: {"code":"rate_limited"';diff --git a/web/src/features/in-app-agent/components/utils/utils.ts b/web/src/features/in-app-agent/components/utils/utils.tsindex c85625d699..2c4d7f2f0e 100644--- a/web/src/features/in-app-agent/components/utils/utils.ts+++ b/web/src/features/in-app-agent/components/utils/utils.ts@@ -6,6 +6,7 @@ import { deduplicateBy } from "@/src/utils/arrays";import { safeJsonParse, stableJsonStringify } from "@langfuse/shared";import {IN_APP_AGENT_REDIRECT_TOOL_NAME,+ IN_APP_AGENT_SANDBOX_CONVERSATION_WRITE_LOCK_MESSAGE,IN_APP_AGENT_TOOL_REJECTION_ERROR_CODE,} from "@langfuse/shared/in-app-agent";import {@@ -19,6 +20,7 @@ import {export type InAppAgentError =| { type: "generic"; message: string }+ | { type: "write_lock" }| { type: "rate_limit"; retryAt: number };const InAppAiAgentMessageSchema = AgUiMessageSchema.and(@@ -348,6 +350,10 @@ export function getInAppAgentError(};}+ if (message.includes(IN_APP_AGENT_SANDBOX_CONVERSATION_WRITE_LOCK_MESSAGE)) {+ return { type: "write_lock" };+ }+return { type: "generic", message };}diff --git a/web/src/features/in-app-agent/server/backgroundRunService.ts b/web/src/features/in-app-agent/server/backgroundRunService.tsindex 64d1347261..50c5773c34 100644--- a/web/src/features/in-app-agent/server/backgroundRunService.ts+++ b/web/src/features/in-app-agent/server/backgroundRunService.ts@@ -20,6 +20,7 @@ import { deleteApiKeyFromDb } from "@langfuse/shared/src/server/auth/apiKeys";import {createInAppAgentMessageId,createInAppAgentRunId,+ IN_APP_AGENT_SANDBOX_CONVERSATION_WRITE_LOCK_MESSAGE,parseInAppAgentApprovalDecisionEvent,type AgUiRunAgentInput,} from "@langfuse/shared/in-app-agent";@@ -49,9 +50,6 @@ import { assertInAppAgentRunCapacity } from "@/src/features/in-app-agent/server/import { resolveInAppAgentRunContext } from "@/src/features/in-app-agent/server/runContext";import { getConversationSnapshotFromEvents } from "@/src/features/in-app-agent/server/conversationSnapshot";-const SANDBOX_CONVERSATION_WRITE_LOCK_MESSAGE =- "Sandbox-enabled conversations become read-only after 8 hours. Start a new conversation to continue.";-export async function getBackgroundConversationSnapshot(params: {prisma: PrismaClient;projectId: string;@@ -240,7 +238,7 @@ export async function startBackgroundRun(params: {throw new BaseError("PreconditionFailedError",412,- SANDBOX_CONVERSATION_WRITE_LOCK_MESSAGE,+ IN_APP_AGENT_SANDBOX_CONVERSATION_WRITE_LOCK_MESSAGE,true,);}@@ -405,7 +403,7 @@ export async function decideBackgroundApproval(params: {throw new BaseError("PreconditionFailedError",412,- SANDBOX_CONVERSATION_WRITE_LOCK_MESSAGE,+ IN_APP_AGENT_SANDBOX_CONVERSATION_WRITE_LOCK_MESSAGE,true,);}diff --git a/worker/src/features/in-app-agent/executeInAppAgentRun.ts b/worker/src/features/in-app-agent/executeInAppAgentRun.tsindex 823ea21c1a..e0a8311a1d 100644--- a/worker/src/features/in-app-agent/executeInAppAgentRun.ts+++ b/worker/src/features/in-app-agent/executeInAppAgentRun.ts@@ -18,6 +18,7 @@ import {} from "@langfuse/shared/src/server/auth/apiKeys";import {getInAppAgentInstrumentationTraceId,+ IN_APP_AGENT_SANDBOX_CONVERSATION_WRITE_LOCK_MESSAGE,type AgUiEvent,type AgUiRunAgentInput,type InAppAgentToolApprovalRequest,@@ -224,7 +225,7 @@ export async function executeInAppAgentRun(params: {})) {throw new InAppAgentRunInitError(- "Conversation is write-locked (sandbox session expired)",+ IN_APP_AGENT_SANDBOX_CONVERSATION_WRITE_LOCK_MESSAGE,);}