Skip to content

fix(sdk): align client request types with the /api/sdk routes - #27

Merged
iaj6 merged 2 commits into
mainfrom
fix/sdk-contract
Jul 12, 2026
Merged

iaj6 merged 2 commits into
mainfrom
fix/sdk-contract

Conversation

@iaj6

@iaj6 iaj6 commented Jul 12, 2026

Copy link
Copy Markdown
Owner

Summary

The SDK's request types had drifted from what the /api/sdk/* routes actually consume (existing contract tests only asserted response shapes). From the July audit's medium tier:

  • CompleteRunRequest can now report test results — gains testResults, policyChecks, confidenceScore, artifacts, typed directly off core's Evaluation/Artifact. Previously a type-conforming client could never report tests, so computeScore saw zero tests and mutating runs could reach a Merge recommendation without a single test run. The vestigial result field is kept but @deprecated (the server never read it; deleting it would compile-break existing clients).
  • StartRunRequest.agents is persisted — the route validates ({id, model, role} with the AgentRole enum, 400 with the valid-role list otherwise) and attaches agents at run creation; previously they were silently dropped and run.agents stayed []. Omitting agents still defaults to [] so minimal clients keep working.
  • ReportMetrics merges instead of replaces — omitted fields preserve existing values in both run.metrics and the run_metrics row (previously reporting costUsd after tokenUsage zero-wiped the tokens). The SDK type gains backend/byModel so SDK clients can set Bedrock attribution; cost.threshold only fires when the request itself carries costUsd.
  • terminateSession(sessionId) added to the client — the route existed but no client method did, so SDK-created sessions could only end via the 30-minute staleness reaper.
  • Docs fixed — the SDK README's example called a startSession() method that has never existed; replaced with a working lifecycle example. CLAUDE.md method list updated.

Tests

Request-side contract coverage both ways: agents round-trip to the stored run; a client-shaped complete request drives scoring (correctness 0.5 for 1/2 tests — proving tests now affect the merge recommendation); metrics partial updates preserve earlier fields and round-trip backend/byModel; terminateSession end-to-end; SDK-side wire tests assert the new fields are actually sent. Full workspace suite green, web lint clean.

🤖 Generated with Claude Code

@iaj6 iaj6 closed this Jul 12, 2026
@iaj6 iaj6 reopened this Jul 12, 2026
iaj6 and others added 2 commits July 12, 2026 11:42
Request-side drift found by the July 2026 audit — the contract tests only
asserted response shapes, so a type-conforming SDK client could silently
lose data on the way in:

- CompleteRunRequest now carries what the complete route actually consumes
  (testResults, policyChecks, confidenceScore, artifacts), so clients can
  report test outcomes and correctness is scored from real data instead of
  defaulting to 1.0 "not scored". The vestigial `result` field is kept but
  @deprecated (the server has never read it; removing it would break
  compiling clients during the customer trial).
- /api/sdk/runs now validates and persists StartRunRequest.agents at run
  creation (immutably, via spread) instead of dropping them.
- /api/sdk/runs/[id]/metrics now MERGES each report into the stored
  metrics — omitted optional fields preserve prior values instead of being
  zero-filled — and ReportMetricsRequest declares backend/byModel so SDK
  clients can set Bedrock spend attribution. run_metrics upsert uses the
  same merged values; cost.threshold only fires for cost reported in the
  request.
- New AgentOpsClient.terminateSession() (+ TerminateSessionResponse) for
  the existing /api/sdk/sessions/[id]/terminate route, so SDK sessions can
  end gracefully instead of waiting on the 30-min staleness reaper.

Tests: request-side contract suite in web (agents round-trip, testResults
reach the stored run and drive scoring, metrics partial-update semantics
across both stores), route validation cases (malformed agents, bad
complete payloads), and SDK client tests for the new fields/method.
Also fixes the stale README example (startSession never existed) and the
CLAUDE.md SDK method list.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@iaj6
iaj6 force-pushed the fix/sdk-contract branch from 096d995 to 7b16f3d Compare July 12, 2026 16:14
@iaj6
iaj6 merged commit 5b271b1 into main Jul 12, 2026
3 checks passed
@iaj6
iaj6 deleted the fix/sdk-contract branch July 12, 2026 16:30
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.

1 participant