feat(index): add opt-in discovery resource limits - #1723
Conversation
|
Thanks for opening this — it has been seen, and it is queued. This note is automated, but it is not a brush-off: it exists so you know where your PR stands instead of having to guess from silence. Current review status: working through a backlog. What that means for this PR, concretely:
Things that will genuinely speed it up whenever review does happen:
If this fixes a bug, a reproduction we can run is worth more than a description of the symptom. Thanks for contributing, and sorry in advance for the wait. |
7a9fbef to
2a24781
Compare
|
This fixes exactly what I blocked #1348 on, and I verified it rather than taking the claim. One small defect and I will merge. Default-off is now true by construction, not by convention. I traced all four gates:
Two config keys instead of eighteen. Three things you hardened beyond what I asked, which are worth naming:
And Worth noting: because every new test calls a symbol that does not exist on The one fix before merge — a silent failure.
if (!cbm_index_policy_set(&candidate, key, value, error, sizeof(error))) {
(void)fprintf(stderr, "error: %s\n", error);
return CLI_ERR;
}
return cbm_config_set(config, key, value);but the caller now suppresses the generic message for policy keys: if (!config_key_is_index_policy(argv[CLI_SKIP_ONE])) {
(void)fprintf(stderr, "error: failed to set %s\n", argv[CLI_SKIP_ONE]);
}So if validation passes and the Two things to confirm rather than change:
And one completeness check I would like your eye on, because it is the failure mode your own commit message warns about: the worker argv contract is now mandatory and fail-closed, so any harness that spawns Fix the CLI message and I will merge this. Thank you for taking the reshaping seriously instead of arguing for the original — this is a much better change than #1348 was, and the trust boundary is stronger than what I asked for. |
2a24781 to
41097a2
Compare
Indexing accepts whatever a repository contains. A tree carrying a vendored monorepo, a generated dump, or a runaway build directory is discovered in full, and the first sign of trouble is a host under memory pressure with nothing that attributes it to indexing. Add two opt-in limits evaluated during discovery against accepted source files only: index_max_files and index_max_source_mb. Both default to off, so nothing changes until an operator sets one. Crossing a limit fails the whole attempt with a structured resource_limit_exceeded result naming the resource, the observed value and the limit; no partial graph is published, and an existing serving index keeps answering. Limits are read from the CLI-managed _config.db and are not MCP request arguments. A supervised parent replaces any caller-supplied policy before spawning its worker, and the worker rejects a missing or incomplete contract, so the CLI, the daemon and the supervised worker all enforce the same decision. Both keys reach an operator through the existing config get/set/list/reset with no new subcommand. `set` suppresses its own generic message for them because the policy writer names the precise reason -- so that writer speaks on every failure it can return, including a validated value whose write then fails on a database that cannot be written. Exiting non-zero in silence is not an acceptable answer from a CLI. The two shell regressions that hand-roll the supervisor's worker argv carry that contract as well. Without it the worker exits before either guard can observe anything, and the guard would go quietly vacuous. Signed-off-by: 刘冲 <mail@liuchong.dev>
41097a2 to
3174313
Compare
|
Fixed, and the three checks confirmed. The silent write failure is fixed. int rc = cbm_config_set(config, key, value);
if (rc != 0) {
(void)fprintf(stderr, "error: failed to set %s\n", key);
}
return rc;
1. Fail-closed on the unattended path — deliberate, and specifically for that path. With no policy loadable there is no bound to enforce, and unattended is exactly where an unbounded index is least survivable. The cost is the one you named: nobody reads that log line. #1727 and #1728 are what close that gap — which is also why I understand judging them separately. 2. if (fl->max_files >= 0 && fl->count >= fl->max_files) {
fl->capped = true;
return;
}with 3. Worker argv contract — confirmed complete. Your enumeration matches mine. Every production spawn goes through the strip-and-inject in On the branch. Rebased onto current |
Related to #1347.
Problem
Indexing accepts whatever a repository contains. A tree carrying a vendored monorepo, a generated dump, or a runaway build directory is discovered in full, and the first sign of trouble is a host under memory pressure with nothing that attributes it to indexing. There is currently no way for an operator to say "not larger than this".
What this changes
Two opt-in limits, evaluated during discovery against accepted source files only, so ignored and excluded paths never count against an operator's budget:
index_max_filesindex_max_source_mbBoth default to
off; without configuration this PR changes no behaviour.Crossing a limit fails the whole attempt with a structured
resource_limit_exceededresult naming the resource, the observed value and the limit. No partial graph is published, and an existing serving index keeps answering. A partial graph would be worse than no graph: it looks complete and is silently wrong.Limits are read from the CLI-managed
_config.db, not from MCP request arguments. A supervised parent replaces any caller-supplied internal policy before spawning its worker, and the worker rejects a missing or incomplete contract, so the CLI, the daemon and the supervised worker all enforce the same decision. A test pins the forged-override path.Testing
make -f Makefile.cbm testandmake -f Makefile.cbm lint-cion macOS. New coverage: discovery counting and rejection, policy parsing and validation boundaries, worker-contract propagation and forged-override rejection, end-to-end preservation of the previously published index.One pre-existing failure (
tests/test_cli.c:6484, agent-client registry) is present on the unmodified base commit as well and is unrelated to this change.Stack
This is the first of six PRs that replace #1348. Each is independently reviewable and mergeable in order; later ones build on earlier ones.