Skip to content
Draft
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
4 changes: 3 additions & 1 deletion src/core/agent.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ static int compact_session_via_llm(const char *session_id, char *session_buf, si
if (root) cJSON_Delete(root);
return -1;
}
int to_summarize_n = msg_count - max_ctx;
/* Tail keeps max_ctx-1 messages, so the summary must include index
* msg_count-max_ctx. Stopping one short drops that turn from SQLite. */
int to_summarize_n = msg_count - max_ctx + 1;
char *source_buf = malloc(SUMMARY_SOURCE_MAX);
if (!source_buf) { cJSON_Delete(root); return -1; }
source_buf[0] = '\0';
Expand Down
14 changes: 13 additions & 1 deletion tests/test_agent.c
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,14 @@ static int test_session_persisted_after_exchange(void)
}

static int compaction_call_count;
static int compaction_init(const config_t *cfg) { (void)cfg; compaction_call_count = 0; return 0; }
static int compaction_source_has_boundary;
static int compaction_init(const config_t *cfg)
{
(void)cfg;
compaction_call_count = 0;
compaction_source_has_boundary = 0;
return 0;
}
static int compaction_chat(const provider_message_t *messages, size_t message_count,
const provider_tool_def_t *tools, size_t tool_count, provider_response_t *response)
{
Expand All @@ -377,6 +384,9 @@ static int compaction_chat(const provider_message_t *messages, size_t message_co
response->tool_calls_count = 0;
compaction_call_count++;
if (compaction_call_count == 1) {
const char *src = (message_count >= 2 && messages[1].content) ? messages[1].content : "";
/* msg_10 is the index the summary window and the kept tail both skipped. */
compaction_source_has_boundary = strstr(src, "msg_10\n") != NULL;
response->content = strdup("Summary of earlier conversation.");
return 0;
}
Expand Down Expand Up @@ -442,6 +452,8 @@ static int test_context_compaction_when_history_exceeds_max(void)
}
if (!found_summary) goto cleanup;
if (!found_tail) goto cleanup;
/* Boundary message must be in the summary source; the tail starts at msg_11. */
if (!compaction_source_has_boundary) goto cleanup;
failed = 0;
cleanup:
config_free(cfg);
Expand Down
Loading