Repository navigation
fix(api): five defects from a cold read of the gmi() session runner - #165
Conversation
…rver, and three agent() behaviours hold End-to-end cases over stubbed provider classes for what agent() gives a caller and the GMI path has to keep: - the usage ledger holds a turn by the time send() returns or a stream's text settles, so usage() read right after counts it; - the process-wide usage observer hears each model call of a turn (a tool step, the answer, a billed attempt that failed before any output), under the surface the caller used; - memoryProvider.observe runs on the provider, so a provider built from a class records the turn, and an observe that throws does not fail the turn; - no user message is named after the session id; - a step the session store refuses (two tool calls under one id) does not cost the turn its user message.
|
Warning Review limit reached
This review includes 5 billable files and costs up to $1.25.
Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing. Or wait 25 minutes for your next included review. View limit detailsLimit details: You’ve used all 4 included reviews currently available. Review configuration: ⚙️ Run configuration
📒 Files selected for processing (5)
Comment |
Reviewer's GuideThis PR adds end-to-end regression tests for GMI parity and usage behavior, then updates the GMI session runner to await ledger persistence, report all model attempts, safely observe memory, omit invalid user-message names, and preserve user history when later step storage fails. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
…ssion store keeps runGmiTurn gave the turn's user message to the turn's first step only. When the store refused that step (its pairing check fails for a step whose tool calls share one id, as OllamaProvider's streamed calls can), the user message went with it, and the steps after it were stored alone: the history showed an assistant reply with no message before it. The message now stays with the turn until a step is kept, so the first step the store takes carries it.
… a gmi() turn runGmiTurn took observe off the provider and called it bare. A provider built from a class reads `this` in observe, so the call threw inside the method, the rejection was swallowed, and the provider recorded nothing. An observe that threw outright (one that is not an async function) failed the turn after its reply had been stored and its usage counted, so send() rejected for a turn the history already held. observe is now called on the provider, as agent() calls it, and a throw is warned about and left there.
runGmiTurn started each usage ledger write and moved on. send() returned before the row was on disk, so with the ledger enabled, where usage() reads the ledger alone, usage() read right after a send missed the turn, and a process that exited once the call returned lost the row. generateText writes its row before it returns. The turn now waits for its ledger writes before it ends. The wait sits in a try whose finally releases the turn lock, so nothing thrown while a turn is closing can leave the session's later turns waiting.
A host that meters model spend through setGlobalLlmObserver heard nothing from a turn on the GMI path: generateText and streamText report each call and each billed failed attempt to the observer, and runGmiTurn wrote the usage ledger only. Each model call of a turn now fires one usage event beside its ledger row: a finished step with the provider, model and hop that served it, and an attempt that failed before any output and was billed, as an 'error' event. A folded turn (send, generate) reports under the generateText surface and a streamed one under streamText, the surfaces the same calls report under through agent(). A turn is metered call by call, as its ledger rows are, so a tool loop or a fallback hop reports each request with the provider that was billed for it.
A GMI names the turn's user message after the turn's user id and replays it under that name on every model call after the turn's first (a tool step) and for multimodal input. On the gmi() path that id is the session id unless the caller named a user, so the request carried `name: <session id>`. OpenAI checks a message name against a pattern and answers HTTP 400 for one with a space or a slash in it, so a session id such as 'support chat 1' failed the turn after its tool had run. agent() names no message. gmi()'s model-call hook now takes the name off user messages before the request is sent; tool results keep theirs.
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
PR Summary by QodoFix GMI session usage, memory, request names, and history
AI Description
Diagram
High-Level Assessment
Files changed (5)
|
Code Review by Qodo🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)
Great, no issues found!Qodo reviewed your code and found no material issues that require reviewTip of the day💡 Did you know, you can keep summaries lean with Findings visible per group, which tucks the rest behind a View link |
## [0.13.0](v0.12.24...v0.13.0) (2026-10-08) ### ⚠ BREAKING CHANGE * **speech:** URL output (providerSpecificOptions.outputFormat 'url') downloads only from hosts listed in audioUrlHosts, or in MINIMAX_TTS_AUDIO_URL_HOSTS through SpeechRuntime; without one, synthesize() throws instead of fetching. MiniMaxAsyncSpeechResponse.task_id is number | string instead of string, and file_id is number | string instead of number. ### feat * **safety:** a persisted spend meter that processRequest reserves against before any provider call (#167) ([b9c2e91](b9c2e91)) ### fix * **api:** five defects from a cold read of the gmi() session runner (#165) ([5eec49c](5eec49c)) * **speech:** download MiniMax URL output only from allowed hosts, query async tasks with GET (#166) ([14b86bf](14b86bf))
Summary
A cold read of the
gmi()session runner merged in #135 (src/api/runtime/gmiSession.ts,src/api/gmi.ts) found five places where a turn on the GMI path does less than the same turn throughagent(). Each has an end-to-end case over stubbed provider classes that failed before its fix (run 37824347489, the tests alone: 7 failed, 9036 passed).runGmiTurnstarted each ledger write and moved on, sosend()returned before the row was on disk. With the ledger enabled,usage()reads the ledger alone, so a read right after a send missed the turn, and a process that exited once the call returned lost the row. The turn now waits for its ledger writes before it ends, asgenerateTextwrites its row before it returns. The wait sits in atrywhosefinallyreleases the turn lock.setGlobalLlmObserverheard nothing from this path. Each model call of a turn now fires one usage event beside its ledger row: a finished step with the provider, model and hop that served it, and an attempt that failed before any output and was billed, as an'error'event.send()andgenerate()report under thegenerateTextsurface andstream()understreamText. WheregenerateTextfires one event for a whole call, a GMI turn fires one per model call, as its ledger rows already were: each call of a turn can be served by another hop, so each is attributed to the provider that billed it, and the token totals are the same. Events carry nosource: the path refuses a per-callsource, as it refuses every per-call option outside its list.memoryProvider.observeruns on the provider. It was taken off the provider and called bare, so a provider built from a class lostthis, the rejection was swallowed and nothing was recorded. Anobservethat threw outright failed a turn whose reply was already stored. It is now called on the provider, and a throw is warned about and left there.namewith a space or a slash in it (the pattern, as OpenAI's error states it).gmi()'s model-call hook now takes the name off user messages; tool results keep theirs.Linked issues
Follow-up to #135.
Type of change
How this was verified
CI on this pull request, nothing run locally. The first commit holds only the tests; its
Test & Lintjob (run 37824347489) failed ingmi-runtime.usage.test.ts(3 cases) andgmi-runtime.parity.test.ts(4 cases), each for the defect it names. The run on the head commit b8ebc01 (run 37825031126) is green: build, export check, lint, type check, and the full suite (725 files, 9058 tests passed, the seven new cases among them), with the batch-1 gate and the release dry run.Migration notes
None for code. A host that registers a usage observer starts receiving events from
agent({ runtime: 'gmi' })andgmi()turns, one per model call.Checklist
!before the colon for a change that breaks users (feat!:orfeat(api)!:).