fix(sdk): align client request types with the /api/sdk routes - #27
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:CompleteRunRequestcan now report test results — gainstestResults,policyChecks,confidenceScore,artifacts, typed directly off core'sEvaluation/Artifact. Previously a type-conforming client could never report tests, socomputeScoresaw zero tests and mutating runs could reach a Merge recommendation without a single test run. The vestigialresultfield is kept but@deprecated(the server never read it; deleting it would compile-break existing clients).StartRunRequest.agentsis 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 andrun.agentsstayed[]. Omitting agents still defaults to[]so minimal clients keep working.ReportMetricsmerges instead of replaces — omitted fields preserve existing values in bothrun.metricsand therun_metricsrow (previously reportingcostUsdaftertokenUsagezero-wiped the tokens). The SDK type gainsbackend/byModelso SDK clients can set Bedrock attribution;cost.thresholdonly fires when the request itself carriescostUsd.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.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