feat(routes): PATCH /v1/sessions/{id} for partial cost_data update#3
Merged
Conversation
Adds the partial-update wire shape called out in #2 so agents can record per-turn token usage as an accumulator without rewriting the message history. The handler is a thin delegate over SessionStore.update() — shallow merge per top-level key, write-wins, 404 when the session does not exist. No parallel persistence; the SQLite and Postgres backends from fipsagents.server.sessions own the merge semantics, matching the platform-as-veneer principle. The wire contract is already exercised end-to-end by the agent-side HttpSessionStore.update() in fips-agents/agent-template#116, so this commit lights up the platform half of the round-trip. Five new pytest cases drive the route via httpx.AsyncClient against a real SQLite-backed store: two-call merge with overlapping keys, missing session 404, cost_data null no-op merge, missing-session 404 with null body, and message echo on PATCH for non-empty histories. Closes #2 Refs: fips-agents/agent-template#116 Assisted-by: Claude Code (Opus 4.7)
6 tasks
The PATCH /v1/sessions/{id} route delegates to SessionStore.update()
which is new in fipsagents 0.14.0. Pinning the lower bound prevents
running against an older fipsagents that lacks the ABC method.
Refs #2.
Assisted-by: Claude Code (Opus 4.7)
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
Lands the platform half of the cost-tracking round-trip from #2: a
PATCH /v1/sessions/{session_id}route that delegates toSessionStore.update()for a shallow merge ofcost_data(write-wins per top-level key). 404 if the session does not exist — no auto-create on PATCH, matching the wire contract in the issue.The handler is a thin veneer; persistence and merge semantics live in
fipsagents.server.sessions.SqliteSessionStore/PostgresSessionStore, consistent with the rest of this service.Wire contract
{"session_id", "messages": [...]}on successcost_data: nullis a no-op merge but still confirms existence (200/404 same as a populated body)require_userdependency as the sibling sessions endpointsCompanion
fips-agents/agent-template#116already ships the agent-sideHttpSessionStore.update()that speaks this wire shape; its e2e tests pass against this endpoint.Test plan
pytest -q— 43 passed (5 new intest_sessions.py)make lintgitleaks protect --staged --no-banner --redact— no leaks{a:1}then{b:2,a:5}->{a:5,b:2})cost_data: nullis a no-op on existing accumulator statecost_data: nullon missing session still 404Closes #2
Assisted-by: Claude Code (Opus 4.7)