Skip to content

QVAC-13715 feat: Profiler Operation Transport + Load/Download Metrics + Stream Profiling#899

Merged
opaninakuffo merged 14 commits into
tetherto:mainfrom
opaninakuffo:feat/profiler-download-stream-coverage
Mar 17, 2026
Merged

QVAC-13715 feat: Profiler Operation Transport + Load/Download Metrics + Stream Profiling#899
opaninakuffo merged 14 commits into
tetherto:mainfrom
opaninakuffo:feat/profiler-download-stream-coverage

Conversation

@opaninakuffo

@opaninakuffo opaninakuffo commented Mar 13, 2026

Copy link
Copy Markdown
Contributor

🎯 What problem does this PR solve?

  • No mechanism to surface operation-level metrics (download, cache, checksum, initialization timing) to client
  • No per-call profiling control (RPCOptions) for loadModel/downloadAsset
  • Profiler export formatted all gauges as durations (misleading for bytes/throughput)
  • No test coverage for profiler transport contract
  • Stream profiling lacked server-side metrics
  • Negative clientOverhead values possible due to clock skew

📝 How does it solve it?

Operation Event Transport

  • Add OPERATION_EVENT_KEY + operationEventSchema in profiling schema
  • Inject operation events into __profiling envelope (survives response parsing)
  • Client profiler records serverMeta.operation events

Delegated loadModel Propagation

  • Extend ResponseWithDelegation to carry OPERATION_EVENT_KEY
  • Extract/attach provider operation events in both unary and streaming paths
  • Forward operation metadata to final consumer response

Stream Profiling (Trailer Frame)

  • Server emits profiling-only trailer frame at stream end with __profilingTrailer marker
  • Client extracts metadata then skips trailer (no yield to user code)
  • Server profiler caches delegation/operation from stream chunks, emits in trailer
  • Delegated streams attach breakdown per-chunk (profiled path only, zero overhead on non-profiled)
  • Conditional serverMeta assignment preserves metadata if later chunks lack it
  • clientOverhead clamped to Math.max(0, ...) to prevent negative values

Load/Download Metrics

  • Add DownloadStats, ResolveResult, DownloadMetricsHooks types
  • Add resolveModelPathWithStats() with base/stats mode
  • Add download-stats.ts wrappers (HTTP/Registry/Hyperdrive) with:
    • Progress-based bytes tracking
    • Download timing/speed derivation
    • Cache-hit/miss hooks
    • Checksum timing accumulation

Handler Operation Events

  • loadModel gauges: totalLoadTime, modelInitializationTime, downloadTime, totalBytesDownloaded, downloadSpeedBps, checksumValidationTime
  • loadModel tags: modelType, sourceType, cacheHit
  • downloadAsset gauges: totalDownloadTime, downloadTime, totalBytesDownloaded, downloadSpeedBps, checksumValidationTime
  • downloadAsset tags: sourceType, cacheHit

Client API

  • Add optional rpcOptions?: RPCOptions to loadModel() and downloadAsset()
  • Forward through unary and streaming RPC paths

Export Improvements

  • Aggregate gauge stats (not just timing)
  • Format table by metric type (duration/bytes/throughput/number)

How it was tested

  • bun run typecheck
  • bun test test/unit/profiler.test.ts
  • bun test test/unit/profiler-operation-transport.test.ts
  • bun run examples/profiling/basic.ts (manual verification, results below)
image

This PR depends on #836

@opaninakuffo opaninakuffo force-pushed the feat/profiler-download-stream-coverage branch from f2c5c6e to 9446fe0 Compare March 13, 2026 22:59
@opaninakuffo opaninakuffo marked this pull request as ready for review March 14, 2026 10:21
@opaninakuffo opaninakuffo requested review from a team as code owners March 14, 2026 10:21
@opaninakuffo opaninakuffo force-pushed the feat/profiler-download-stream-coverage branch from ea5edd6 to 99bd579 Compare March 16, 2026 09:37
NamelsKing
NamelsKing previously approved these changes Mar 16, 2026
Comment thread packages/sdk/client/api/load-model.ts Outdated
Comment thread packages/sdk/schemas/download-asset.ts
@opaninakuffo opaninakuffo changed the title QVAC-13715 feat: Profiler Operation Transport + Load/Download Metrics QVAC-13715 feat: Profiler Operation Transport + Load/Download Metrics + Stream Profiling Mar 16, 2026
NamelsKing
NamelsKing previously approved these changes Mar 17, 2026
Comment thread packages/sdk/server/rpc/handlers/load-model/registry.ts Outdated
Comment thread packages/sdk/client/rpc/rpc-client.ts Outdated
Comment thread packages/sdk/server/rpc/handlers/load-model/registry.ts
@opaninakuffo

Copy link
Copy Markdown
Contributor Author

/review

@github-actions

Copy link
Copy Markdown
Contributor

Tier-based Approval Status

**PR Tier:** TIER1

**Current Status:** ✅ APPROVED

**Requirements:**
- 1 Team Member approval ✅ (1/1)
- 1 Team Lead OR Management approval ✅ (1/1)



---
*This comment is automatically updated when reviews change.*

@opaninakuffo opaninakuffo merged commit 97ab383 into tetherto:main Mar 17, 2026
12 checks passed
Proletter pushed a commit that referenced this pull request May 24, 2026
… + Stream Profiling (#899)

* feat: transport operation-level handler events via __profiling envelope

* feat: propagate provider operation events across delegated loadModel

* feat: add source-aware load/download metrics and checksum/cache hooks

* feat: emit load/download operation metrics and forward per-call RPC options

* feat: aggregate gauge stats and format table metrics by value type

* test: add export-contract and operation-transport coverage

* refactor: replace raw Error with typed QvacError

* chore: fix build errors & correctlinting

* refactor: reorder send/stream params

* feat: add stream trailer frame for server metrics and delegated breakdown propagation

* refactor: extract shared utilities and add trailer key constant
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.

3 participants