Skip to content

Commit 1167972

Browse files
committed
fix(mcp): give the over-budget error a retry value, and say the peak is not the requirement
v0.10.9 introduces Decision A: an over-budget index attempt fails whole with a named error instead of thrashing. The error told the caller to "Raise CBM_MEM_BUDGET_MB" but not to what, so the obvious next move is to read peak_rss_mb and retry just above it. That move fails, every time, by construction. The abort fires WHEN resident memory crosses the budget, so peak_rss_mb is pinned just above the budget -- it is where indexing was stopped, not what the repository needs. Measured on the linux kernel (94521 files, 43.1M LOC) while benching v0.10.9: default budget 24576 MB -> aborted, peak_rss_mb 25622 completing the same index actually took 31.75 GB So the reported peak understates the real requirement by 24%, and 1.32x the budget was needed. A caller retrying at peak+10% would have burned another 30 seconds to fail again with a nearly identical message. The response now carries suggested_budget_mb (1.5x the current budget, which would have cleared the kernel case) and the hint says plainly that peak_rss_mb is a floor, not a target. Computed as (3*b+1)/2 rather than b + b/2: integer division makes the latter degenerate to b at b == 1, so the suggestion would have repeated the budget that just failed -- the extended test caught exactly that. Not changed: the abort itself, the backpressure ladder, and worker cleanup. A clean test confirmed workers do NOT survive the abort (process count 2 before, 2 after, both idle at 0% CPU), so there was nothing to fix there. tests/test_mcp.c now pins both halves -- a concrete value strictly greater than the budget, and the hint stating the peak is where indexing STOPPED. Verified against the real pre-fix output captured during the bench, which contains neither. mcp suite 317 passed, 0 failed, 4 skipped; lint-ci clean. Signed-off-by: Martin Vogel <[email protected]>
1 parent 339b3f4 commit 1167972

2 files changed

Lines changed: 38 additions & 5 deletions

File tree

‎src/mcp/mcp.c‎

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11228,11 +11228,34 @@ static char *handle_index_repository(cbm_mcp_server_t *srv, const char *args) {
1122811228
yyjson_mut_obj_add_str(doc, root, "previous_index", "preserved");
1122911229
yyjson_mut_obj_add_int(doc, root, "budget_mb", budget_mb);
1123011230
yyjson_mut_obj_add_int(doc, root, "peak_rss_mb", peak_rss_mb);
11231-
yyjson_mut_obj_add_str(doc, root, "hint",
11232-
"Indexing stopped: resident memory stayed above the budget after "
11233-
"backpressure; no partial graph was published and the previous "
11234-
"index still serves. Raise CBM_MEM_BUDGET_MB, lower CBM_WORKERS, "
11235-
"or exclude large subtrees.");
11231+
/* A CONCRETE retry value, because "raise CBM_MEM_BUDGET_MB" alone makes
11232+
* the caller guess — and the obvious guess is wrong. peak_rss_mb is
11233+
* where the run was STOPPED (it is pinned just above the budget by
11234+
* construction), not what the repo needs, so retrying at peak+10% fails
11235+
* again. Measured 2026-09-13 on the linux kernel: aborted at 25622 MB
11236+
* against a 24576 MB budget, but completing it actually took 31.75 GB —
11237+
* 1.32x the budget, 1.24x the reported peak. Suggest 1.5x the budget so
11238+
* the first retry has a real chance, and say plainly that the peak is a
11239+
* floor rather than a requirement. */
11240+
/* (3*b+1)/2 rather than b + b/2: integer division makes the latter
11241+
* degenerate to b for b == 1, so the "suggestion" would repeat the
11242+
* budget that just failed. Rounding up keeps it strictly larger for
11243+
* every positive budget. */
11244+
int suggested_budget_mb = budget_mb > 0 ? (budget_mb * 3 + 1) / 2 : 0;
11245+
char hint_text[CBM_SZ_512];
11246+
(void)snprintf(hint_text, sizeof(hint_text),
11247+
"Indexing stopped: resident memory stayed above the budget after "
11248+
"backpressure; no partial graph was published and the previous index "
11249+
"still serves. peak_rss_mb is where indexing was STOPPED, not what this "
11250+
"repo needs — the real requirement is higher, so retrying just above the "
11251+
"peak will fail again. Retry with CBM_MEM_BUDGET_MB=%d (1.5x the current "
11252+
"budget) if the machine has the RAM, or lower CBM_WORKERS, or exclude "
11253+
"large subtrees.",
11254+
suggested_budget_mb);
11255+
if (suggested_budget_mb > 0) {
11256+
yyjson_mut_obj_add_int(doc, root, "suggested_budget_mb", suggested_budget_mb);
11257+
}
11258+
yyjson_mut_obj_add_strcpy(doc, root, "hint", hint_text);
1123611259
} else if (rc == CBM_PIPELINE_ABORT_PRESERVE_DB) {
1123711260
/* The truthful abort message (#2020): the old generic "check repo_path"
1123811261
* hint sent people debugging a path that was fine, when the run

‎tests/test_mcp.c‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17773,8 +17773,15 @@ TEST(index_repository_over_budget_reports_named_reason) {
1777317773
bool reason_named = second_reason && strcmp(second_reason, "over_memory_budget") == 0;
1777417774
bool previous_preserved = second_previous && strcmp(second_previous, "preserved") == 0;
1777517775
bool hint_names_knob = second_hint && strstr(second_hint, "CBM_MEM_BUDGET_MB") != NULL;
17776+
/* The hint must also say that peak_rss_mb is NOT the requirement. The abort
17777+
* fires when RSS crosses the budget, so the peak is pinned just above it by
17778+
* construction; a caller who retries at peak+10% fails again. Measured on
17779+
* the linux kernel 2026-09-13: aborted at 25622 MB against a 24576 MB
17780+
* budget, but completing it took 31.75 GB. */
17781+
bool hint_warns_peak_is_not_need = second_hint && strstr(second_hint, "STOPPED") != NULL;
1777617782
int budget_mb = budget_doc_int(second_doc, "budget_mb", -1);
1777717783
int peak_rss_mb = budget_doc_int(second_doc, "peak_rss_mb", -1);
17784+
int suggested_mb = budget_doc_int(second_doc, "suggested_budget_mb", -1);
1777817785
yyjson_doc_free(second_doc);
1777917786
free(second);
1778017787
long db_size_after = (long)cbm_file_size(db_path);
@@ -17817,8 +17824,11 @@ TEST(index_repository_over_budget_reports_named_reason) {
1781717824
ASSERT_TRUE(reason_named);
1781817825
ASSERT_TRUE(previous_preserved);
1781917826
ASSERT_TRUE(hint_names_knob);
17827+
ASSERT_TRUE(hint_warns_peak_is_not_need);
1782017828
ASSERT_EQ(budget_mb, 1);
1782117829
ASSERT_GT(peak_rss_mb, budget_mb);
17830+
/* A CONCRETE retry value, not just the knob name: 1.5x the budget. */
17831+
ASSERT_GT(suggested_mb, budget_mb);
1782217832
/* Preserved on disk and still served: same file size, same node count. */
1782317833
ASSERT_GT(db_size_before, 0L);
1782417834
ASSERT_EQ(db_size_after, db_size_before);

0 commit comments

Comments
 (0)