Skip to content
Merged
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
1 change: 1 addition & 0 deletions assistant/src/__tests__/agent-loop-exit-reason.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ describe("AgentLoop exit-reason instrumentation", () => {
});

expect(events.map((e) => e.type)).toEqual([
"llm_call_started",
"usage",
"max_tokens_reached",
"message_complete",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ mock.module("../memory/conversation-crud.js", () => ({
getMessageById: () => null,
getLastUserTimestampBefore: () => 0,
reserveMessage: mock(async () => ({ id: "msg-reserve" })),
updateMessageContent: mock(() => {}),
}));

mock.module("../memory/conversation-queries.js", () => ({
Expand Down Expand Up @@ -193,6 +194,9 @@ mock.module("../agent/loop.js", () => ({
onEvent: (event: AgentEvent) => void,
_signal?: AbortSignal,
): Promise<Message[]> {
// Prime the assistant row anchor — production code emits this from
// `AgentLoop.run` just before `provider.sendMessage`.
await onEvent({ type: "llm_call_started" });
const history = [...messages];

// Simulate provider response with 2 tool_use blocks
Expand Down
33 changes: 33 additions & 0 deletions assistant/src/__tests__/conversation-agent-loop-overflow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,9 @@ describe("session-agent-loop overflow recovery (JARVIS-110)", () => {

let agentLoopCallCount = 0;
const agentLoopRun: AgentLoopRun = async (messages, onEvent) => {
// Prime the assistant row anchor — production code emits this from
// `AgentLoop.run` just before `provider.sendMessage`.
await onEvent({ type: "llm_call_started" });
agentLoopCallCount++;
if (agentLoopCallCount === 1) {
// Simulate: agent makes progress (tool calls + results added)
Expand Down Expand Up @@ -915,6 +918,9 @@ describe("session-agent-loop overflow recovery (JARVIS-110)", () => {
};

const agentLoopRun: AgentLoopRun = async (messages, onEvent) => {
// Prime the assistant row anchor — production code emits this from
// `AgentLoop.run` just before `provider.sendMessage`.
await onEvent({ type: "llm_call_started" });
callCount++;
if (callCount === 1) {
// Provider rejects with "prompt is too long: 242201 tokens > 200000"
Expand Down Expand Up @@ -1037,6 +1043,9 @@ describe("session-agent-loop overflow recovery (JARVIS-110)", () => {
};

const agentLoopRun: AgentLoopRun = async (messages, onEvent) => {
// Prime the assistant row anchor — production code emits this from
// `AgentLoop.run` just before `provider.sendMessage`.
await onEvent({ type: "llm_call_started" });
callCount++;
if (callCount === 1) {
// Provider rejects: actual tokens 242201, way above estimate of 185k
Expand Down Expand Up @@ -1162,6 +1171,9 @@ describe("session-agent-loop overflow recovery (JARVIS-110)", () => {
};

const agentLoopRun: AgentLoopRun = async (messages, onEvent) => {
// Prime the assistant row anchor — production code emits this from
// `AgentLoop.run` just before `provider.sendMessage`.
await onEvent({ type: "llm_call_started" });
callCount++;
onEvent({
type: "message_complete",
Expand Down Expand Up @@ -1250,6 +1262,9 @@ describe("session-agent-loop overflow recovery (JARVIS-110)", () => {

let agentLoopCallCount = 0;
const agentLoopRun: AgentLoopRun = async (messages, onEvent) => {
// Prime the assistant row anchor — production code emits this from
// `AgentLoop.run` just before `provider.sendMessage`.
await onEvent({ type: "llm_call_started" });
agentLoopCallCount++;
if (agentLoopCallCount === 1) {
// Agent makes progress (tool calls succeed, messages grow)
Expand Down Expand Up @@ -1441,6 +1456,9 @@ describe("session-agent-loop overflow recovery (JARVIS-110)", () => {
_requestId,
onCheckpoint,
) => {
// Prime the assistant row anchor — production code emits this from
// `AgentLoop.run` just before `provider.sendMessage`.
await onEvent({ type: "llm_call_started" });
agentLoopCallCount++;

if (agentLoopCallCount === 1) {
Expand Down Expand Up @@ -1626,6 +1644,9 @@ describe("session-agent-loop overflow recovery (JARVIS-110)", () => {
_requestId,
onCheckpoint,
) => {
// Prime the assistant row anchor — production code emits this from
// `AgentLoop.run` just before `provider.sendMessage`.
await onEvent({ type: "llm_call_started" });
agentLoopCallCount++;

if (agentLoopCallCount === 1) {
Expand Down Expand Up @@ -1801,6 +1822,9 @@ describe("session-agent-loop overflow recovery (JARVIS-110)", () => {
_requestId,
onCheckpoint,
) => {
// Prime the assistant row anchor — production code emits this from
// `AgentLoop.run` just before `provider.sendMessage`.
await onEvent({ type: "llm_call_started" });
agentLoopCallCount++;

// Every call: simulate tool progress then yield at checkpoint
Expand Down Expand Up @@ -1962,6 +1986,9 @@ describe("session-agent-loop overflow recovery (JARVIS-110)", () => {
_requestId,
onCheckpoint,
) => {
// Prime the assistant row anchor — production code emits this from
// `AgentLoop.run` just before `provider.sendMessage`.
await onEvent({ type: "llm_call_started" });
agentLoopCallCount++;

const withProgress: Message[] = [
Expand Down Expand Up @@ -2194,6 +2221,9 @@ describe("session-agent-loop overflow recovery (JARVIS-110)", () => {
};

const agentLoopRun: AgentLoopRun = async (messages, onEvent) => {
// Prime the assistant row anchor — production code emits this from
// `AgentLoop.run` just before `provider.sendMessage`.
await onEvent({ type: "llm_call_started" });
onEvent({
type: "message_complete",
message: {
Expand Down Expand Up @@ -2297,6 +2327,9 @@ describe("session-agent-loop overflow recovery (JARVIS-110)", () => {
_requestId,
onCheckpoint,
) => {
// Prime the assistant row anchor — production code emits this from
// `AgentLoop.run` just before `provider.sendMessage`.
await onEvent({ type: "llm_call_started" });
agentLoopCallCount++;

const withProgress: Message[] = [
Expand Down
Loading
Loading