Repository navigation
fix(api): gmi() follow-ups (session privacy, stream stop, usage on errors) and the guide - #175
Conversation
…g of the exchange
A case that fails today. On agent({ runtime: 'gmi' }), session.send()
with a responseSchema commits the turn to the session's history and
hands it to memoryProvider.observe before it parses the answer, so an
answer that is not JSON, or JSON the schema refuses, rejects with
ObjectGenerationError and still stays in messages(): the caller's retry
replays the refused exchange. agent()'s send parses first and appends
nothing.
The case sends twice with answers that fail (not JSON, then JSON
without the schema's field), then once with a valid answer, and checks
that the history and the retry's request hold none of the refused
exchanges and that observe heard none of them.
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Reviewer's guide (collapsed on small PRs)Reviewer's GuideFixes GMI session follow-up behavior by preserving session privacy after rejected structured sends, tolerating empty tool-hook results, closing session-created cognitive memory correctly, and aligning schema and prompting behavior with agent() semantics; regression coverage documents the corrected paths. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
Warning Review limit reached
This review includes 18 billable files and costs up to $4.50.
Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing. Or wait 36 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 (18)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
PR Summary by Qodotest(api): Keep failed GMI structured sends out of session history
AI Description
Diagram
High-Level Assessment
Files changed (1)
|
Code Review by Qodo
1.
|
…he turn
On agent({ runtime: 'gmi' }), session.send() with a responseSchema
committed the turn to the session's history, and handed it to
memoryProvider.observe, before it parsed the answer. An answer that was
not JSON, or JSON the schema refused, rejected with ObjectGenerationError
and still stayed in messages(), so the caller's retry replayed the
refused exchange. agent()'s send parses first and appends nothing.
The turn runner now takes an acceptReply check that runs once a turn has
ended without error and before the store keeps it; a check that throws
closes the turn's writer without storing anything, skips observe, and
is the turn's error. sendGmiTurn parses the schema answer there. The
usage of the refused turn is still counted and metered: the provider
billed it.
…ot fail the turn
A case that fails today. On agent({ runtime: 'gmi' }), the hook wrapper
reads the hook's result outside its try, so a hook that only logs and
resolves undefined throws a TypeError into the GMI's tool round and the
whole turn fails. generateText reads the result inside its try: it warns
and runs the tool with the arguments the model sent.
…er fails the turn
On agent({ runtime: 'gmi' }), the wrapper around the shared tool
orchestrator read the hook's result outside its try. A hook that only
logs and resolves undefined made it throw a TypeError into the GMI's
tool round, and the turn failed. generateText and streamText read
hookResult.args inside their try: they warn and run the tool with the
arguments the model sent.
The wrapper now reads the result the same way: null still skips the
tool, returned arguments still replace the call's, and a hook that
throws or resolves with nothing to read is warned about and the tool
runs as the model called it.
…) runs
Cases that fail today. agent.close() on agent({ runtime: 'gmi' }) takes
the memory build it finds and resets it before the sessions have
finished. A session's first turn that is still setting up when close()
runs then builds a new cognitive memory manager, and nothing closes it.
The same happens to the turn of a session closed on its own just before
agent.close().
Each case counts the managers that were initialised and checks every one
of them was shut down once the agent is closed.
… runs
agent.close() on agent({ runtime: 'gmi' }) took the memory build it
found and reset the memo before the sessions had finished. A session's
first turn that was still setting up then built a new cognitive memory
manager (its embedding probe, vector store and consolidation timer) and
nothing closed it; the turn of a session closed on its own just before
agent.close() did the same.
Each session now takes the memory the agent's sessions share when it
opens. agent.close() starts a new one for the sessions opened after it,
closes the open sessions (each stops its turn and waits for it), and
then closes the memory those sessions shared, with whatever a turn built
while they closed. A build asked of that memory after close() fails
instead of building a manager no one would close.
… payload does
Cases that fail today, on both runtimes. session.send() with a
responseSchema sends the provider the structured-output payload
buildResponseFormatForProvider shapes for it, and nothing else. Where
that payload carries no schema, the model never sees it: Claude Opus
5.5, Sonnet 5.5 and Fable take no forced tool, so they get no payload at
all, and OpenAI's JSON mode (the fallback for a schema strict mode
cannot take) has no schema in it. Nothing adds the schema to the
prompt, though responseFormatForProvider and the Fable case say it
rides the system prompt; the existing cases passed only because the
stubs answer JSON whatever they are sent. generateObject puts the
schema in the system prompt on every call.
agent({ runtime: 'gmi' }): the Sonnet 5.5 case now checks the request's
system prompt holds the schema, and a new case checks the same for JSON
mode while a strict json_schema request does not repeat it.
agent(): the Fable and record-schema cases check the same, and a new
case checks each fallback leg decides for its own payload: a strict
OpenAI primary sends no schema text, a Sonnet 5.5 leg gets it.
…payload does
session.send() with a responseSchema sent the provider only the payload
buildResponseFormatForProvider shapes for it. Where that payload carried
no schema, the model never saw it: Claude Opus 5.5, Sonnet 5.5 and Fable
take no forced tool, so they got no payload at all, and the JSON mode
OpenAI and OpenRouter get for a schema strict mode cannot take
({ type: 'json_object' }) has no schema in it. generateObject puts the
schema in the system prompt on every call.
A call whose payload carries no schema now sends the schema
instructions generateObject uses as a system message after the system
prompt, and each hop or fallback leg decides for its own payload, so a
strict json_schema request does not repeat it:
- agent({ runtime: 'gmi' }): the completion gateway adds the message on
the hops whose lowered payload carries no schema.
- agent(): session.send hands generateText the instructions in the
internal _schemaInstruction option, and generateText adds them on each
call or fallback leg whose _responseFormat carries no schema.
buildSchemaInstructionText moves from generateObject into
responseFormatForProvider beside the new responseFormatCarriesSchema,
with its text unchanged. docs/GMI.md says what the gateway sends such a
hop.
A case that fails today. On agent({ runtime: 'gmi' }), the persona's
base prompt starts with the chain-of-thought instruction whenever the
agent has tools, so a structured send, whose step goes without tools,
still asks the model to reason about which tool to pick before it
answers, which invites prose ahead of the JSON. agent() adds the
instruction per call only when the call offers tools, and a structured
send strips them.
The case sends once with a schema and once without on an agent with a
tool: the first request carries no tools and no instruction, the second
carries both.
On agent({ runtime: 'gmi' }), the persona's base prompt started with the
chain-of-thought instruction whenever the agent had tools, so a
structured send, whose step goes without tools, still asked the model to
reason about which tool to pick before it answered. agent() decides per
call: generateText puts the instruction first in the system prompt only
when the call offers tools, and a structured send strips them.
The persona's base prompt is now the agent's system prompt alone, and
gmi() puts the instruction first in the system prompt of each model call
of an agent with tools, except the calls of a structured send (the turn
runner tells the GMI's hooks which turns are structured). The text and
its place on the other calls are unchanged, and onBeforeGeneration's
`system` is now the agent's system prompt without the instruction, as
agent() passes it.
The persona unit case now checks the base prompt holds no instruction,
and a case pins chainOfThought: false on the GMI path, which the persona
case covered before.
A case that fails today. responseFormatCarriesSchema, which decides whether a structured call also sends the schema instructions, reads a payload of type json_object as JSON mode without a schema. Gemini's payload has that type too, with the schema in its _gemini.responseSchema, so a Gemini hop or leg would get the instructions on top of a schema the provider enforces. The case runs the check over buildResponseFormatForProvider's payloads: strict json_schema, the Anthropic schema tool and Gemini's responseSchema carry the schema; no payload and JSON mode do not.
responseFormatCarriesSchema read every payload of type json_object as JSON mode without a schema, so a Gemini hop or leg, whose payload has that type with the schema under _gemini.responseSchema, would also get the schema instructions in its system prompt. The check now names the payloads that carry a schema: a strict json_schema, Anthropic's forced schema tool and Gemini's responseSchema. No payload, JSON mode and any other shape leave the schema to the prompt.
…o payload carries it LLM_PROVIDERS.md said a session's responseSchema never writes the schema into the system prompt, so a provider with no structured-output format never saw it. Since the previous commits it does, on either agent runtime, whenever the provider-side format carries no schema, and each fallback provider is checked for its own format. The SessionSendOptions.responseSchema comment said the agent's tools are still passed through with a schema request; both runtimes leave them out, and the chain-of-thought instruction with them.
# Conflicts: # src/api/generateObject.ts
…ort signal per event stalls Anthropic, Gemini and Ollama stream with a fetch that does not take the caller's abort signal: they check it when an SSE event arrives. A request that stalls before its first byte therefore holds the GMI turn, and with it session.close(), until the provider's own timeout (requestTimeout and the idle watchdog, 90 s each for Anthropic by default). The stub's hold reply honours the signal, which hid this. The stub gets reply.stall, a held reply that ignores the signal until its gate opens, and the session test closes a session during such a request on Claude Sonnet 5.5. It fails until the completion gateway stops waiting on the provider once the turn's signal aborts.
…fter the turn is stopped The completion gateway now reads each provider chunk against the turn's abort signal. Once the signal aborts, the attempt ends at once with the abort chunk the providers send for a stopped request, and the provider's stream is ended in the background. Before, a provider that checks the signal only when a streamed event arrives (Anthropic, Gemini and Ollama pass it to no fetch) kept the turn, and session.close() or agent.close() behind it, waiting until its own request or idle timeout when the request stalled before its first byte or between events. A provider that honours the signal is unchanged: its turn ends with the same abort error, and an attempt with no signal is read as before.
…nly hop once A structured reply (processRequest's structuredReply, #177) puts its instruction in the GMI's system prompt and hands its Zod schema to the completion gateway. On a hop whose provider payload carries no schema, such as Claude Sonnet 5.5 with no forced tool, the gateway now adds the schema instruction as well, so the request carries it twice. The case runs such a turn through the real gateway and counts the instruction in the system prompt; it fails until the gateway leaves it to a prompt that already carries it.
The GMI tells the completion gateway when its system prompt already carries the schema's instructions: a structured reply puts its own there and hands its Zod schema to the gateway. CompletionGateway.stream() takes that as an optional sixth argument, schemaInPrompt, and a hop whose payload carries no schema then gets no second copy. A responseSchema turn (gmi() sessions' structured send) is unchanged: its prompt-only hops still get the instruction from the gateway. docs/GMI.md says so.
Follow-ups from the review of #175 on the agent({ runtime: 'gmi' }) path and the completion gateway, each fix after a regression test that CI ran red: - A model call that starts after close() sends no provider request: the gateway reads the abort signal before it asks the provider's stream for a chunk and skips the provider call when the signal has already aborted. A stream that has started is read to its end in the background. - When the gateway ends an attempt on abort, the usage the provider still reports for it (OpenRouter's held content-filter decline or held error) is counted as a failed attempt's usage. - A structured request that OpenRouter retries in JSON mode after its 404 "no endpoints" carries the schema in its system prompt, once. - A structured reply's meta.enforcement is provider_schema only when the payload of the hop that answered carried the schema, else prompt_only. - On a structured send whose primary payload carries no schema, onBeforeGeneration sees the schema instruction in the messages on both runtimes, and a hook that removes it removes it. Every change keeps the existing call signatures.
## [0.13.11](v0.13.10...v0.13.11) (2026-10-09) ### fix * **gmi:** follow-ups from the review of #175 (#193) ([d9f0dd8](d9f0dd8))
Summary
Follow-ups to #161 on the
agent({ runtime: 'gmi' })path. Each fix comes after a regression test that CI ran red for the reason the test names.The five P2 findings left from the review of the session runner:
session.send()whose answer does not parse or validate keeps nothing of the exchange: no history and nomemoryProvider.observe. A retry no longer replays the refused exchange.runtime: 'legacy'also appends nothing to the history, but it callsobservefromonAfterGenerationbefore it parses.onBeforeToolExecutionhook that resolves nothing no longer fails the turn. The GMI path warns about it and runs the tool with the arguments the model sent, asgenerateTextdoes.agent.close()now also closes a cognitive memory that a session's first turn builds whileclose()runs. A build requested afterclose()fails.generateObjectuses. This covers a provider with no structured-output payload, an Anthropic model that rejects a forced tool choice, and JSON-object mode. It applies on both runtimes and is decided for each fallback leg. Gemini'sresponseSchemapayload counts as carrying the schema. Those calls carry more prompt tokens.generateTextputs it.onBeforeGenerationnow receives the persona's prompt without the instruction assystem, as on the legacy path.Closing a session during a stalled request:
session.close()andagent.close()stop a running turn. Anthropic, Gemini and Ollama only check the abort signal when a streamed event arrives, so a request stalled before its first byte still keptclose()waiting until the provider's timeout (90 s for Anthropic). The completion gateway now checks the turn's signal while it waits for each chunk. Once the signal aborts, the gateway ends the attempt with an abort chunk and closes the provider's stream in the background.Merge with master (#177, structured reply):
buildSchemaInstructionTextout ofgenerateObject.ts. The merge keeps master's copy instructuredReply.ts.CompletionGateway.stream()takes a new optional argument,schemaInPrompt, for this.docs/GMI.md,docs/features/LLM_PROVIDERS.mdand theSessionSendOptions.responseSchemaJSDoc describe the new behaviour.Linked issues
Follow-up to #161.
Type of change
How this was verified
CI on this pull request. Each test commit was pushed and its run read red for the expected reason (only the new cases failing), then its fix was pushed and its run read green:
The docs commit f49d0ce ran green in 37852967181. Master is merged at b417899 (3f6fc84), and the last run, 37866493227 on f392485, is green.
Migration notes
None. Nothing here breaks existing callers. The new
CompletionGateway.stream()argument is optional, so existing callers and implementations still compile.Checklist
!before the colon for a change that breaks users (feat!:orfeat(api)!:).Summary by Sourcery
Harden GMI sessions and structured responses by preserving privacy on rejected turns, improving shutdown cancellation, and aligning prompt and memory behavior across runtime paths.
Bug Fixes:
Enhancements:
Documentation:
Tests: