Skip to content

Share execution configuration across run paths (#134) - #219

Open
leynos wants to merge 4 commits into
mainfrom
issue-134-introduce-a-shared-execution-config-thread-hnsw-params-derive-memory-estimates-centralise-run-preconditions
Open

Share execution configuration across run paths (#134)#219
leynos wants to merge 4 commits into
mainfrom
issue-134-introduce-a-shared-execution-config-thread-hnsw-params-derive-memory-estimates-centralise-run-preconditions

Conversation

@leynos

@leynos leynos commented Aug 23, 2026

Copy link
Copy Markdown
Owner

Summary

This branch makes builder-provided HNSW tuning govern both supported execution
paths. One-shot CPU runs now consume the same validated configuration as
sessions, use it in the memory guard, and retain the full run-precondition
policy behind Chutoro::run.

The parameter-aware memory guard now includes the configured HNSW distance-cache
capacity, while the legacy public estimate retains its default-capacity
behaviour. It also records bounded batch outcomes and CPU resource observations
when the metrics feature is enabled. Metrics and decision-point tracing
exclude source names, paths, and payload data.

Closes #134.

Review walkthrough

Validation

  • Focused CPU memory and Chutoro integration regressions: passed.
  • make check-fmt, make typecheck, make lint, make markdownlint,
    make nixie, and make test: passed (1,095 tests; 1 skipped).
  • coderabbit review --agent --committed: passed with 0 findings.

References

Summary by Sourcery

Share validated execution configuration across batch and session paths while aligning CPU resource usage, memory guards, observability, and run preconditions.

New Features:

  • Apply builder-configured HNSW settings consistently to one-shot CPU runs and sessions.
  • Add parameter-aware CPU memory estimation that accounts for effective construction width and configured distance-cache capacity.
  • Emit bounded one-shot batch outcome and CPU resource metrics when metrics support is enabled.

Bug Fixes:

  • Ensure one-shot runs enforce the complete set of preconditions, including backend availability and configured memory limits, before execution.
  • Remove source-identifying data from batch tracing and metrics.

Enhancements:

  • Centralize validated clustering and CPU HNSW policy in a shared execution configuration.
  • Bound HNSW construction width to the useful dataset size while preserving graph connectivity requirements.
  • Replace the public standalone CPU pipeline entry point with the supported builder-and-run API.

Documentation:

  • Document shared HNSW configuration, parameter-aware memory limits, batch metrics, and migration to the supported run API.

Tests:

  • Add cross-path property coverage and regressions for HNSW propagation, cache-aware memory guards, bounded construction width, metrics, and privacy-safe tracing.

Carry validated clustering and HNSW settings from the builder into both
batch execution and session construction. Use those parameters for CPU
pipeline construction and memory estimates so one-shot runs honour the
same tuning policy as sessions.

Remove the weaker public CPU pipeline entrypoint, leaving `Chutoro::run`
as the validated public batch path, and cover the configured memory
estimate with a regression test.
@coderabbitai

coderabbitai Bot commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 40068702-dfd4-42dc-aef8-d63ec2fc4009

📥 Commits

Reviewing files that changed from the base of the PR and between 29a6920 and 3f7727c.

📒 Files selected for processing (9)
  • chutoro-core/src/builder.rs
  • chutoro-core/src/chutoro.rs
  • chutoro-core/src/cpu_pipeline.rs
  • chutoro-core/src/execution_config.rs
  • chutoro-core/src/lib.rs
  • chutoro-core/src/session/config.rs
  • chutoro-core/src/session/tests/builder.rs
  • chutoro-core/tests/chutoro.rs
  • docs/developers-guide.md
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • leynos/whitaker (auto-detected)
  • leynos/typos-config-builder (auto-detected)

Limit details: You’ve used all 3 included reviews currently available. Your 72 included PR review attempts over the past 7 days set your current allowance at 3 reviews per hour.


Summary

  • Centralize validated batch and session execution settings in ExecutionConfig.
  • Pass builder-configured HnswParams through one-shot runs, sessions, CPU pipeline creation, and memory estimation.
  • Centralize execution preconditions, including source checks, cluster-size validation, backend availability, and memory limits.
  • Remove the weaker public run_cpu_pipeline entry point.
  • Add regression coverage for custom HNSW settings and max_connections memory estimation.
  • Document the configuration flow in the developer guide.

Related issue

  • Address issue #134.

Walkthrough

Changes

Centralise validated execution settings in ExecutionConfig. Pass the configuration through batch and session builders. Use configured HNSW parameters for CPU pipeline construction and memory estimation. Remove the public CPU pipeline wrapper and update tests and documentation.

Execution configuration flow

Layer / File(s) Summary
Execution configuration contract
chutoro-core/src/execution_config.rs, chutoro-core/src/chutoro.rs, chutoro-core/src/session/...
Store clustering and CPU HNSW settings in ExecutionConfig. Make Chutoro and SessionConfig use this configuration.
Builder and CPU runtime propagation
chutoro-core/src/builder.rs, chutoro-core/src/chutoro.rs, chutoro-core/src/cpu_pipeline.rs, chutoro-core/src/lib.rs
Construct ExecutionConfig in batch and session builders. Pass configured HNSW parameters to CPU execution and memory estimation. Remove the public CPU pipeline re-export.
Configuration validation and documentation
chutoro-core/src/chutoro.rs, chutoro-core/tests/chutoro.rs, chutoro-core/src/session/tests/builder.rs, docs/developers-guide.md
Verify parameter propagation and memory-limit behaviour. Document ExecutionConfig as the shared configuration source.

Sequence Diagram(s)

sequenceDiagram
  participant ChutoroBuilder
  participant Chutoro
  participant CPU_Pipeline
  ChutoroBuilder->>Chutoro: construct ExecutionConfig
  ChutoroBuilder->>Chutoro: pass ExecutionConfig
  Chutoro->>Chutoro: estimate memory from HnswParams
  Chutoro->>CPU_Pipeline: pass HnswParams and min_cluster_size
  CPU_Pipeline->>CPU_Pipeline: build HNSW index with supplied parameters
Loading

Suggested labels: Issue

Poem

Gather the settings, keep them in line,
Let batch and session share one design.
Feed HNSW the values it knows,
Estimate memory as execution flows.
One config guides the runtime bright. ✨


Caution

Pre-merge checks failed

Please resolve all errors before merging. Addressing warnings is optional.

  • Ignore

❌ Failed checks (1 error, 7 warnings)

Check name Status Explanation Resolution
Testing (Overall) ❌ Error Require an end-to-end CPU test: the new run test stops at the memory guard, while the accessor test only checks stored fields and passes if the pipeline still uses defaults. Add a CPU integration test that runs past the memory check and detects builder HnswParams in pipeline construction, including ef_construction and max_connections.
User-Facing Documentation ⚠️ Warning HEAD removes public run_cpu_pipeline and changes with_hnsw_params behaviour for batch runs and memory checks, but docs/users-guide.md is unchanged and lacks migration guidance. Document with_hnsw_params for batch runs and memory limits in docs/users-guide.md; add an n+1 migration note for run_cpu_pipeline removal.
Developer Documentation ⚠️ Warning Update the design record: the PR adds ExecutionConfig, but docs/chutoro-design.md still shows direct fields and the old three-argument pipeline call. Revise §§10.1 and 12.3 to record the shared configuration, CPU HNSW and memory flow, and the new pipeline boundary; correct stale API examples.
Testing (Unit And Behavioural) ⚠️ Warning The new integration test stops at MemoryLimitExceeded, while the only pipeline-parameter test reads private Chutoro state; no test runs a custom-configured one-shot CPU pipeline. Add a CPU-gated integration test that runs ChutoroBuilder::build().run() with non-default HnswParams and verifies parameter-sensitive behaviour at the public boundary.
Testing (Property / Proof) ⚠️ Warning ExecutionConfig introduces a cross-path invariant over valid HnswParams, but the PR adds only one fixed-case regression test and no proptest, bounded proof, or recommendation. Add a proptest over valid min_cluster_size and HnswParams values. Assert exact propagation to batch memory estimation, CPU pipeline configuration, and SessionConfig across generated cases.
Testing (Compile-Time / Ui) ⚠️ Warning The PR removes the public Rust run_cpu_pipeline export, but adds only runtime tests; existing trybuild fixtures do not cover this compile-time API change. Add and register a focused trybuild compile-fail fixture that asserts chutoro_core::run_cpu_pipeline is unavailable.
Observability ⚠️ Warning Reject this change: builder HNSW settings now alter CPU resource use and memory-limit failures, but the diff adds no batch metrics or decision-point fields for max_connections or estimated memory. Add bounded batch run outcome/resource metrics and include max_connections, estimate, limit, backend, and stable error codes in decision-point tracing without raw payloads.
Performance And Resource Use ⚠️ Warning Passing unrestricted ef_construction into the batch HNSW planner can allocate SearchState at that width, while check_memory_limit estimates only max_connections. Bound ef_construction to the dataset or a documented safe maximum, and include the effective search width in the memory estimate before HNSW construction.
✅ Passed checks (12 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes implement #134 by sharing ExecutionConfig, threading HnswParams, deriving memory estimates, and removing the weaker public CPU entry point.
Out of Scope Changes check ✅ Passed All code, tests, and documentation changes support the shared execution configuration objectives in #134.
Docstring Coverage ✅ Passed Docstring check was indeterminate for this PR — some files could not be analyzed in time. Not blocking.
Module-Level Documentation ✅ Passed Pass the check: execution_config.rs documents its purpose, utility, and links from the builder to Chutoro and SessionConfig; all changed modules retain module documentation.
Unit Architecture ✅ Passed Keep the change: ExecutionConfig accessors are pure, run_cpu_pipeline_with_len receives explicit HnswParams, and no new hidden I/O, network, clock, or mutation path appears.
Domain Architecture ✅ Passed Keep PASS: the diff adds only crate-private ExecutionConfig and HNSW policy plumbing; no changed production line introduces transport, storage, filesystem, framework, or adapter dependencies.
Security And Privacy ✅ Passed Pass this check: the committed diff adds only internal configuration and pipeline wiring; scans found no secrets, credentials, authentication logic, external-boundary sinks, or unsafe deserialization.
Concurrency And State ✅ Passed Pass: the diff adds only owned immutable configuration; no new shared mutable state, locks, tasks, or ordering protocol. The existing parallel HNSW/MST model and concurrency tests remain unchanged.
Architectural Complexity And Maintainability ✅ Passed ExecutionConfig is a small crate-private value used immediately by batch and session paths; the PR documents this reuse, adds no dependencies or indirection-heavy mechanisms, and shows no dependenc...
Rust Compiler Lint Integrity ✅ Passed Pass this check: the diff adds no broad lint suppressions or artificial anchors; new configuration items have real callers, and the single HnswParams clone supplies the owned index API.
Title check ✅ Passed The title accurately describes sharing execution configuration and includes the referenced issue number (#134).
Description check ✅ Passed The description directly explains the shared execution configuration changes and references the matching issue and validation results.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch issue-134-introduce-a-shared-execution-config-thread-hnsw-params-derive-memory-estimates-centralise-run-preconditions

Comment @coderabbitai help to get the list of available commands.

@sourcery-ai

sourcery-ai Bot commented Aug 23, 2026

Copy link
Copy Markdown

Reviewer's Guide

Introduce a shared ExecutionConfig to centralize validated clustering and HNSW CPU parameters, and ensure both batch runs and sessions use the same configuration for execution, memory estimation, and pipeline construction.

File-Level Changes

Change Details Files
Introduce ExecutionConfig as the single source of validated clustering and CPU HNSW parameters, and thread it through Chutoro and SessionConfig.
  • Add execution_config module defining ExecutionConfig with min_cluster_size and optional HnswParams, plus accessors
  • Update Chutoro to store ExecutionConfig instead of bare min_cluster_size, expose min_cluster_size() and hnsw_params() via ExecutionConfig, and adjust internal callers
  • Change SessionConfig to hold ExecutionConfig and delegate min_cluster_size and hnsw_params accessors to it
chutoro-core/src/execution_config.rs
chutoro-core/src/chutoro.rs
chutoro-core/src/session/config.rs
Update ChutoroBuilder and session tests to construct and pass ExecutionConfig into batch and session paths.
  • Adjust builder to construct ExecutionConfig after validation for both batch Chutoro and session SessionConfig, wiring in HnswParams under the cpu feature
  • Clarify builder HNSW parameter docs to reflect use by both CPU execution and sessions
  • Update tests to use ExecutionConfig helper when constructing Chutoro and SessionConfig, and add a regression test that builder HNSW params reach Chutoro’s execution configuration
chutoro-core/src/builder.rs
chutoro-core/src/chutoro.rs
chutoro-core/src/session/tests/builder.rs
Ensure CPU pipeline and memory estimation use builder-configured HNSW parameters instead of internal defaults, and validate via regression tests.
  • Extend run_cpu_pipeline_with_len to accept HnswParams and use them for CpuHnsw::build_with_edges and ef calculation, removing the internal HnswParams::default construction
  • Change Chutoro::check_memory_limit to estimate memory using execution_config.hnsw_params().max_connections() under the cpu feature and a 0-byte estimate when cpu is disabled
  • Wire run_cpu to pass min_cluster_size and HNSW params into the CPU pipeline
  • Add integration test confirming run()’s memory limit uses the configured non-default max_connections rather than the previous constant, and remove the test binding a constant to HnswParams::default
chutoro-core/src/cpu_pipeline.rs
chutoro-core/src/chutoro.rs
chutoro-core/tests/chutoro.rs
Adjust public API surface and documentation to reflect the new execution configuration composition boundary.
  • Stop re-exporting run_cpu_pipeline from the crate root, keeping CPU pipeline usage internal to Chutoro
  • Document ExecutionConfig as the internal composition boundary for min_cluster_size and CPU HNSW params, with guidance that execution and session code should read but not recreate or revalidate these settings
chutoro-core/src/lib.rs
docs/developers-guide.md

Assessment against linked issues

Issue Objective Addressed Explanation
#134 Introduce a shared validated execution configuration carrying the minimum cluster size and HNSW parameters, and use it consistently for one-shot Chutoro runs and session construction.
#134 Thread the configured HNSW parameters into CPU one-shot execution and derive memory estimates from the actual configured max-connections value rather than a hard-coded default.
#134 Centralise run preconditions for empty sources, insufficient items, backend availability, and memory limits instead of enforcing an incomplete duplicate policy in the public CPU pipeline entrypoint.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

codescene-access[bot]

This comment was marked as outdated.

codescene-access[bot]

This comment was marked as outdated.

@leynos
leynos marked this pull request as ready for review August 23, 2026 21:27

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @leynos, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@coderabbitai coderabbitai Bot added the Issue label Aug 23, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3f7727c63a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread chutoro-core/src/chutoro.rs Outdated
Comment on lines +223 to +224
let estimated =
crate::memory::estimate_peak_bytes(items, self.hnsw_params().max_connections());

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Account for the configured distance-cache capacity

When a caller supplies HnswParams::with_distance_cache_max_entries with a capacity above the default, these parameters now reach CpuHnsw, but this estimate still passes only max_connections and estimate_peak_bytes assumes the default 1,048,576-entry cache. The pre-flight guard can therefore approve a run whose configured cache alone exceeds max_bytes, defeating the OOM protection; derive the cache contribution from the configured HnswParams and cover a non-default capacity.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@coderabbitai Has this now been resolved in the latest commit?

Use codegraph analysis to determine your answer.

If this comment is now resolved, please mark it as such using the API. Otherwise, please provide an AI agent prompt for the remaining work to be done to address this comment.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '== Candidate modules =='
fd -t f -e rs . chutoro-core | rg '(memory|hnsw|cpu_pipeline|execution_config|builder)\.rs$' || true

printf '%s\n' '== Symbol map =='
ast-grep outline chutoro-core --items all --type function,struct,impl \
  --match 'estimate_peak_bytes|HnswParams|CpuHnsw|run_cpu_pipeline_with_len' || true

printf '%s\n' '== Configuration, estimator, and CPU propagation references =='
rg -n -C 5 \
  'estimate_peak_bytes_for_hnsw_params|estimate_peak_bytes\s*\(|distance_cache_max_entries|with_distance_cache_max_entries|CpuHnsw|run_cpu_pipeline_with_len' \
  chutoro-core --glob '*.rs' || true

Length of output: 135218


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '== Parameter-aware memory estimator =='
sed -n '84,145p' chutoro-core/src/memory.rs

printf '%s\n' '== HNSW parameter cache accessors =='
sed -n '1,125p' chutoro-core/src/hnsw/params.rs

printf '%s\n' '== Distance-cache configuration =='
sed -n '1,120p' chutoro-core/src/hnsw/distance_cache.rs

printf '%s\n' '== CPU HNSW allocation =='
sed -n '135,185p' chutoro-core/src/hnsw/cpu/construction.rs

printf '%s\n' '== Cache-capacity estimator tests =='
rg -n -C 6 \
  'distance_cache|max_entries|parameter_estimate|MemoryLimitExceeded|estimate_peak_bytes_for_hnsw_params' \
  chutoro-core/src/memory.rs chutoro-core/tests/chutoro.rs

Length of output: 19096


@leynos, keep this review thread open.

The latest commit does not resolve the finding.

The code graph shows that HnswParams reaches CpuHnsw::with_capacity. That constructor creates DistanceCache from params.distance_cache_config(). Therefore, a caller-provided with_distance_cache_max_entries value changes the actual allocation.

However, estimate_peak_bytes_for_hnsw_params passes only max_connections and effective_ef_construction into the estimator. The estimator still charges DEFAULT_CACHE_MAX_ENTRIES at chutoro-core/src/memory.rs, Line 137. It does not read hnsw_params.distance_cache_config().max_entries().

Use this AI agent prompt:

Fix the `Chutoro::run` memory-limit estimate so it accounts for the configured HNSW distance-cache capacity.

Trace the existing configuration flow first:
- `Chutoro::check_memory_limit` calls `estimate_peak_bytes_for_hnsw_params`.
- `Chutoro::run_cpu` passes the same `HnswParams` into `run_cpu_pipeline_with_len`.
- `run_cpu_pipeline_with_len` passes those parameters to `CpuHnsw::build_with_edges`.
- `CpuHnsw::with_capacity` creates `DistanceCache` from `params.distance_cache_config()`.

Update `chutoro-core/src/memory.rs`:
1. Change the parameter-aware estimator or its internal helper so it derives the distance-cache contribution from `hnsw_params.distance_cache_config().max_entries().get()`.
2. Preserve `estimate_peak_bytes(point_count, max_connections)` as the default-configuration API, if it is public API. It must retain default cache-capacity behaviour.
3. Use saturating arithmetic for the cache entry calculation.
4. Update comments and documentation so they do not claim that every CPU HNSW index allocates `DEFAULT_CACHE_MAX_ENTRIES`.

Add regression coverage:
1. Add a unit test proving that `estimate_peak_bytes_for_hnsw_params` produces a larger estimate for a parameter set with `with_distance_cache_max_entries` above `DistanceCacheConfig::DEFAULT_MAX_ENTRIES`.
2. Add an integration test in `chutoro-core/tests/chutoro.rs` that:
   - Configures `HnswParams` with a non-default cache capacity above the default.
   - Calculates the parameter-aware estimate.
   - Sets `max_bytes` below that estimate but above the equivalent default-cache estimate.
   - Calls `Chutoro::run`.
   - Asserts that it returns `ChutoroError::MemoryLimitExceeded` with the parameter-aware estimate.
3. Use `NonZeroUsize` for the custom cache capacity.

Run the existing focused Rust test suites after the change.

You are interacting with an AI system.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@coderabbitai Has this now been resolved in the latest commit?

Use codegraph analysis to determine your answer.

If this comment is now resolved, please mark it as such using the API. Otherwise, please provide an AI agent prompt for the remaining work to be done to address this comment.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '== Symbol map =='
ast-grep outline chutoro-core/src/memory.rs --items all --type function,struct,impl \
  --match 'estimate_peak_bytes|HnswParams' || true
ast-grep outline chutoro-core/src/hnsw --items all --type function,struct,impl \
  --match 'HnswParams|DistanceCache|CpuHnsw|with_capacity|build_with_edges' || true
ast-grep outline chutoro-core/tests/chutoro.rs --items all --type function \
  --match 'memory|cache|hnsw' || true

printf '%s\n' '== Configuration flow and regression coverage =='
rg -n -C 5 \
  'estimate_peak_bytes_for_hnsw_params|estimate_peak_bytes\s*\(|distance_cache_config|distance_cache_max_entries|with_distance_cache_max_entries|DistanceCache::|DistanceCacheConfig|run_cpu_pipeline_with_len|build_with_edges|MemoryLimitExceeded' \
  chutoro-core/src chutoro-core/tests --glob '*.rs' || true

Length of output: 71655


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '== Parameter-aware estimator and cache arithmetic =='
sed -n '84,190p' chutoro-core/src/memory.rs

printf '%s\n' '== Memory-estimator tests =='
sed -n '250,335p' chutoro-core/src/memory.rs

printf '%s\n' '== One-shot memory-limit tests =='
sed -n '145,190p' chutoro-core/tests/chutoro.rs

printf '%s\n' '== Exact cache-capacity references in changed test areas =='
rg -n -C 8 \
  'with_distance_cache_max_entries|DEFAULT_MAX_ENTRIES|cache.*estimate|estimate.*cache' \
  chutoro-core/src/memory.rs chutoro-core/tests/chutoro.rs || true

Length of output: 11903


@leynos, keep this review thread open.

The latest commit does not resolve the finding.

Chutoro::check_memory_limit now calls estimate_peak_bytes_for_hnsw_params. The CPU pipeline also receives the configured HnswParams. CpuHnsw constructs DistanceCache with params.distance_cache_config().

However, estimate_peak_bytes_for_hnsw_params passes only max_connections and effective_ef_construction to its helper. The helper still calculates distance_cache from DEFAULT_CACHE_MAX_ENTRIES in chutoro-core/src/memory.rs. A custom HnswParams::with_distance_cache_max_entries value therefore changes the allocation but not the memory-limit estimate.

No regression test covers a non-default distance-cache capacity.

Use this AI agent prompt:

Fix the CPU memory-limit estimate so that it accounts for the configured HNSW distance-cache capacity.

Trace and preserve the current configuration flow:
- `Chutoro::check_memory_limit` calls `estimate_peak_bytes_for_hnsw_params`.
- `Chutoro::run_cpu` passes the same `HnswParams` to `run_cpu_pipeline_with_len`.
- `run_cpu_pipeline_with_len` passes the parameters to `CpuHnsw::build_with_edges`.
- `CpuHnsw` creates `DistanceCache` from `params.distance_cache_config()`.

Update `chutoro-core/src/memory.rs`:
1. Extend the internal estimator to accept a distance-cache entry capacity.
2. Make `estimate_peak_bytes_for_hnsw_params` pass `hnsw_params.distance_cache_config().max_entries().get()`.
3. Calculate the cache contribution from that capacity with saturating arithmetic.
4. Keep the public `estimate_peak_bytes(point_count, max_connections)` API unchanged. It must continue to use `DEFAULT_CACHE_MAX_ENTRIES`.
5. Update comments and documentation that state the cache always uses `DEFAULT_CACHE_MAX_ENTRIES`.

Add regression tests:
1. In `chutoro-core/src/memory.rs`, construct `HnswParams` with `with_distance_cache_max_entries` above `DistanceCacheConfig::DEFAULT_MAX_ENTRIES`. Assert that `estimate_peak_bytes_for_hnsw_params` returns a larger value than for equivalent default-cache parameters.
2. In `chutoro-core/tests/chutoro.rs`, configure the same non-default cache capacity. Set `max_bytes` below the parameter-aware estimate but above the default-cache estimate. Assert that `Chutoro::run` returns `ChutoroError::MemoryLimitExceeded` and reports the parameter-aware estimate.
3. Use `NonZeroUsize` for the custom cache capacity.

Run the focused memory and Chutoro integration tests with the `cpu` feature enabled.

You are interacting with an AI system.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@coderabbitai Has this now been resolved in the latest commit?

Use codegraph analysis to determine your answer.

If this comment is now resolved, please mark it as such using the API. Otherwise, please provide an AI agent prompt for the remaining work to be done to address this comment.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Post @coderabbitai resolve or @coderabbitai approve as a new top-level PR comment. Approve commands are disabled for review-thread replies.

Comment thread chutoro-core/src/builder.rs
Document the supported batch tuning and migration path, cover the removed
pipeline export at compile time, and verify configured CPU HNSW parameters
reach a successful one-shot run.

Bound construction search state to the batch's useful width and include it
in the memory guard. Record bounded resource decision fields in tracing.
codescene-access[bot]

This comment was marked as outdated.

codescene-access[bot]

This comment was marked as outdated.

@leynos

This comment was marked as resolved.

@coderabbitai

This comment was marked as resolved.

Record bounded one-shot outcomes and CPU resource observations while keeping
source-identifying data out of metrics and decision-point tracing. Prove
shared execution configuration propagation across batch and session paths,
and document the metric contract for operators.
codescene-access[bot]

This comment was marked as outdated.

codescene-access[bot]

This comment was marked as outdated.

Make the CPU memory guard reflect the distance-cache capacity supplied to
the HNSW builder. Preserve the legacy public estimate's default-capacity
behaviour, and cover both estimates and the one-shot guard with regressions.
codescene-access[bot]

This comment was marked as outdated.

@codescene-access codescene-access Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No quality gates enabled for this code.

@coderabbitai

coderabbitai Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

base="$(git merge-base HEAD origin/main 2>/dev/null || git rev-parse HEAD~1)"
echo '=== Changed files ==='
git diff --name-status "$base" HEAD

echo '=== Relevant diff ==='
git diff --unified=16 "$base" HEAD -- \
  chutoro-core/src \
  chutoro-core/tests \
  docs/users-guide.md \
  docs/chutoro-design.md \
  docs/developers-guide.md

echo '=== Relevant symbols and instrumentation ==='
rg -n -C 5 --glob '*.rs' \
  'ExecutionConfig|with_hnsw_params|run_cpu_pipeline|run_cpu_pipeline_with_len|bounded_for_point_count|effective_ef_construction|estimate_peak_bytes_for_hnsw_params|check_memory_limit|proptest!|trybuild|compile_fail|metrics::|counter!|histogram!|tracing::|error_code|MemoryLimitExceeded' \
  chutoro-core/src chutoro-core/tests || true

echo '=== Documentation references ==='
rg -n -C 5 \
  'with_hnsw_params|run_cpu_pipeline|ExecutionConfig|effective.*construction|memory|metric|tracing|error.code' \
  docs/users-guide.md docs/chutoro-design.md docs/developers-guide.md 2>/dev/null || true

echo '=== Test and UI fixture inventory ==='
fd -HI -t f . chutoro-core/tests | sort

Length of output: 1648


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '=== Repository state ==='
git status --short --branch || true
git show -s --format='HEAD %H%n%s' HEAD || true

echo '=== Relevant file inventory ==='
fd -HI -t f . chutoro-core/src chutoro-core/tests docs \
  | rg '(builder|chutoro|cpu_pipeline|execution_config|memory|params|session.*config|users-guide|chutoro-design|developers-guide|trybuild|api_surface)' \
  | sort

echo '=== Source and test outlines ==='
for file in \
  chutoro-core/src/builder.rs \
  chutoro-core/src/chutoro.rs \
  chutoro-core/src/cpu_pipeline.rs \
  chutoro-core/src/execution_config.rs \
  chutoro-core/src/memory.rs \
  chutoro-core/src/hnsw/params.rs \
  chutoro-core/src/session/config.rs \
  chutoro-core/tests/chutoro.rs \
  chutoro-core/tests/session_api_surface.rs
do
  if [ -f "$file" ]; then
    echo "--- $file"
    ast-grep outline "$file" --items all 2>/dev/null || true
  fi
done

echo '=== Targeted implementation, test, and telemetry references ==='
rg -n -C 8 --glob '*.rs' \
  'ExecutionConfig|with_hnsw_params|run_cpu_pipeline|run_cpu_pipeline_with_len|bounded_for_point_count|effective_ef_construction|estimate_peak_bytes_for_hnsw_params|check_memory_limit|proptest!|prop_assert|trybuild|compile_fail|metrics::|counter!|histogram!|tracing::|error_code|MemoryLimitExceeded' \
  chutoro-core/src chutoro-core/tests || true

echo '=== Targeted documentation references ==='
rg -n -C 8 \
  'with_hnsw_params|run_cpu_pipeline|ExecutionConfig|effective.*construction|memory|metric|tracing|error.code' \
  docs/users-guide.md docs/chutoro-design.md docs/developers-guide.md 2>/dev/null || true

echo '=== UI fixtures ==='
fd -HI -t f . chutoro-core/tests | rg '(trybuild|\.stderr$|api_surface)' | sort

Length of output: 202191


🏁 Script executed:

#!/bin/bash
set -euo pipefail

show_matches() {
  local file="$1" pattern="$2"
  if [ -f "$file" ]; then
    echo "--- $file"
    rg -n -C 18 --pcre2 "$pattern" "$file" || true
  fi
}

show_matches chutoro-core/src/chutoro.rs \
  'fn run\b|fn run_cpu\b|fn check_memory_limit\b|fn estimate_peak_bytes\b|metrics::|tracing::|error_code|batch\.'
show_matches chutoro-core/src/cpu_pipeline.rs \
  'fn run_cpu_pipeline_with_len\b|building CPU HNSW index|effective_ef_construction|bounded_for_point_count'
show_matches chutoro-core/src/memory.rs \
  'estimate_peak_bytes_for_hnsw_params|effective_ef_construction|SEARCH_STATE_BYTES_PER_WIDTH'
show_matches chutoro-core/src/hnsw/params.rs \
  'bounded_for_point_count|effective_ef_construction'
show_matches chutoro-core/tests/chutoro.rs \
  'hnsw|Hnsw|memory|metrics|tracing|proptest|run\('
show_matches chutoro-core/tests/session_api_surface.rs \
  'trybuild|compile_fail'
show_matches chutoro-core/tests/trybuild/run_cpu_pipeline_is_private.rs \
  '.'
show_matches chutoro-core/tests/trybuild/run_cpu_pipeline_is_private.stderr \
  '.'

echo '=== Batch test candidates ==='
rg -n -l --glob '*.rs' \
  'chutoro\.batch|batch.*metrics|MemoryLimitExceeded|building CPU HNSW index|with_hnsw_params' \
  chutoro-core/tests chutoro-core/src | sort

echo '=== Metrics feature and test configuration ==='
rg -n -C 5 \
  'metrics.*=|metrics-util|tracing-subscriber|trybuild|proptest' \
  chutoro-core/Cargo.toml Cargo.toml 2>/dev/null || true

Length of output: 37506


🏁 Script executed:

#!/bin/bash
set -euo pipefail

for file in \
  chutoro-core/src/chutoro/properties.rs \
  chutoro-core/src/chutoro_tests.rs \
  chutoro-core/src/batch_metrics.rs \
  chutoro-core/tests/batch_metrics.rs \
  chutoro-core/src/lib.rs \
  chutoro-core/src/error.rs
do
  if [ -f "$file" ]; then
    echo "--- $file"
    cat -n "$file"
  fi
done

echo '=== Test module registration ==='
rg -n -C 6 --glob '*.rs' \
  'mod properties|mod batch_metrics|batch_metrics|chutoro_tests|cfg\(test\)' \
  chutoro-core/src chutoro-core/tests || true

Length of output: 97052


@leynos Mark all eight checks as resolved.

Check Status Evidence
Testing (Overall) Resolved chutoro-core/tests/chutoro.rs runs ChutoroBuilder::build().run() with custom HnswParams. It verifies max_connections, configured_ef_construction, and effective_ef_construction in the CPU HNSW construction event.
User-Facing Documentation Resolved docs/users-guide.md documents batch with_hnsw_params, parameter-aware memory limits, metrics, and migration from removed run_cpu_pipeline.
Developer Documentation Resolved docs/chutoro-design.md documents ExecutionConfig, the four-argument internal CPU pipeline boundary, dataset-bounded construction width, and parameter-aware estimation.
Testing (Unit And Behavioural) Resolved The one-shot CPU test completes the pipeline with non-default HNSW parameters. It does not stop at the memory guard.
Testing (Property / Proof) Resolved chutoro-core/src/chutoro/properties.rs generates valid min_cluster_size, max_connections, and ef_construction values. It verifies the batch memory guard, CPU pipeline event fields, and SessionConfig propagation.
Testing (Compile-Time / Ui) Resolved chutoro-core/tests/session_api_surface.rs registers chutoro-core/tests/trybuild/run_cpu_pipeline_is_private.rs as a compile-fail case.
Observability Resolved chutoro-core/src/batch_metrics.rs emits bounded batch outcome and resource metrics behind metrics. chutoro-core/tests/batch_metrics.rs covers successful CPU execution, memory-limit rejection, empty source, insufficient items, and unavailable CPU backend. Tracing includes stable error_code fields and excludes source identifiers and payload data.
Performance And Resource Use Resolved HnswParams::bounded_for_point_count() bounds construction width. The CPU pipeline applies that bound. estimate_peak_bytes_for_hnsw_params() charges the same effective width.

Do not create a follow-up issue. No remaining work is required for these checks.

Runtime verification remains required. This inspection sandbox could not compile or run the repository tests. Run the PR validation commands in CI before merge.

You are interacting with an AI system.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Introduce a shared execution config: thread HNSW params, derive memory estimates, centralise run preconditions

1 participant