fix(adaptive): reuse stable ACG scaffolds#481
Conversation
Signed-off-by: teerthsharma <teerths57@Gmail.com>
WalkthroughACG prompt IR now includes canonicalized structured output, while learning/profile keys incorporate scaffold and response-format fingerprints. Stability results persist dominant prefix fingerprints, and intent construction validates live fingerprints before reuse. Tests cover key bucketing, persistence, serialization, and mismatch rejection. ChangesACG scaffold fingerprinting
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant AnnotatedLlmRequest
participant build_prompt_ir
participant AcgLearner
participant RedisBackend
participant build_intent_bundle
AnnotatedLlmRequest->>build_prompt_ir: messages and response_format
build_prompt_ir-->>AcgLearner: PromptIR and structured_output_schema_id
AcgLearner->>AcgLearner: analyze stability and derive prefix fingerprint
AcgLearner->>RedisBackend: persist observations and stability
RedisBackend-->>build_intent_bundle: stored stability fingerprint
build_intent_bundle->>build_intent_bundle: compare live and stored fingerprints
build_intent_bundle-->>AnnotatedLlmRequest: intent bundle or skipped result
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@crates/adaptive/src/acg_profile.rs`:
- Around line 101-110: In the response_format_hash construction within the
profile-building logic, remove the unreachable has_stable_scaffold conditional
and short_hash call. Map response_format_fingerprint directly to an owned string
so the full fingerprint is always preserved, while keeping the existing optional
behavior unchanged.
In `@crates/adaptive/src/acg/stability.rs`:
- Around line 165-178: Update the fingerprint construction around
request_fingerprint so a deeper prefix (prefix_length > scaffold_length) returns
None when observation.source_request_hash is absent, rather than falling back to
"stable-scaffold"; retain the stable fallback for non-deeper prefixes. Add a
regression test covering a deeper prefix without source_request_hash and
asserting no fingerprint is produced.
In `@crates/adaptive/tests/integration/redis_tests.rs`:
- Around line 531-543: Update the restart assertions in the Redis integration
test to derive the scaffold-specific learning key from the request used by
process_run, then pass that key to restarted.load_observations and
restarted.load_stability. Keep the existing count and fingerprint assertions,
ensuring they validate the scaffold profile record rather than the plain
agent_id aggregate.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Enterprise
Run ID: e2272280-9799-46b2-baf1-c68bd359d9c6
📒 Files selected for processing (23)
crates/adaptive/src/acg/ir_builder.rscrates/adaptive/src/acg/stability.rscrates/adaptive/src/acg_component.rscrates/adaptive/src/acg_learner.rscrates/adaptive/src/acg_profile.rscrates/adaptive/tests/integration/redis_tests.rscrates/adaptive/tests/integration/runtime_integration_tests.rscrates/adaptive/tests/unit/acg/economics_internal_tests.rscrates/adaptive/tests/unit/acg/economics_policy_tests.rscrates/adaptive/tests/unit/acg/ir_builder_tests.rscrates/adaptive/tests/unit/acg/multi_breakpoint_tests.rscrates/adaptive/tests/unit/acg/stability_internal_tests.rscrates/adaptive/tests/unit/acg_component_tests.rscrates/adaptive/tests/unit/acg_learner_tests.rscrates/adaptive/tests/unit/acg_profile_tests.rscrates/adaptive/tests/unit/cache_diagnostics_tests.rscrates/adaptive/tests/unit/intercepts_tests.rscrates/adaptive/tests/unit/runtime_features_tests.rscrates/adaptive/tests/unit/runtime_tests.rscrates/adaptive/tests/unit/storage_memory_internal_tests.rscrates/adaptive/tests/unit/storage_tests.rscrates/adaptive/tests/unit/types_tests.rscrates/python/tests/coverage/py_storage_coverage_tests.rs
📜 Review details
🧰 Additional context used
📓 Path-based instructions (15)
**/*.rs
📄 CodeRabbit inference engine (.agents/skills/prepare-pr/SKILL.md)
**/*.rs: Any Rust change must runjust test-rust
Any Rust change must runcargo fmt --all
Any Rust change must runcargo clippy --workspace --all-targets -- -D warnings
**/*.rs: Runcargo fmt --allfor all FFI work since it is Rust work
Runjust test-rustto validate FFI changes
Runcargo clippy --workspace --all-targets -- -D warningsto enforce strict linting on FFI workWhen Rust files changed as part of Go work, also run
cargo fmt --all,just test-rust, andcargo clippy --workspace --all-targets -- -D warnings
**/*.rs: Runcargo fmt --allwhen Rust files are changed as part of Node work
Runcargo clippy --workspace --all-targets -- -D warningswhen Rust files are changed as part of Node work
Runjust test-rustwhen Rust files are changed as part of Node workWhen changing the core Rust runtime or Rust-facing API surface, format Rust code with
cargo fmt(rustfmt defaults), keepcargo clippy -- -D warningsclean, and satisfycargo deny checkperdeny.toml.
**/*.rs: If any Rust code changed, always runjust test-rust.
If any Rust code changed, also runcargo fmt --all.
If any Rust code changed, also runcargo clippy --workspace --all-targets -- -D warnings.
For Rust changes headed for review, runcargo fmt --allandcargo clippy --workspace --all-targets -- -D warningseven if relying on pre-commit.
Files:
crates/adaptive/tests/unit/intercepts_tests.rscrates/python/tests/coverage/py_storage_coverage_tests.rscrates/adaptive/tests/unit/acg/economics_internal_tests.rscrates/adaptive/tests/unit/acg/stability_internal_tests.rscrates/adaptive/tests/unit/storage_memory_internal_tests.rscrates/adaptive/tests/unit/acg/multi_breakpoint_tests.rscrates/adaptive/tests/unit/storage_tests.rscrates/adaptive/tests/unit/cache_diagnostics_tests.rscrates/adaptive/tests/unit/acg/economics_policy_tests.rscrates/adaptive/src/acg_learner.rscrates/adaptive/tests/integration/redis_tests.rscrates/adaptive/src/acg_component.rscrates/adaptive/tests/unit/acg_learner_tests.rscrates/adaptive/tests/unit/acg_profile_tests.rscrates/adaptive/tests/unit/runtime_features_tests.rscrates/adaptive/tests/unit/types_tests.rscrates/adaptive/src/acg/stability.rscrates/adaptive/tests/unit/runtime_tests.rscrates/adaptive/src/acg_profile.rscrates/adaptive/tests/integration/runtime_integration_tests.rscrates/adaptive/src/acg/ir_builder.rscrates/adaptive/tests/unit/acg_component_tests.rscrates/adaptive/tests/unit/acg/ir_builder_tests.rs
{crates/core,crates/adaptive}/**/*
📄 CodeRabbit inference engine (.agents/skills/prepare-pr/SKILL.md)
Changes to
crates/coreorcrates/adaptivemust run the full language matrix
Files:
crates/adaptive/tests/unit/intercepts_tests.rscrates/adaptive/tests/unit/acg/economics_internal_tests.rscrates/adaptive/tests/unit/acg/stability_internal_tests.rscrates/adaptive/tests/unit/storage_memory_internal_tests.rscrates/adaptive/tests/unit/acg/multi_breakpoint_tests.rscrates/adaptive/tests/unit/storage_tests.rscrates/adaptive/tests/unit/cache_diagnostics_tests.rscrates/adaptive/tests/unit/acg/economics_policy_tests.rscrates/adaptive/src/acg_learner.rscrates/adaptive/tests/integration/redis_tests.rscrates/adaptive/src/acg_component.rscrates/adaptive/tests/unit/acg_learner_tests.rscrates/adaptive/tests/unit/acg_profile_tests.rscrates/adaptive/tests/unit/runtime_features_tests.rscrates/adaptive/tests/unit/types_tests.rscrates/adaptive/src/acg/stability.rscrates/adaptive/tests/unit/runtime_tests.rscrates/adaptive/src/acg_profile.rscrates/adaptive/tests/integration/runtime_integration_tests.rscrates/adaptive/src/acg/ir_builder.rscrates/adaptive/tests/unit/acg_component_tests.rscrates/adaptive/tests/unit/acg/ir_builder_tests.rs
**/*.{rs,py}
📄 CodeRabbit inference engine (AGENTS.md)
Follow binding naming conventions in Rust and Python: use
snake_case.
Files:
crates/adaptive/tests/unit/intercepts_tests.rscrates/python/tests/coverage/py_storage_coverage_tests.rscrates/adaptive/tests/unit/acg/economics_internal_tests.rscrates/adaptive/tests/unit/acg/stability_internal_tests.rscrates/adaptive/tests/unit/storage_memory_internal_tests.rscrates/adaptive/tests/unit/acg/multi_breakpoint_tests.rscrates/adaptive/tests/unit/storage_tests.rscrates/adaptive/tests/unit/cache_diagnostics_tests.rscrates/adaptive/tests/unit/acg/economics_policy_tests.rscrates/adaptive/src/acg_learner.rscrates/adaptive/tests/integration/redis_tests.rscrates/adaptive/src/acg_component.rscrates/adaptive/tests/unit/acg_learner_tests.rscrates/adaptive/tests/unit/acg_profile_tests.rscrates/adaptive/tests/unit/runtime_features_tests.rscrates/adaptive/tests/unit/types_tests.rscrates/adaptive/src/acg/stability.rscrates/adaptive/tests/unit/runtime_tests.rscrates/adaptive/src/acg_profile.rscrates/adaptive/tests/integration/runtime_integration_tests.rscrates/adaptive/src/acg/ir_builder.rscrates/adaptive/tests/unit/acg_component_tests.rscrates/adaptive/tests/unit/acg/ir_builder_tests.rs
**/*.{rs,py,js,mjs,cjs,ts,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
**/*.{rs,py,js,mjs,cjs,ts,tsx}: UseJson = serde_json::Valuein Rust-facing runtime APIs where the existing code expects JSON payloads.
UseResult<T>withFlowErrorin core runtime paths, and keep errors explicit and binding-appropriate at the wrapper layer.
Keep async behavior on the existing tokio-based model; bindings should preserve callback and future lifetimes rather than blocking or hiding async work unexpectedly.
Files:
crates/adaptive/tests/unit/intercepts_tests.rscrates/python/tests/coverage/py_storage_coverage_tests.rscrates/adaptive/tests/unit/acg/economics_internal_tests.rscrates/adaptive/tests/unit/acg/stability_internal_tests.rscrates/adaptive/tests/unit/storage_memory_internal_tests.rscrates/adaptive/tests/unit/acg/multi_breakpoint_tests.rscrates/adaptive/tests/unit/storage_tests.rscrates/adaptive/tests/unit/cache_diagnostics_tests.rscrates/adaptive/tests/unit/acg/economics_policy_tests.rscrates/adaptive/src/acg_learner.rscrates/adaptive/tests/integration/redis_tests.rscrates/adaptive/src/acg_component.rscrates/adaptive/tests/unit/acg_learner_tests.rscrates/adaptive/tests/unit/acg_profile_tests.rscrates/adaptive/tests/unit/runtime_features_tests.rscrates/adaptive/tests/unit/types_tests.rscrates/adaptive/src/acg/stability.rscrates/adaptive/tests/unit/runtime_tests.rscrates/adaptive/src/acg_profile.rscrates/adaptive/tests/integration/runtime_integration_tests.rscrates/adaptive/src/acg/ir_builder.rscrates/adaptive/tests/unit/acg_component_tests.rscrates/adaptive/tests/unit/acg/ir_builder_tests.rs
**/*.{rs,py,go,js,ts,c,h}
📄 CodeRabbit inference engine (CONTRIBUTING.md)
Use language-appropriate naming conventions: Rust
snake_case, C FFI exports prefixednemo_relay_, GoPascalCase, Node.jscamelCase, and Pythonsnake_case.
Files:
crates/adaptive/tests/unit/intercepts_tests.rscrates/python/tests/coverage/py_storage_coverage_tests.rscrates/adaptive/tests/unit/acg/economics_internal_tests.rscrates/adaptive/tests/unit/acg/stability_internal_tests.rscrates/adaptive/tests/unit/storage_memory_internal_tests.rscrates/adaptive/tests/unit/acg/multi_breakpoint_tests.rscrates/adaptive/tests/unit/storage_tests.rscrates/adaptive/tests/unit/cache_diagnostics_tests.rscrates/adaptive/tests/unit/acg/economics_policy_tests.rscrates/adaptive/src/acg_learner.rscrates/adaptive/tests/integration/redis_tests.rscrates/adaptive/src/acg_component.rscrates/adaptive/tests/unit/acg_learner_tests.rscrates/adaptive/tests/unit/acg_profile_tests.rscrates/adaptive/tests/unit/runtime_features_tests.rscrates/adaptive/tests/unit/types_tests.rscrates/adaptive/src/acg/stability.rscrates/adaptive/tests/unit/runtime_tests.rscrates/adaptive/src/acg_profile.rscrates/adaptive/tests/integration/runtime_integration_tests.rscrates/adaptive/src/acg/ir_builder.rscrates/adaptive/tests/unit/acg_component_tests.rscrates/adaptive/tests/unit/acg/ir_builder_tests.rs
**/*.{rs,go,js,ts}
📄 CodeRabbit inference engine (CONTRIBUTING.md)
Add the SPDX license header to all Rust, Go, JavaScript, and TypeScript source files using the corresponding
//comment form.
Files:
crates/adaptive/tests/unit/intercepts_tests.rscrates/python/tests/coverage/py_storage_coverage_tests.rscrates/adaptive/tests/unit/acg/economics_internal_tests.rscrates/adaptive/tests/unit/acg/stability_internal_tests.rscrates/adaptive/tests/unit/storage_memory_internal_tests.rscrates/adaptive/tests/unit/acg/multi_breakpoint_tests.rscrates/adaptive/tests/unit/storage_tests.rscrates/adaptive/tests/unit/cache_diagnostics_tests.rscrates/adaptive/tests/unit/acg/economics_policy_tests.rscrates/adaptive/src/acg_learner.rscrates/adaptive/tests/integration/redis_tests.rscrates/adaptive/src/acg_component.rscrates/adaptive/tests/unit/acg_learner_tests.rscrates/adaptive/tests/unit/acg_profile_tests.rscrates/adaptive/tests/unit/runtime_features_tests.rscrates/adaptive/tests/unit/types_tests.rscrates/adaptive/src/acg/stability.rscrates/adaptive/tests/unit/runtime_tests.rscrates/adaptive/src/acg_profile.rscrates/adaptive/tests/integration/runtime_integration_tests.rscrates/adaptive/src/acg/ir_builder.rscrates/adaptive/tests/unit/acg_component_tests.rscrates/adaptive/tests/unit/acg/ir_builder_tests.rs
crates/adaptive/**
📄 CodeRabbit inference engine (.agents/skills/maintain-optimizer/SKILL.md)
Keep
crates/adaptivealigned with the canonical adaptive config schema, built-in section helpers, plugin lifecycle, and validation/report behavior.
Files:
crates/adaptive/tests/unit/intercepts_tests.rscrates/adaptive/tests/unit/acg/economics_internal_tests.rscrates/adaptive/tests/unit/acg/stability_internal_tests.rscrates/adaptive/tests/unit/storage_memory_internal_tests.rscrates/adaptive/tests/unit/acg/multi_breakpoint_tests.rscrates/adaptive/tests/unit/storage_tests.rscrates/adaptive/tests/unit/cache_diagnostics_tests.rscrates/adaptive/tests/unit/acg/economics_policy_tests.rscrates/adaptive/src/acg_learner.rscrates/adaptive/tests/integration/redis_tests.rscrates/adaptive/src/acg_component.rscrates/adaptive/tests/unit/acg_learner_tests.rscrates/adaptive/tests/unit/acg_profile_tests.rscrates/adaptive/tests/unit/runtime_features_tests.rscrates/adaptive/tests/unit/types_tests.rscrates/adaptive/src/acg/stability.rscrates/adaptive/tests/unit/runtime_tests.rscrates/adaptive/src/acg_profile.rscrates/adaptive/tests/integration/runtime_integration_tests.rscrates/adaptive/src/acg/ir_builder.rscrates/adaptive/tests/unit/acg_component_tests.rscrates/adaptive/tests/unit/acg/ir_builder_tests.rs
**/*
📄 CodeRabbit inference engine (.agents/skills/validate-change/SKILL.md)
**/*: Format changed files with the language-native formatter before the final lint/test pass.
If dynamic plugin behavior changed, usemaintain-dynamic-pluginsand include the native SDK, worker protocol, Python SDK, docs, packaging, and Codecov surfaces in the validation plan.
If code changes alter APIs, bindings, commands, paths, packaging behavior, observability/adaptive semantics, or documented best practices, update any dependent maintainer or consumer skills in the same branch.
During iteration, preferuv run pre-commit run --files <changed files...>.
Before review or handoff, runuv run pre-commit run --all-files.
Files:
crates/adaptive/tests/unit/intercepts_tests.rscrates/python/tests/coverage/py_storage_coverage_tests.rscrates/adaptive/tests/unit/acg/economics_internal_tests.rscrates/adaptive/tests/unit/acg/stability_internal_tests.rscrates/adaptive/tests/unit/storage_memory_internal_tests.rscrates/adaptive/tests/unit/acg/multi_breakpoint_tests.rscrates/adaptive/tests/unit/storage_tests.rscrates/adaptive/tests/unit/cache_diagnostics_tests.rscrates/adaptive/tests/unit/acg/economics_policy_tests.rscrates/adaptive/src/acg_learner.rscrates/adaptive/tests/integration/redis_tests.rscrates/adaptive/src/acg_component.rscrates/adaptive/tests/unit/acg_learner_tests.rscrates/adaptive/tests/unit/acg_profile_tests.rscrates/adaptive/tests/unit/runtime_features_tests.rscrates/adaptive/tests/unit/types_tests.rscrates/adaptive/src/acg/stability.rscrates/adaptive/tests/unit/runtime_tests.rscrates/adaptive/src/acg_profile.rscrates/adaptive/tests/integration/runtime_integration_tests.rscrates/adaptive/src/acg/ir_builder.rscrates/adaptive/tests/unit/acg_component_tests.rscrates/adaptive/tests/unit/acg/ir_builder_tests.rs
crates/{core,adaptive}/**/*
📄 CodeRabbit inference engine (.agents/skills/validate-change/SKILL.md)
If
crates/coreorcrates/adaptivechanged, run the full validation matrix across Rust, Python, Go, and Node.js.
Files:
crates/adaptive/tests/unit/intercepts_tests.rscrates/adaptive/tests/unit/acg/economics_internal_tests.rscrates/adaptive/tests/unit/acg/stability_internal_tests.rscrates/adaptive/tests/unit/storage_memory_internal_tests.rscrates/adaptive/tests/unit/acg/multi_breakpoint_tests.rscrates/adaptive/tests/unit/storage_tests.rscrates/adaptive/tests/unit/cache_diagnostics_tests.rscrates/adaptive/tests/unit/acg/economics_policy_tests.rscrates/adaptive/src/acg_learner.rscrates/adaptive/tests/integration/redis_tests.rscrates/adaptive/src/acg_component.rscrates/adaptive/tests/unit/acg_learner_tests.rscrates/adaptive/tests/unit/acg_profile_tests.rscrates/adaptive/tests/unit/runtime_features_tests.rscrates/adaptive/tests/unit/types_tests.rscrates/adaptive/src/acg/stability.rscrates/adaptive/tests/unit/runtime_tests.rscrates/adaptive/src/acg_profile.rscrates/adaptive/tests/integration/runtime_integration_tests.rscrates/adaptive/src/acg/ir_builder.rscrates/adaptive/tests/unit/acg_component_tests.rscrates/adaptive/tests/unit/acg/ir_builder_tests.rs
**/*.{rs,py,go,js,ts}
📄 CodeRabbit inference engine (.agents/skills/validate-change/SKILL.md)
If a language surface changed, always run that language's test target even when Rust core did not change.
Files:
crates/adaptive/tests/unit/intercepts_tests.rscrates/python/tests/coverage/py_storage_coverage_tests.rscrates/adaptive/tests/unit/acg/economics_internal_tests.rscrates/adaptive/tests/unit/acg/stability_internal_tests.rscrates/adaptive/tests/unit/storage_memory_internal_tests.rscrates/adaptive/tests/unit/acg/multi_breakpoint_tests.rscrates/adaptive/tests/unit/storage_tests.rscrates/adaptive/tests/unit/cache_diagnostics_tests.rscrates/adaptive/tests/unit/acg/economics_policy_tests.rscrates/adaptive/src/acg_learner.rscrates/adaptive/tests/integration/redis_tests.rscrates/adaptive/src/acg_component.rscrates/adaptive/tests/unit/acg_learner_tests.rscrates/adaptive/tests/unit/acg_profile_tests.rscrates/adaptive/tests/unit/runtime_features_tests.rscrates/adaptive/tests/unit/types_tests.rscrates/adaptive/src/acg/stability.rscrates/adaptive/tests/unit/runtime_tests.rscrates/adaptive/src/acg_profile.rscrates/adaptive/tests/integration/runtime_integration_tests.rscrates/adaptive/src/acg/ir_builder.rscrates/adaptive/tests/unit/acg_component_tests.rscrates/adaptive/tests/unit/acg/ir_builder_tests.rs
**/*.{rs,py,js,ts,tsx,go,java,kt,swift}
📄 CodeRabbit inference engine (.agents/skills/add-middleware/SKILL.md)
Add tests covering registration and duplicate names, deregistration and missing names, priority ordering, callback failure policy, scope-local inheritance and cleanup, event payload semantics, immutable mark and scope fields, and parity across affected bindings.
Files:
crates/adaptive/tests/unit/intercepts_tests.rscrates/python/tests/coverage/py_storage_coverage_tests.rscrates/adaptive/tests/unit/acg/economics_internal_tests.rscrates/adaptive/tests/unit/acg/stability_internal_tests.rscrates/adaptive/tests/unit/storage_memory_internal_tests.rscrates/adaptive/tests/unit/acg/multi_breakpoint_tests.rscrates/adaptive/tests/unit/storage_tests.rscrates/adaptive/tests/unit/cache_diagnostics_tests.rscrates/adaptive/tests/unit/acg/economics_policy_tests.rscrates/adaptive/src/acg_learner.rscrates/adaptive/tests/integration/redis_tests.rscrates/adaptive/src/acg_component.rscrates/adaptive/tests/unit/acg_learner_tests.rscrates/adaptive/tests/unit/acg_profile_tests.rscrates/adaptive/tests/unit/runtime_features_tests.rscrates/adaptive/tests/unit/types_tests.rscrates/adaptive/src/acg/stability.rscrates/adaptive/tests/unit/runtime_tests.rscrates/adaptive/src/acg_profile.rscrates/adaptive/tests/integration/runtime_integration_tests.rscrates/adaptive/src/acg/ir_builder.rscrates/adaptive/tests/unit/acg_component_tests.rscrates/adaptive/tests/unit/acg/ir_builder_tests.rs
crates/{core,adaptive}/**/*.rs
⚙️ CodeRabbit configuration file
crates/{core,adaptive}/**/*.rs: Review the Rust runtime for async correctness, scope isolation, middleware ordering, and event lifecycle regressions.
Pay close attention to task-local/thread-local scope propagation, callback lifetimes, stream finalization, and root_uuid isolation.
Public API changes should preserve existing behavior unless tests and docs show the intended migration path.
Files:
crates/adaptive/tests/unit/intercepts_tests.rscrates/adaptive/tests/unit/acg/economics_internal_tests.rscrates/adaptive/tests/unit/acg/stability_internal_tests.rscrates/adaptive/tests/unit/storage_memory_internal_tests.rscrates/adaptive/tests/unit/acg/multi_breakpoint_tests.rscrates/adaptive/tests/unit/storage_tests.rscrates/adaptive/tests/unit/cache_diagnostics_tests.rscrates/adaptive/tests/unit/acg/economics_policy_tests.rscrates/adaptive/src/acg_learner.rscrates/adaptive/tests/integration/redis_tests.rscrates/adaptive/src/acg_component.rscrates/adaptive/tests/unit/acg_learner_tests.rscrates/adaptive/tests/unit/acg_profile_tests.rscrates/adaptive/tests/unit/runtime_features_tests.rscrates/adaptive/tests/unit/types_tests.rscrates/adaptive/src/acg/stability.rscrates/adaptive/tests/unit/runtime_tests.rscrates/adaptive/src/acg_profile.rscrates/adaptive/tests/integration/runtime_integration_tests.rscrates/adaptive/src/acg/ir_builder.rscrates/adaptive/tests/unit/acg_component_tests.rscrates/adaptive/tests/unit/acg/ir_builder_tests.rs
{crates/**/tests/**,python/tests/**,go/nemo_relay/**/*_test.go}
⚙️ CodeRabbit configuration file
{crates/**/tests/**,python/tests/**,go/nemo_relay/**/*_test.go}: Tests should cover the behavior promised by the changed API surface, including error paths and cross-request isolation where relevant.
Prefer assertions on lifecycle events, scope stacks, middleware ordering, and binding parity over shallow smoke tests.
Files:
crates/adaptive/tests/unit/intercepts_tests.rscrates/python/tests/coverage/py_storage_coverage_tests.rscrates/adaptive/tests/unit/acg/economics_internal_tests.rscrates/adaptive/tests/unit/acg/stability_internal_tests.rscrates/adaptive/tests/unit/storage_memory_internal_tests.rscrates/adaptive/tests/unit/acg/multi_breakpoint_tests.rscrates/adaptive/tests/unit/storage_tests.rscrates/adaptive/tests/unit/cache_diagnostics_tests.rscrates/adaptive/tests/unit/acg/economics_policy_tests.rscrates/adaptive/tests/integration/redis_tests.rscrates/adaptive/tests/unit/acg_learner_tests.rscrates/adaptive/tests/unit/acg_profile_tests.rscrates/adaptive/tests/unit/runtime_features_tests.rscrates/adaptive/tests/unit/types_tests.rscrates/adaptive/tests/unit/runtime_tests.rscrates/adaptive/tests/integration/runtime_integration_tests.rscrates/adaptive/tests/unit/acg_component_tests.rscrates/adaptive/tests/unit/acg/ir_builder_tests.rs
crates/{python,ffi,node}/**/*
⚙️ CodeRabbit configuration file
crates/{python,ffi,node}/**/*: Treat binding changes as public API changes. Check for parity with the other language bindings, FFI ownership/lifetime safety,
callback error propagation, stable type conversion, and consistent async/stream semantics.
Flag changes that update one binding without corresponding tests or documentation for the same surface elsewhere.
Files:
crates/python/tests/coverage/py_storage_coverage_tests.rs
{crates/**/src/**/*.rs,python/**/*.py}
📄 CodeRabbit inference engine (.agents/skills/maintain-dynamic-plugins/SKILL.md)
Do not add tests under
src; Rust tests belong in cratetests/trees, and Python SDK tests belong underpython/tests.
Files:
crates/adaptive/src/acg_learner.rscrates/adaptive/src/acg_component.rscrates/adaptive/src/acg/stability.rscrates/adaptive/src/acg_profile.rscrates/adaptive/src/acg/ir_builder.rs
🔇 Additional comments (22)
crates/adaptive/src/acg/ir_builder.rs (1)
35-83: LGTM!Also applies to: 263-284
crates/adaptive/src/acg_profile.rs (1)
33-46: LGTM!Also applies to: 71-100, 225-232
crates/adaptive/tests/unit/acg/ir_builder_tests.rs (1)
191-251: LGTM!crates/adaptive/tests/unit/acg_profile_tests.rs (1)
49-145: LGTM!crates/adaptive/tests/unit/runtime_tests.rs (1)
416-417: LGTM!Also applies to: 493-495
crates/adaptive/tests/unit/acg_learner_tests.rs (1)
231-267: LGTM!crates/adaptive/tests/unit/runtime_features_tests.rs (1)
90-97: LGTM!Also applies to: 123-127
crates/python/tests/coverage/py_storage_coverage_tests.rs (1)
143-143: LGTM!crates/adaptive/tests/unit/acg/economics_internal_tests.rs (1)
124-124: LGTM!crates/adaptive/tests/unit/acg_component_tests.rs (1)
50-50: LGTM!Also applies to: 235-235, 266-266, 291-311, 454-458, 534-538, 584-605, 646-646, 677-681, 737-737, 815-846, 945-950, 982-1131, 1185-1185, 1240-1240, 1287-1291, 1390-1390, 1431-1435, 1569-1573
crates/adaptive/src/acg_component.rs (1)
136-162: LGTM!crates/adaptive/tests/integration/runtime_integration_tests.rs (1)
516-517: LGTM!crates/adaptive/src/acg/stability.rs (1)
42-145: LGTM!crates/adaptive/src/acg_learner.rs (1)
108-114: 📐 Maintainability & Code QualityProvide the required validation evidence.
The supplied summary does not confirm
cargo fmt --all,just test-rust, or the required Rust/Python/Go/Node matrix for thiscrates/adaptivechange. Please run and attach results forcargo fmt --all,cargo clippy --workspace --all-targets -- -D warnings,just test-rust, and the repository’s full language matrix.As per coding guidelines, “Any Rust change must run
just test-rust,” “Any Rust change must runcargo fmt --all,” and “Any Rust change must runcargo clippy --workspace --all-targets -- -D warnings.” As per path instructions, “Changes tocrates/coreorcrates/adaptivemust run the full language matrix.”Sources: Coding guidelines, Path instructions
crates/adaptive/tests/unit/acg/stability_internal_tests.rs (1)
81-121: LGTM!crates/adaptive/tests/unit/types_tests.rs (1)
44-44: LGTM!Also applies to: 200-208
crates/adaptive/tests/unit/acg/economics_policy_tests.rs (1)
87-87: LGTM!crates/adaptive/tests/unit/acg/multi_breakpoint_tests.rs (1)
84-84: LGTM!crates/adaptive/tests/unit/cache_diagnostics_tests.rs (1)
85-85: LGTM!crates/adaptive/tests/unit/intercepts_tests.rs (1)
53-53: LGTM!crates/adaptive/tests/unit/storage_memory_internal_tests.rs (1)
87-87: LGTM!crates/adaptive/tests/unit/storage_tests.rs (1)
92-92: LGTM!
Signed-off-by: teerthsharma <teerths57@Gmail.com>
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
crates/adaptive/tests/integration/redis_tests.rs (1)
551-553: 🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick winAssert fingerprint equality across the restart.
is_some()would also pass for a stale or changed fingerprint, so this test does not prove that the serialized value survived backend recreation. Capture the pre-restart fingerprint forlearning_keyand compare it with the reloaded value.As per path instructions, “Tests should cover the behavior promised by the changed API surface, including error paths and cross-request isolation where relevant.”
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@crates/adaptive/tests/integration/redis_tests.rs` around lines 551 - 553, Update the restart persistence test around the stability assertions to capture the pre-restart stable_prefix_fingerprint for learning_key before recreating the backend, then assert the reloaded fingerprint equals that captured value rather than only checking is_some(). Preserve the existing observation-count assertions.Source: Path instructions
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@crates/adaptive/tests/integration/redis_tests.rs`:
- Around line 551-553: Update the restart persistence test around the stability
assertions to capture the pre-restart stable_prefix_fingerprint for learning_key
before recreating the backend, then assert the reloaded fingerprint equals that
captured value rather than only checking is_some(). Preserve the existing
observation-count assertions.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Enterprise
Run ID: bd62dbe9-c14b-4043-8324-462a452bb69d
📒 Files selected for processing (4)
crates/adaptive/src/acg/stability.rscrates/adaptive/src/acg_profile.rscrates/adaptive/tests/integration/redis_tests.rscrates/adaptive/tests/unit/acg/stability_internal_tests.rs
📜 Review details
🧰 Additional context used
📓 Path-based instructions (14)
**/*.rs
📄 CodeRabbit inference engine (.agents/skills/prepare-pr/SKILL.md)
**/*.rs: Any Rust change must runjust test-rust
Any Rust change must runcargo fmt --all
Any Rust change must runcargo clippy --workspace --all-targets -- -D warnings
**/*.rs: Runcargo fmt --allfor all FFI work since it is Rust work
Runjust test-rustto validate FFI changes
Runcargo clippy --workspace --all-targets -- -D warningsto enforce strict linting on FFI workWhen Rust files changed as part of Go work, also run
cargo fmt --all,just test-rust, andcargo clippy --workspace --all-targets -- -D warnings
**/*.rs: Runcargo fmt --allwhen Rust files are changed as part of Node work
Runcargo clippy --workspace --all-targets -- -D warningswhen Rust files are changed as part of Node work
Runjust test-rustwhen Rust files are changed as part of Node workWhen changing the core Rust runtime or Rust-facing API surface, format Rust code with
cargo fmt(rustfmt defaults), keepcargo clippy -- -D warningsclean, and satisfycargo deny checkperdeny.toml.
**/*.rs: If any Rust code changed, always runjust test-rust.
If any Rust code changed, also runcargo fmt --all.
If any Rust code changed, also runcargo clippy --workspace --all-targets -- -D warnings.
For Rust changes headed for review, runcargo fmt --allandcargo clippy --workspace --all-targets -- -D warningseven if relying on pre-commit.
Files:
crates/adaptive/tests/integration/redis_tests.rscrates/adaptive/tests/unit/acg/stability_internal_tests.rscrates/adaptive/src/acg_profile.rscrates/adaptive/src/acg/stability.rs
{crates/core,crates/adaptive}/**/*
📄 CodeRabbit inference engine (.agents/skills/prepare-pr/SKILL.md)
Changes to
crates/coreorcrates/adaptivemust run the full language matrix
Files:
crates/adaptive/tests/integration/redis_tests.rscrates/adaptive/tests/unit/acg/stability_internal_tests.rscrates/adaptive/src/acg_profile.rscrates/adaptive/src/acg/stability.rs
**/*.{rs,py}
📄 CodeRabbit inference engine (AGENTS.md)
Follow binding naming conventions in Rust and Python: use
snake_case.
Files:
crates/adaptive/tests/integration/redis_tests.rscrates/adaptive/tests/unit/acg/stability_internal_tests.rscrates/adaptive/src/acg_profile.rscrates/adaptive/src/acg/stability.rs
**/*.{rs,py,js,mjs,cjs,ts,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
**/*.{rs,py,js,mjs,cjs,ts,tsx}: UseJson = serde_json::Valuein Rust-facing runtime APIs where the existing code expects JSON payloads.
UseResult<T>withFlowErrorin core runtime paths, and keep errors explicit and binding-appropriate at the wrapper layer.
Keep async behavior on the existing tokio-based model; bindings should preserve callback and future lifetimes rather than blocking or hiding async work unexpectedly.
Files:
crates/adaptive/tests/integration/redis_tests.rscrates/adaptive/tests/unit/acg/stability_internal_tests.rscrates/adaptive/src/acg_profile.rscrates/adaptive/src/acg/stability.rs
**/*.{rs,py,go,js,ts,c,h}
📄 CodeRabbit inference engine (CONTRIBUTING.md)
Use language-appropriate naming conventions: Rust
snake_case, C FFI exports prefixednemo_relay_, GoPascalCase, Node.jscamelCase, and Pythonsnake_case.
Files:
crates/adaptive/tests/integration/redis_tests.rscrates/adaptive/tests/unit/acg/stability_internal_tests.rscrates/adaptive/src/acg_profile.rscrates/adaptive/src/acg/stability.rs
**/*.{rs,go,js,ts}
📄 CodeRabbit inference engine (CONTRIBUTING.md)
Add the SPDX license header to all Rust, Go, JavaScript, and TypeScript source files using the corresponding
//comment form.
Files:
crates/adaptive/tests/integration/redis_tests.rscrates/adaptive/tests/unit/acg/stability_internal_tests.rscrates/adaptive/src/acg_profile.rscrates/adaptive/src/acg/stability.rs
crates/adaptive/**
📄 CodeRabbit inference engine (.agents/skills/maintain-optimizer/SKILL.md)
Keep
crates/adaptivealigned with the canonical adaptive config schema, built-in section helpers, plugin lifecycle, and validation/report behavior.
Files:
crates/adaptive/tests/integration/redis_tests.rscrates/adaptive/tests/unit/acg/stability_internal_tests.rscrates/adaptive/src/acg_profile.rscrates/adaptive/src/acg/stability.rs
**/*
📄 CodeRabbit inference engine (.agents/skills/validate-change/SKILL.md)
**/*: Format changed files with the language-native formatter before the final lint/test pass.
If dynamic plugin behavior changed, usemaintain-dynamic-pluginsand include the native SDK, worker protocol, Python SDK, docs, packaging, and Codecov surfaces in the validation plan.
If code changes alter APIs, bindings, commands, paths, packaging behavior, observability/adaptive semantics, or documented best practices, update any dependent maintainer or consumer skills in the same branch.
During iteration, preferuv run pre-commit run --files <changed files...>.
Before review or handoff, runuv run pre-commit run --all-files.
Files:
crates/adaptive/tests/integration/redis_tests.rscrates/adaptive/tests/unit/acg/stability_internal_tests.rscrates/adaptive/src/acg_profile.rscrates/adaptive/src/acg/stability.rs
crates/{core,adaptive}/**/*
📄 CodeRabbit inference engine (.agents/skills/validate-change/SKILL.md)
If
crates/coreorcrates/adaptivechanged, run the full validation matrix across Rust, Python, Go, and Node.js.
Files:
crates/adaptive/tests/integration/redis_tests.rscrates/adaptive/tests/unit/acg/stability_internal_tests.rscrates/adaptive/src/acg_profile.rscrates/adaptive/src/acg/stability.rs
**/*.{rs,py,go,js,ts}
📄 CodeRabbit inference engine (.agents/skills/validate-change/SKILL.md)
If a language surface changed, always run that language's test target even when Rust core did not change.
Files:
crates/adaptive/tests/integration/redis_tests.rscrates/adaptive/tests/unit/acg/stability_internal_tests.rscrates/adaptive/src/acg_profile.rscrates/adaptive/src/acg/stability.rs
**/*.{rs,py,js,ts,tsx,go,java,kt,swift}
📄 CodeRabbit inference engine (.agents/skills/add-middleware/SKILL.md)
Add tests covering registration and duplicate names, deregistration and missing names, priority ordering, callback failure policy, scope-local inheritance and cleanup, event payload semantics, immutable mark and scope fields, and parity across affected bindings.
Files:
crates/adaptive/tests/integration/redis_tests.rscrates/adaptive/tests/unit/acg/stability_internal_tests.rscrates/adaptive/src/acg_profile.rscrates/adaptive/src/acg/stability.rs
crates/{core,adaptive}/**/*.rs
⚙️ CodeRabbit configuration file
crates/{core,adaptive}/**/*.rs: Review the Rust runtime for async correctness, scope isolation, middleware ordering, and event lifecycle regressions.
Pay close attention to task-local/thread-local scope propagation, callback lifetimes, stream finalization, and root_uuid isolation.
Public API changes should preserve existing behavior unless tests and docs show the intended migration path.
Files:
crates/adaptive/tests/integration/redis_tests.rscrates/adaptive/tests/unit/acg/stability_internal_tests.rscrates/adaptive/src/acg_profile.rscrates/adaptive/src/acg/stability.rs
{crates/**/tests/**,python/tests/**,go/nemo_relay/**/*_test.go}
⚙️ CodeRabbit configuration file
{crates/**/tests/**,python/tests/**,go/nemo_relay/**/*_test.go}: Tests should cover the behavior promised by the changed API surface, including error paths and cross-request isolation where relevant.
Prefer assertions on lifecycle events, scope stacks, middleware ordering, and binding parity over shallow smoke tests.
Files:
crates/adaptive/tests/integration/redis_tests.rscrates/adaptive/tests/unit/acg/stability_internal_tests.rs
{crates/**/src/**/*.rs,python/**/*.py}
📄 CodeRabbit inference engine (.agents/skills/maintain-dynamic-plugins/SKILL.md)
Do not add tests under
src; Rust tests belong in cratetests/trees, and Python SDK tests belong underpython/tests.
Files:
crates/adaptive/src/acg_profile.rscrates/adaptive/src/acg/stability.rs
🔇 Additional comments (4)
crates/adaptive/src/acg_profile.rs (1)
18-19: LGTM!Also applies to: 33-46, 71-102, 216-224
crates/adaptive/src/acg/stability.rs (1)
42-46: LGTM!Also applies to: 77-77, 98-118, 121-200
crates/adaptive/tests/integration/redis_tests.rs (1)
518-546: LGTM!crates/adaptive/tests/unit/acg/stability_internal_tests.rs (1)
81-109: LGTM!Also applies to: 111-121, 123-135
Overview
ACG currently includes the first non-system message in its learning key. That fragments otherwise identical system/tool/output scaffolds whenever the first user task changes, so observations never converge into a reusable profile.
This draft keeps the change inside the existing ACG path:
bucket learning by the full stable system/tool/structured-output scaffold while preserving the prior task seed for requests without a scaffold;
populate the existing
structured_output_schema_idand model the response format as a stable IR block;bind learned reuse fingerprints to the exact scaffold key, and conservatively to the full source request when a learned prefix extends beyond that scaffold;
fail open for legacy, missing, shorter, or mismatched fingerprints.
I confirm this contribution is my own work, or I have the right to submit it under this project's license.
I searched existing issues and open pull requests, and this does not duplicate existing work.
Details
The implementation deliberately excludes the governor, drift detector, convergence machinery, configuration expansion, and public binding helpers proposed in #322. It uses the current learner, storage, hot cache, and provider translators.
Coverage includes variable first-user tasks, changed system/tool/output contracts, canonical structured output, raw-whitespace changes hidden by normalized IR, prefixes extending beyond the scaffold, legacy persisted state, same-run aggregation, fresh-cache rehydration, Redis backend restart, and serialization compatibility.
Validation completed locally:
cargo test -p nemo-relay-adaptive --quiet: 482 unit, 8 surface, and 12 runtime-integration tests passed; doctests passed.cargo clippy -p nemo-relay-adaptive -p nemo-relay-python --all-targets -- -D warningspassed.just test-python: 531 passed, 4 skipped.just test-node: 263 passed, 2 skipped.Repository-wide limitations on this Windows host are not hidden:
just test-rustreaches unrelated existing CLI/DACL filesystem failures,just test-gorequires an unavailableclang/lld, and docs validation reports zero content errors before a later Windows libuv assertion. CI should provide the authoritative Linux matrix.No provider-cache, cost, or latency improvement is claimed by this PR. A prior interleaved three-arm run demonstrated the internal fragmentation (144 keys/0 hints versus 1 key/120 hints) but used an older main revision and a benchmark overlay, so it is not presented as final performance evidence for this diff.
Persisted JSON remains backward-compatible through an optional fingerprint field. The added field is source-visible to downstream Rust code that constructs
StabilityAnalysisResultwith a struct literal.Where should the reviewer start?
Start with
crates/adaptive/src/acg_profile.rsfor the learning-key boundary, thencrates/adaptive/src/acg/stability.rsandcrates/adaptive/src/acg_component.rsfor exact reuse validation. The focused behavior tests are incrates/adaptive/tests/unit/acg_profile_tests.rsandcrates/adaptive/tests/unit/acg_component_tests.rs.Related Issues: (use one of the action keywords Closes / Fixes / Resolves / Relates to)
Summary by CodeRabbit