feat: add LETTA_BACKFILL env var to disable message history backfilling (#504)
This commit is contained in:
@@ -10,6 +10,16 @@ import { debugWarn } from "../utils/debug";
|
||||
// Number of recent messages to backfill when resuming a session
|
||||
const MESSAGE_HISTORY_LIMIT = 15;
|
||||
|
||||
/**
|
||||
* Check if message backfilling is enabled via LETTA_BACKFILL env var.
|
||||
* Defaults to true. Set LETTA_BACKFILL=0 or LETTA_BACKFILL=false to disable.
|
||||
*/
|
||||
function isBackfillEnabled(): boolean {
|
||||
const val = process.env.LETTA_BACKFILL;
|
||||
// Default to enabled (true) - only disable if explicitly set to "0" or "false"
|
||||
return val !== "0" && val !== "false";
|
||||
}
|
||||
|
||||
export interface ResumeData {
|
||||
pendingApproval: ApprovalRequest | null; // Deprecated: use pendingApprovals
|
||||
pendingApprovals: ApprovalRequest[];
|
||||
@@ -63,6 +73,14 @@ export async function getResumeData(
|
||||
"check-approval",
|
||||
`No in-context messages (message_ids empty/null) - no pending approvals`,
|
||||
);
|
||||
// Skip backfill if disabled via LETTA_BACKFILL=false
|
||||
if (!isBackfillEnabled()) {
|
||||
return {
|
||||
pendingApproval: null,
|
||||
pendingApprovals: [],
|
||||
messageHistory: [],
|
||||
};
|
||||
}
|
||||
const historyCount = Math.min(MESSAGE_HISTORY_LIMIT, messages.length);
|
||||
let messageHistory = messages.slice(-historyCount);
|
||||
if (messageHistory[0]?.message_type === "tool_return_message") {
|
||||
@@ -198,6 +216,11 @@ export async function getResumeData(
|
||||
}
|
||||
|
||||
// Get last N messages for backfill (always use cursor messages for history)
|
||||
// Skip backfill if disabled via LETTA_BACKFILL=false
|
||||
if (!isBackfillEnabled()) {
|
||||
return { pendingApproval, pendingApprovals, messageHistory: [] };
|
||||
}
|
||||
|
||||
const historyCount = Math.min(MESSAGE_HISTORY_LIMIT, messages.length);
|
||||
let messageHistory = messages.slice(-historyCount);
|
||||
|
||||
|
||||
@@ -6718,11 +6718,13 @@ Plan file path: ${planFilePath}`;
|
||||
});
|
||||
buffersRef.current.order.push(statusId);
|
||||
refreshDerived();
|
||||
commitEligibleLines(buffersRef.current);
|
||||
}
|
||||
}, [
|
||||
loadingState,
|
||||
continueSession,
|
||||
messageHistory.length,
|
||||
commitEligibleLines,
|
||||
columns,
|
||||
agentProvenance,
|
||||
agentState,
|
||||
@@ -7145,6 +7147,27 @@ Plan file path: ${planFilePath}`;
|
||||
</Box>
|
||||
)}
|
||||
|
||||
{/* Fallback approval UI when backfill is disabled (no liveItems) */}
|
||||
{liveItems.length === 0 && currentApproval && (
|
||||
<Box flexDirection="column">
|
||||
<InlineGenericApproval
|
||||
toolName={currentApproval.toolName}
|
||||
toolArgs={currentApproval.toolArgs}
|
||||
onApprove={() => handleApproveCurrent()}
|
||||
onApproveAlways={(scope) => handleApproveAlways(scope)}
|
||||
onDeny={(reason) => handleDenyCurrent(reason)}
|
||||
onCancel={handleCancelApprovals}
|
||||
isFocused={true}
|
||||
approveAlwaysText={
|
||||
currentApprovalContext?.approveAlwaysText
|
||||
}
|
||||
allowPersistence={
|
||||
currentApprovalContext?.allowPersistence ?? true
|
||||
}
|
||||
/>
|
||||
</Box>
|
||||
)}
|
||||
|
||||
{/* Subagent group display - shows running/completed subagents */}
|
||||
<SubagentGroupDisplay />
|
||||
</AnimationProvider>
|
||||
|
||||
Reference in New Issue
Block a user