feat(routes): GET /v1/sessions/{id}/cost_data read companion (#4)#5
Merged
Conversation
Closes the cumulative-cost gap that the 0.14.1 cluster smoke spotlighted.
Without a read endpoint, agent-side _persist_cost_data could only write
deltas (HttpSessionStore.get_cost_data raised NotImplementedError, so the
accumulator fell back to existing={} every turn). With the GET route in
place, the agent reads existing totals before computing the merge and
HTTP-backed deployments converge on the same cumulative semantics that
SQLite/Postgres provide natively.
Wire shape mirrors the existing /v1/sessions/{id} handler:
{"session_id": ..., "cost_data": {...}}. 404 when the session is missing;
200 with empty cost_data when the session exists but has no PATCH writes
yet. Existence is decided via store.exists() since
SessionStore.get_cost_data() returns {} for both missing-session and
empty-cost_data and the route needs to distinguish the two.
Three new pytest cases against the live ASGI app + SqliteSessionStore
(after-PATCHes merge, empty-no-writes, missing-session 404). Suite
total 43 -> 46.
Closes #4
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
GET /v1/sessions/{session_id}/cost_datareturning{"session_id": ..., "cost_data": {...}}. 404 when the session does not exist; 200 with emptycost_datawhen the session exists but has no PATCH writes yet.HttpSessionStore.get_cost_datapreviously raisedNotImplementedError, so the per-turn accumulator onOpenAIChatServerhad nothing cumulative to read and HTTP-backed deployments degraded to last-write-wins per top-level key.GET /v1/sessions/{id}. Usesstore.exists()to distinguish missing-session from empty-cost_data (SessionStore.get_cost_data()returns{}for both).Pairs with the agent-side companion at fips-agents/agent-template#TBD (will reference once opened). Older agents (<=0.14.1) never call this route — safe to ship independently.
Closes #4
Test plan
pytest tests/test_sessions.py— 22 passing locally (3 new: after-PATCHes merge, empty-no-writes, missing 404).Assisted-by: Claude Code (Opus 4.7)