Skip to content

Feat/phase4 fe features - #18

Merged
ravin00 merged 33 commits into
mainfrom
feat/phase4-fe-features
Aug 6, 2026
Merged

Feat/phase4 fe features#18
ravin00 merged 33 commits into
mainfrom
feat/phase4-fe-features

Conversation

@ravin00

@ravin00 ravin00 commented Aug 5, 2026

Copy link
Copy Markdown
Owner

Summary

Adds the 47-dimensional state-vector computation and the /state/{workloadName}
HTTP endpoint. This closes Phase 4's core loop: JSONL events from Phase 3
now feed a per-workload sliding window that gets projected into the fixed
observation shape the RL agent (Phase 5) will consume.

  • IFeatureGroup composition with 8 concrete groups covering dims 0–46:
    Cpu, Memory, AppSignal, NodePressure, Cost, Temporal, Deployment,
    ActionHistory.
  • StateVectorBuilder validates that groups cover [0, 47) contiguously
    at construction time, dispatches each group to its span slice, then
    clamps [-2, 2] and coerces NaN / ±Inf → 0.
  • StateVector record with Dimensions = 47 invariant.
  • Minimal-API GET /state/{workloadName} returns 404 for unknown
    workloads or 200 with a float[47] JSON body. Companion
    /state/{workloadName}/latest returns the same values with the
    timestamp for debugging.
  • Cost coefficients (ConfiguredBudgetUsdPerHour, CpuCostPerCoreHourUsd,
    MemCostPerGiBHourUsd) added to FeatureEngineeringOptions and
    appsettings.json so they're overridable at deploy time.
  • New packages: MathNet.Numerics 5.0 for percentile computation;
    Microsoft.AspNetCore.Mvc.Testing 8.0.11 for the endpoint integration
    test.

Design decisions

  • CPU / memory layout — percentiles only. Each 9-dim slot is
    {P50, P95, P99} × {5m, 15m, 1h} of usage / limit. CpuLimit /
    MemLimit act as normalisation denominators, not standalone dims — this
    is what makes the 47-total add up.
  • App-signal dim 23 reserved (0f). Doc names 5 quantities for a
    6-dim group; keeping the slot at zero preserves indices for a future
    signal without shifting the vector.
  • Placeholder groups. Deployment (35–37), action-history (38–46) and
    cost 7-day-trend (28) return zeros or fixed placeholders. Real values
    come from Phase 6 (K8s informer) and Phase 8 (Cosmos DB trend store) —
    documented as such in code.
  • Interface + composition, not selection. IFeatureGroup is used
    compositionally (all 8 groups always run), unlike IMetricEventConsumer
    and IStateVectorPublisher which are config-switched strategies.

Test plan

  • dotnet build AFIE.slnx — clean
  • dotnet test AFIE.slnx — 52 passing (20 telemetry + 32 FE)
  • WebApplicationFactory-backed endpoint test: /state/missing
    returns 404, /state/nginx-endpoint-test returns 47-length array
  • TemporalFeatures: midnight sin=0 / cos=1; hour-adjacent and
    day-of-week-adjacent boundaries within 0.01 of each other
  • StateVectorBuilder ctor throws when groups don't sum to 47 or
    leave a gap
  • Local smoke: dotnet run + append MetricEvent to today's JSONL,
    confirm curl /state/nginx | jq 'length' returns 47 and all
    values fall in [-1, 1]

Summary by CodeRabbit

  • New Features
    • Added endpoints for retrieving current and latest timestamped workload state data.
    • Added 47-dimensional state vectors covering resource, cost, deployment, temporal, application, pressure, and action-history signals.
    • Added configurable hourly budget and resource cost settings.
  • Bug Fixes
    • Unknown workloads now return a not-found response.
    • State values are validated, bounded, and kept finite.
  • Tests
    • Added coverage for state endpoints, feature calculations, validation, and edge cases.

ravin00 added 26 commits August 4, 2026 21:10
@ravin00
ravin00 requested review from Dinuda and a lite review from Copilot and removed request for Copilot August 5, 2026 11:54
@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown

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
📝 Walkthrough

Walkthrough

The project adds feature-group computation for a 47-dimensional state vector, state-vector assembly and sanitization, dependency-injection wiring, and HTTP endpoints with integration tests.

Changes

Feature engineering state flow

Layer / File(s) Summary
Feature contracts and group computations
src/api/feature-engineering/Models/*, src/api/feature-engineering/Features/*, src/api/feature-engineering/AFIE.FeatureEngineering.csproj, tests/AFIE.FeatureEngineering.Tests/Features/*, tests/AFIE.FeatureEngineering.Tests/Models/*
Defines feature inputs, 47 state dimensions, cost options, feature calculations, and unit tests for feature outputs.
State-vector assembly and sanitization
src/api/feature-engineering/Features/StateVectorBuilder.cs, tests/AFIE.FeatureEngineering.Tests/Features/StateVectorBuilderTests.cs
Validates contiguous dimensions, computes values, converts non-finite results to zero, clamps results, and validates vector length.
Endpoint wiring and integration coverage
src/api/feature-engineering/Program.cs, src/api/feature-engineering/Endpoints/StateEndpoints.cs, src/api/feature-engineering/appsettings.json, tests/AFIE.FeatureEngineering.Tests/Endpoints/*, tests/AFIE.FeatureEngineering.Tests/AFIE.FeatureEngineering.Tests.csproj
Registers feature services, adds cost settings, renames the EventHub storage key, maps state endpoints, and tests 404 and 47-value responses.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant StateEndpoints
  participant WindowStore
  participant StateVectorBuilder

  Client->>StateEndpoints: GET workload state
  StateEndpoints->>WindowStore: Snapshot workload samples
  WindowStore-->>StateEndpoints: Samples or untracked workload
  StateEndpoints->>StateVectorBuilder: Build workload state vector
  StateVectorBuilder-->>StateEndpoints: StateVector with 47 values
  StateEndpoints-->>Client: State response or 404
Loading

Possibly related PRs

  • ravin00/AFIE#16: Provides stores, options, and program wiring used by this implementation.

Suggested reviewers: dinuda

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title identifies the Phase 4 feature-engineering work, which matches the main changes in the pull request.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/phase4-fe-features

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

@coderabbitai coderabbitai 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.

Actionable comments posted: 5

🤖 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 `@src/api/feature-engineering/appsettings.json`:
- Line 22: Align the blob storage configuration key with the existing
EventHubOptions contract by renaming the option from BlobStorageUrl to
BlobStorageUri, or restore the JSON key to BlobStorageUrl; ensure
EventHubConsumer and any related configuration binding use the same key
consistently.

In `@src/api/feature-engineering/Features/ActionHistoryFeatures.cs`:
- Around line 16-19: Update the minutesScaled calculation in the action-history
feature encoding to clamp elapsed time at a minimum of 0 as well as the existing
maximum of 1. Ensure future record.Timestamp values encode zero elapsed time
while preserving the current [0, 1] range for normal timestamps.

In `@src/api/feature-engineering/Features/NodePressureFeatures.cs`:
- Around line 19-21: Update the utilization assignment in the feature
computation to clamp the maximum of cpuUtil and memUtil to the inclusive range
[0, 1], preserving the existing upper-bound behavior while preventing negative
values from reaching dest[2].

In `@src/api/feature-engineering/Features/TemporalFeatures.cs`:
- Around line 22-25: Update the age calculation in the temporal feature
computation to use the latest sample timestamp via ctx.Samples[^1].Timestamp
rather than the first sample. Clamp the computed age to the range [0, 365]
before dividing by 365 and assigning dest[4], while preserving the zero value
for empty samples.

In `@src/api/feature-engineering/Models/StateVector.cs`:
- Around line 3-10: Update the public StateVector constructor to reject null
Values and any array whose length differs from Dimensions (47), while preserving
valid construction and serialization for correctly sized vectors.
🪄 Autofix

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: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 4c2b7431-79f9-443b-a577-81bef654da6b

📥 Commits

Reviewing files that changed from the base of the PR and between c292717 and f424461.

📒 Files selected for processing (24)
  • src/api/feature-engineering/AFIE.FeatureEngineering.csproj
  • src/api/feature-engineering/Endpoints/StateEndpoints.cs
  • src/api/feature-engineering/Features/ActionHistoryFeatures.cs
  • src/api/feature-engineering/Features/AppSignalFeature.cs
  • src/api/feature-engineering/Features/CostFeatures.cs
  • src/api/feature-engineering/Features/CpuFeatures.cs
  • src/api/feature-engineering/Features/DeploymentFeatures.cs
  • src/api/feature-engineering/Features/IFeatureGroup.cs
  • src/api/feature-engineering/Features/MemoryFeatures.cs
  • src/api/feature-engineering/Features/NodePressureFeatures.cs
  • src/api/feature-engineering/Features/StateVectorBuilder.cs
  • src/api/feature-engineering/Features/TemporalFeatures.cs
  • src/api/feature-engineering/Models/FeatureEngineeringOptions.cs
  • src/api/feature-engineering/Models/StateVector.cs
  • src/api/feature-engineering/Program.cs
  • src/api/feature-engineering/appsettings.json
  • tests/AFIE.FeatureEngineering.Tests/AFIE.FeatureEngineering.Tests.csproj
  • tests/AFIE.FeatureEngineering.Tests/Endpoints/StateEndpointsTests.cs
  • tests/AFIE.FeatureEngineering.Tests/Features/ActionHistoryFeaturesTests.cs
  • tests/AFIE.FeatureEngineering.Tests/Features/CpuFeaturesTests.cs
  • tests/AFIE.FeatureEngineering.Tests/Features/MemoryFeaturesTests.cs
  • tests/AFIE.FeatureEngineering.Tests/Features/NodePressureFeaturesTests.cs
  • tests/AFIE.FeatureEngineering.Tests/Features/StateVectorBuilderTests.cs
  • tests/AFIE.FeatureEngineering.Tests/Features/TemporalFeaturesTests.cs

Comment thread src/api/feature-engineering/appsettings.json
Comment thread src/api/feature-engineering/Features/ActionHistoryFeatures.cs Outdated
Comment thread src/api/feature-engineering/Features/NodePressureFeatures.cs Outdated
Comment thread src/api/feature-engineering/Features/TemporalFeatures.cs Outdated
Comment thread src/api/feature-engineering/Models/StateVector.cs
Copilot AI lite review requested due to automatic review settings August 5, 2026 12:52

Copilot AI left a 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.

Pull request overview

Adds the Phase 4 feature-engineering “state vector” pipeline by composing multiple IFeatureGroups into a fixed 47-dim observation and exposing it via minimal-API endpoints for per-workload retrieval.

Changes:

  • Introduces 8 feature groups + StateVectorBuilder to compute a clamped/finite 47-dimensional state vector.
  • Adds /state/{workloadName} and /state/{workloadName}/latest endpoints to retrieve current vectors from the sliding window store.
  • Adds unit/integration tests and brings in MathNet + MVC testing dependencies.

Reviewed changes

Copilot reviewed 24 out of 24 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
tests/AFIE.FeatureEngineering.Tests/Features/TemporalFeaturesTests.cs Verifies temporal sine/cosine continuity around boundaries.
tests/AFIE.FeatureEngineering.Tests/Features/StateVectorBuilderTests.cs Validates builder dimension coverage, clamping, and finiteness.
tests/AFIE.FeatureEngineering.Tests/Features/NodePressureFeaturesTests.cs Tests node-pressure flag/util feature behavior.
tests/AFIE.FeatureEngineering.Tests/Features/MemoryFeaturesTests.cs Tests memory percentile features at limit.
tests/AFIE.FeatureEngineering.Tests/Features/CpuFeaturesTests.cs Tests CPU percentile features and empty/short sample handling.
tests/AFIE.FeatureEngineering.Tests/Features/ActionHistoryFeaturesTests.cs Tests action-history encoding into the vector tail.
tests/AFIE.FeatureEngineering.Tests/Endpoints/StateEndpointsTests.cs Integration coverage for the new /state/* endpoints.
tests/AFIE.FeatureEngineering.Tests/AFIE.FeatureEngineering.Tests.csproj Adds Microsoft.AspNetCore.Mvc.Testing for endpoint tests.
src/api/feature-engineering/Program.cs Registers feature groups/builder and maps state endpoints.
src/api/feature-engineering/Models/StateVector.cs Adds the StateVector model and dimension constant.
src/api/feature-engineering/Models/FeatureEngineeringOptions.cs Adds deploy-time overridable cost/budget coefficients.
src/api/feature-engineering/Features/TemporalFeatures.cs Implements temporal encodings (hour/day-of-week + age).
src/api/feature-engineering/Features/StateVectorBuilder.cs Orchestrates group computation and post-processing (finite + clamp).
src/api/feature-engineering/Features/NodePressureFeatures.cs Implements node pressure flags + combined utilization.
src/api/feature-engineering/Features/MemoryFeatures.cs Implements memory usage/limit percentile features.
src/api/feature-engineering/Features/IFeatureGroup.cs Defines the feature-group contract and shared FeatureContext.
src/api/feature-engineering/Features/DeploymentFeatures.cs Adds placeholder deployment features for future phases.
src/api/feature-engineering/Features/CpuFeatures.cs Implements CPU usage/limit percentile features and slice helper.
src/api/feature-engineering/Features/CostFeatures.cs Adds hourly-cost and budget-relative cost features (plus placeholder trend).
src/api/feature-engineering/Features/AppSignalFeature.cs Adds app-signal aggregation features (with one reserved dim).
src/api/feature-engineering/Features/ActionHistoryFeatures.cs Encodes last few actions into fixed slots.
src/api/feature-engineering/Endpoints/StateEndpoints.cs Implements /state/{workloadName} and /latest endpoints.
src/api/feature-engineering/appsettings.json Adds FeatureEngineering cost settings and modifies EventHub config key.
src/api/feature-engineering/AFIE.FeatureEngineering.csproj Adds MathNet dependency for percentile computation.

Comment thread src/api/feature-engineering/appsettings.json
Comment thread src/api/feature-engineering/Models/FeatureEngineeringOptions.cs
Comment thread src/api/feature-engineering/Models/StateVector.cs Outdated
Comment thread src/api/feature-engineering/Features/CostFeatures.cs
Comment thread src/api/feature-engineering/Features/AppSignalFeature.cs
@ravin00

ravin00 commented Aug 6, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown
✅ Action performed

Full review finished.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🤖 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 `@src/api/feature-engineering/Models/StateVector.cs`:
- Line 11: Update the StateVector Values property to use a backing field and
validating init accessor so constructor assignments, object initializers, and
with expressions all reject arrays whose length is not 47; preserve the existing
ValidateValues behavior for valid arrays, and add a regression test covering
invalid assignment through an object initializer or with expression.
🪄 Autofix

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: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: ecd8653e-40e4-42dc-a27e-2127258c88e2

📥 Commits

Reviewing files that changed from the base of the PR and between 7066455 and 15e2014.

📒 Files selected for processing (3)
  • src/api/feature-engineering/Features/TemporalFeatures.cs
  • src/api/feature-engineering/Models/StateVector.cs
  • tests/AFIE.FeatureEngineering.Tests/Features/StateVectorBuilderTests.cs
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/api/feature-engineering/Features/TemporalFeatures.cs

Comment thread src/api/feature-engineering/Models/StateVector.cs Outdated

@coderabbitai coderabbitai 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.

🧹 Nitpick comments (1)
tests/AFIE.FeatureEngineering.Tests/Models/StateVectorTests.cs (1)

11-33: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add tests for constructor validation.

StateVector validates Values during primary construction and in the init accessor. These tests cover only with and object-initializer paths. A constructor regression could therefore pass this test file. Add constructor cases for null and invalid lengths. Include a length greater than StateVector.Dimensions.

Suggested additions
+    [Fact]
+    public void Constructor_WrongLength_Throws()
+    {
+        Assert.Throws<ArgumentException>(() =>
+            new StateVector("nginx", "default", DateTimeOffset.UtcNow,
+                new float[StateVector.Dimensions + 1]));
+    }
+
+    [Fact]
+    public void Constructor_NullValues_Throws()
+    {
+        Assert.Throws<ArgumentNullException>(() =>
+            new StateVector("nginx", "default", DateTimeOffset.UtcNow, null!));
+    }
🤖 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 `@tests/AFIE.FeatureEngineering.Tests/Models/StateVectorTests.cs` around lines
11 - 33, Add direct constructor-validation tests for StateVector, covering null
Values, a length below StateVector.Dimensions, and a length greater than
StateVector.Dimensions. Use the constructor path rather than with expressions or
object initializers, and assert ArgumentNullException for null and
ArgumentException for invalid lengths.
🤖 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.

Nitpick comments:
In `@tests/AFIE.FeatureEngineering.Tests/Models/StateVectorTests.cs`:
- Around line 11-33: Add direct constructor-validation tests for StateVector,
covering null Values, a length below StateVector.Dimensions, and a length
greater than StateVector.Dimensions. Use the constructor path rather than with
expressions or object initializers, and assert ArgumentNullException for null
and ArgumentException for invalid lengths.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 876e5ace-5a2b-4cee-82e7-f6900506c53b

📥 Commits

Reviewing files that changed from the base of the PR and between 15e2014 and b24b321.

📒 Files selected for processing (2)
  • src/api/feature-engineering/Models/StateVector.cs
  • tests/AFIE.FeatureEngineering.Tests/Models/StateVectorTests.cs
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/api/feature-engineering/Models/StateVector.cs

@ravin00
ravin00 merged commit 474c368 into main Aug 6, 2026
1 check passed
@ravin00
ravin00 deleted the feat/phase4-fe-features branch August 6, 2026 05:34
@coderabbitai coderabbitai Bot mentioned this pull request Aug 6, 2026
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants