Skip to content

feat: implements bid matching in provider-inventory#3169

Closed
stalniy wants to merge 1 commit into
mainfrom
feat/bid-screening-inventory
Closed

feat: implements bid matching in provider-inventory#3169
stalniy wants to merge 1 commit into
mainfrom
feat/bid-screening-inventory

Conversation

@stalniy
Copy link
Copy Markdown
Contributor

@stalniy stalniy commented May 12, 2026

Why

Ref CON-308

What

Summary by CodeRabbit

Release Notes

  • New Features

    • Added /v1/bid-screening API endpoint to screen and match providers against resource requirements.
    • Enhanced provider inventory with additional GPU metadata (memory size, interface, model ID).
  • Chores

    • Updated sandbox and functional test environment configurations.
    • Improved test coverage with expanded integration and unit test suites.

@stalniy stalniy requested a review from a team as a code owner May 12, 2026 16:04
@stalniy stalniy marked this pull request as draft May 12, 2026 16:04
@codecov
Copy link
Copy Markdown

codecov Bot commented May 12, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 63.38%. Comparing base (af0dcdb) to head (682d316).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3169      +/-   ##
==========================================
- Coverage   63.68%   63.38%   -0.31%     
==========================================
  Files        1081     1051      -30     
  Lines       26197    25717     -480     
  Branches     6357     6261      -96     
==========================================
- Hits        16684    16300     -384     
+ Misses       8325     8238      -87     
+ Partials     1188     1179       -9     
Flag Coverage Δ
api 84.69% <ø> (ø)
deploy-web 46.53% <ø> (ø)
log-collector 85.85% <ø> (ø)
notifications 91.06% <ø> (ø)
provider-console 81.48% <ø> (ø)
provider-inventory ?
provider-proxy 85.21% <ø> (ø)
tx-signer 78.14% <ø> (ø)
see 31 files with indirect coverage changes
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@stalniy stalniy closed this May 12, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 12, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 89915b67-feb3-4ed7-b1f7-c42a10228e93

📥 Commits

Reviewing files that changed from the base of the PR and between af0dcdb and 682d316.

📒 Files selected for processing (47)
  • apps/provider-inventory/.eslintrc.js
  • apps/provider-inventory/env/.env.functional.test
  • apps/provider-inventory/env/.env.sandbox
  • apps/provider-inventory/package.json
  • apps/provider-inventory/src/config/env.config.ts
  • apps/provider-inventory/src/controllers/bid-screening/bid-screening.controller.spec.ts
  • apps/provider-inventory/src/controllers/bid-screening/bid-screening.controller.ts
  • apps/provider-inventory/src/http-schemas/bid-screening.schema.ts
  • apps/provider-inventory/src/index.ts
  • apps/provider-inventory/src/lib/compute-rollups/compute-rollups.spec.ts
  • apps/provider-inventory/src/lib/gpu-attribute-parser/gpu-attribute-parser.spec.ts
  • apps/provider-inventory/src/lib/gpu-attribute-parser/gpu-attribute-parser.ts
  • apps/provider-inventory/src/lib/groupspec-mapper/groupspec-mapper.spec.ts
  • apps/provider-inventory/src/lib/groupspec-mapper/groupspec-mapper.ts
  • apps/provider-inventory/src/lib/inventory-mapper/inventory-mapper.spec.ts
  • apps/provider-inventory/src/lib/inventory-mapper/inventory-mapper.ts
  • apps/provider-inventory/src/lib/project-row/project-row.spec.ts
  • apps/provider-inventory/src/lib/project-row/project-row.ts
  • apps/provider-inventory/src/lib/projected-row-equals/projected-row-equals.spec.ts
  • apps/provider-inventory/src/lib/resource-aggregator/resource-aggregator.ts
  • apps/provider-inventory/src/lib/resource-pair/resource-pair.spec.ts
  • apps/provider-inventory/src/lib/resource-pair/resource-pair.ts
  • apps/provider-inventory/src/lib/storage-attribute-parser/storage-attribute-parser.spec.ts
  • apps/provider-inventory/src/lib/storage-attribute-parser/storage-attribute-parser.ts
  • apps/provider-inventory/src/providers/index.ts
  • apps/provider-inventory/src/providers/stream-bootstrap.provider.ts
  • apps/provider-inventory/src/repositories/bid-screening/bid-screening.repository.integration.ts
  • apps/provider-inventory/src/repositories/bid-screening/bid-screening.repository.spec.ts
  • apps/provider-inventory/src/repositories/bid-screening/bid-screening.repository.ts
  • apps/provider-inventory/src/routes/bid-screening/bid-screening.router.ts
  • apps/provider-inventory/src/routes/index.ts
  • apps/provider-inventory/src/services/bid-screening/bid-screening.service.integration.ts
  • apps/provider-inventory/src/services/bid-screening/bid-screening.service.ts
  • apps/provider-inventory/src/services/cluster-inventory-matcher/cluster-inventory-matcher.service.spec.ts
  • apps/provider-inventory/src/services/cluster-inventory-matcher/cluster-inventory-matcher.service.ts
  • apps/provider-inventory/src/services/discovery-scheduler/discovery-scheduler.service.spec.ts
  • apps/provider-inventory/src/services/stream-lifecycle-manager/stream-lifecycle-manager.service.spec.ts
  • apps/provider-inventory/src/services/streamer-bootstrap/streamer-bootstrap.spec.ts
  • apps/provider-inventory/src/services/streamer-bootstrap/streamer-bootstrap.ts
  • apps/provider-inventory/src/types/inventory.ts
  • apps/provider-inventory/src/types/inventory.types.ts
  • apps/provider-inventory/src/types/provider.ts
  • apps/provider-inventory/src/types/stream-status.ts
  • apps/provider-inventory/test/setup-integration-env.ts
  • apps/provider-inventory/test/setup-integration-tests.ts
  • apps/provider-inventory/vitest.config.ts
  • packages/docker/.env.sandbox.docker-compose-dev

Disabled knowledge base sources:

  • Linear integration is disabled

You can enable these sources in your CodeRabbit configuration.


📝 Walkthrough

Walkthrough

This PR introduces a complete bid-screening feature for provider inventory matching. It adds HTTP endpoints for querying providers by resource requirements, implements bin-packing allocation logic to simulate placement across cluster nodes, provides GPU/storage attribute parsing and validation, and refactors bootstrap initialization to use dependency-injection providers instead of direct function calls.

Changes

Bid-Screening API & Data Layer

Layer / File(s) Summary
HTTP schemas and API contracts
src/http-schemas/bid-screening.schema.ts, src/types/inventory.types.ts
Zod schemas define request/response shapes for bid-screening with nested resource requirements (CPU/GPU/memory/storage), attributes, pricing, and replicas; exported types support strong typing throughout the stack.
Controller and routing
src/controllers/bid-screening/bid-screening.controller.ts, src/routes/bid-screening/bid-screening.router.ts, src/routes/index.ts
Controller injects BidScreeningService and exposes screenProviders handler; OpenApiHonoHandler router binds the POST /v1/bid-screening endpoint with OpenAPI validation and error handling.
Service layer validation and orchestration
src/services/bid-screening/bid-screening.service.ts, src/services/bid-screening/bid-screening.service.integration.ts
Service validates incoming requests (rejects empty resources, enforces persistent storage requires a storage class), maps/aggregates resource units into filtering aggregates, queries repository for SQL prefilter candidates, then filters via bin-packing matcher; integration tests seed providers and validate multi-filter scenarios.
Repository: SQL query generation and filtering
src/repositories/bid-screening/bid-screening.repository.ts, src/repositories/bid-screening/bid-screening.repository.spec.ts, src/repositories/bid-screening/bid-screening.repository.integration.ts
Repository builds parameterized WHERE clauses for online status, aggregate thresholds (CPU/memory/GPU/ephemeral/persistent), GPU vendor/model matching with wildcard support, persistent storage class containment, JSONB self-attribute filtering (glob-to-regex), and signed-by auditor constraints; hydrates rows into snapshot-based BidScreeningCandidate objects with inventory expansion; extensive tests validate SQL generation, operator selection, and edge cases.

Resource Inventory & Matching Logic

Layer / File(s) Summary
Type definitions for inventory state and results
src/types/inventory.types.ts, src/types/inventory.ts, src/types/stream-status.ts, src/types/provider.ts
New types define cluster/node/GPU/CPU resource state (NodeState, ClusterState, ResourcePairState), requested resource shapes (RequestedResourceUnit, RequestedStorage), and ProviderWithSnapshot for provider identity + snapshot data; GPU/stream-status types extended with memorySize, interface, modelId; ToJSON<T> utility converts bigint/Uint8Array to JSON-safe strings.
Resource pair abstraction
src/lib/resource-pair/resource-pair.ts, src/lib/resource-pair/resource-pair.spec.ts
ResourcePair class models allocatable vs allocated bigint quantities, supports unlimited via -1n sentinel (returning MAX_INT64 for available), allocation checks/mutations, and state serialization; used throughout inventory to track capacity.
Inventory mapping from snapshots
src/lib/inventory-mapper/inventory-mapper.ts, src/lib/inventory-mapper/inventory-mapper.spec.ts
Maps provider snapshot nodes into ClusterState by normalizing GPU info (sorted by vendor/name/memory), normalizing CPU metadata, wrapping allocatable/allocated into ResourcePair with bigint, deriving storage capability flags from node properties, and reducing storage pools into class-keyed map; tests assert correct bigint conversion and storage class derivation.
Group spec and resource unit mapping
src/lib/groupspec-mapper/groupspec-mapper.ts, src/lib/groupspec-mapper/groupspec-mapper.spec.ts
Maps incoming GroupSpecJSON into RequestedResourceUnit[] by parsing CPU/GPU/memory/storage quantities as non-negative bigints, preserving attributes, and failing on invalid values; allows multi-unit requests and empty storage lists.
GPU and storage attribute parsing
src/lib/gpu-attribute-parser/gpu-attribute-parser.ts, src/lib/gpu-attribute-parser/gpu-attribute-parser.spec.ts, src/lib/storage-attribute-parser/storage-attribute-parser.ts, src/lib/storage-attribute-parser/storage-attribute-parser.spec.ts, src/lib/project-row/*
GPU parser extracts vendor/model/ram/interface from slash-delimited attribute keys with value=true, validates vendor presence, defaults model to *, and provides normalization (sxm*/sxm mapping); storage parser classifies volumes as ephemeral/ram/persistent and validates persistent+ram rejection and persistent-without-class rejection; project-row mapper populates node GPU with additional fields for snapshots.
Resource aggregation across units
src/lib/resource-aggregator/resource-aggregator.ts
Iterates requested resource units, sums CPU/memory/GPU with unit count multipliers, tracks per-replica maxima, conditionally extracts GPU specs from parsed attributes (mapping wildcard to undefined), classifies and sums storage per class, and determines singular persistentStorageClass only when exactly one distinct persistent class exists.
Cluster inventory matcher: bin-packing allocator
src/services/cluster-inventory-matcher/cluster-inventory-matcher.service.ts, src/services/cluster-inventory-matcher/cluster-inventory-matcher.service.spec.ts
Core matching service simulates allocations across nodes and storage pools via state cloning; validates CPU attribute fingerprint consistency across groups; iterates requested units (reverse order), allocating CPU/memory/GPU/storage per-node; enforces storage classification semantics (ephemeral and ram deduct from node memory; persistent require pool capacity and node storage class membership); pins GPU specs by matching canonical or attribute-parsed specs; returns success or specific failure reason; extensive tests cover capacity exhaustion, storage-pool depletion, GPU matching invariants, and 4-node boundary-value scenarios.
Computing and projection
src/lib/compute-rollups/compute-rollups.spec.ts, src/lib/project-row/project-row.ts, src/lib/projected-row-equals/projected-row-equals.spec.ts
Updated test fixtures and projection logic to include extended GPU metadata (memorySize, interface, modelId); equality comparison tests verify order-insensitive matching of enriched GPU objects.

Bootstrap Refactoring & Infrastructure

Layer / File(s) Summary
DI provider-based bootstrap
src/providers/stream-bootstrap.provider.ts, src/providers/index.ts, src/index.ts
New stream-bootstrap.provider registers an APP_INITIALIZER via tsyringe with ON_APP_START lifecycle hook that resets online-since state then starts discovery scheduler; removed direct runStreamerBootstrap function call from bootstrap flow; updated src/index.ts to import providers relatively and mount bidScreeningRouter.
Environment config and test setup
src/config/env.config.ts, env/.env.sandbox, env/.env.functional.test, test/setup-integration-env.ts, test/setup-integration-tests.ts, package.json, vitest.config.ts
Extended envSchema to include AUDITOR_ADDRESS, REST_API_NODE_URL, and STREAM_FIRST_MESSAGE_TIMEOUT_MS; added environment variable definitions for sandbox; integrated dotenv+expand in test setup; test database auto-setup via TestDatabaseService with beforeAll/afterAll lifecycle; vitest config expanded with integration project targeting *.integration.ts files; test npm scripts now run unit+integration+functional projects.
Removed bootstrap code
src/services/streamer-bootstrap/streamer-bootstrap.ts, src/services/streamer-bootstrap/streamer-bootstrap.spec.ts
Removed direct runStreamerBootstrap function (now wired via provider); deleted associated unit test since logic moved to provider lifecycle.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~75 minutes

Rationale: The cluster inventory matcher implements intricate bin-packing state cloning and mutation tracking; the repository generates complex parameterized SQL with glob-to-regex conversion, JSONB operators, and conditional filter inclusion; resource allocation enforces non-obvious semantics (storage classification affecting memory, persistent pools requiring both node membership and cluster capacity); GPU matching must track canonical specs across fragmented node sets. While test coverage is extensive, correctness hinges on allocation ordering, state isolation during backtracking, SQL injection safety in glob patterns, and validation boundary cases.

Possibly related PRs

  • akash-network/console#3114: Introduces overlapping GPU/resource matching, groupspec mapping, inventory-mapper, ResourcePair, and ClusterInventoryMatcherService with identical core logic and type shapes—direct functional coupling.

Suggested labels

size: XL, experienced-contributor

Suggested reviewers

  • baktun14
✨ 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 feat/bid-screening-inventory

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

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant