feat: add workspace usage attribution

Merged
KH
3mo ago
+1707-25

Summary

  • record immutable workspace creation provenance (source, optional origin_id, sanitized request identity) in the existing workspace insert
  • maintain explicit internal / external / unknown classification with creator versus operator evidence
  • expose the contract through shared Zod types, OpenAPI, TypeScript SDK, Rust SDK, and MCP; Relaycast E2E creators declare first-party CI/internal provenance
  • document the hosted usage seam, cost model, historical boundary, and no-billing scope

This is stacked on #338 because that PR owns migration 0036; attribution is migration 0037. Retarget this PR to main after #338 lands.

Why the hosted view is separate

The portable engine owns creation-time facts and authenticated per-workspace metadata. Cross-workspace ranking and operator classification are hosted control-plane concerns, so the internal usage endpoints are in the companion relaycast-cloud PR behind the existing internal bearer.

Backfill and trust boundary

The existing 41,320 workspaces remain provenance NULL, classification unknown, classification_source unclassified. Legacy relay-<8hex> and agent-name patterns are investigation hints only; they are never written as facts. Caller-declared classification is observability evidence, not authentication, authorization, or billing authority.

Cost

  • zero additional workspace-creation writes: provenance is added to the existing row insert
  • zero message-path writes
  • hosted usage is a read-time aggregate initiated by an authenticated operator
  • one explicit workspace-row write when an operator records a classification and reason

Rollout dependencies

Verification

  • focused attribution + lifecycle + types: 50 tests passed
  • TypeScript SDK/MCP focused: 171 tests passed
  • selected package build: 5/5 tasks passed
  • selected package lint: 7/7 tasks passed
  • Rust SDK: 43 unit + 43 parity + 5 doc tests passed
  • selected package regression: types 164, SDK 425, MCP 223, engine 596/597 passed; the existing two-node contention test timed out only in the CPU-saturated full run, then passed alone in 632 ms
  • git diff --check: passed

No production data was read, changed, or deleted. No billing behavior is included.

Part of #337.