Skip to content

fix(api): gmi() follow-ups (session privacy, stream stop, usage on errors) and the guide - #175

Merged
jddunn merged 19 commits into
masterfrom
fix/gmi-followups-2
Oct 9, 2026
Merged

jddunn merged 19 commits into
masterfrom
fix/gmi-followups-2

Conversation

@jddunn

@jddunn jddunn commented Oct 8, 2026 •

Copy link
Copy Markdown
Member

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:

  1. A structured session.send() whose answer does not parse or validate keeps nothing of the exchange: no history and no memoryProvider.observe. A retry no longer replays the refused exchange. runtime: 'legacy' also appends nothing to the history, but it calls observe from onAfterGeneration before it parses.
  2. An onBeforeToolExecution hook that resolves nothing no longer fails the turn. The GMI path warns about it and runs the tool with the arguments the model sent, as generateText does.
  3. agent.close() now also closes a cognitive memory that a session's first turn builds while close() runs. A build requested after close() fails.
  4. A structured send whose provider payload carries no schema puts the schema in the system prompt, in the same words generateObject uses. 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's responseSchema payload counts as carrying the schema. Those calls carry more prompt tokens.
  5. A structured send carries no chain-of-thought instruction. Every other call of an agent with tools gets the instruction first in its system prompt, where generateText puts it. onBeforeGeneration now receives the persona's prompt without the instruction as system, as on the legacy path.

Closing a session during a stalled request:

  1. fix(api): gmi() follow-ups (session privacy, stream stop, usage on errors) and the guide #161 made session.close() and agent.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 kept close() 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):

  1. Both branches moved buildSchemaInstructionText out of generateObject.ts. The merge keeps master's copy in structuredReply.ts.
  2. A structured reply puts its own instruction in the GMI's system prompt. On a hop whose payload carries no schema, the gateway no longer adds a second copy. CompletionGateway.stream() takes a new optional argument, schemaInPrompt, for this.

docs/GMI.md, docs/features/LLM_PROVIDERS.md and the SessionSendOptions.responseSchema JSDoc describe the new behaviour.

Linked issues

Follow-up to #161.

Type of change

  • Bug fix
  • Feature
  • Performance
  • Documentation
  • Refactor
  • Tests
  • Build or CI

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:

Item Test commit, red run Fix commit, green run
1 117c1bf, 37850383707 8c2bdc8, 37850558354
2 37c243b, 37850616177 ed0f143, 37850929725
3 b858e7f, 37851147434 36ba737, 37851239844
4 f3b0cd8, 37851801228 5213b8e, 37852024465
4 (Gemini payload) 268d379, 37852414730 64c3028, 37852433587
5 b3ca948, 37852143032 35b3f55, 37852302469
6 c66ddf4, 37865716822 a2cf8b1, 37866084627
8 73bc0ad, 37866136177 f392485, 37866493227

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

  • Tests cover the changed behavior.
  • Docs are updated.
  • The title follows Conventional Commits, with ! before the colon for a change that breaks users (feat!: or feat(api)!:).
  • No secrets or private data are included.
  • Every automated review thread is settled (how).
  • I have read this change and can explain every line.

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:

  • Prevent failed structured session replies from being persisted or observed, allowing retries to start without the rejected exchange.
  • Allow tool-execution hooks that return no value to fall back to the model-supplied arguments while warning about the hook result.
  • Ensure agent and session shutdown closes cognitive memory initialized during an in-flight turn and prevents new memory builds after closure.
  • Stop stalled provider streams promptly when a session or agent is closed.
  • Avoid duplicating structured-reply schema instructions when the schema is already present in the prompt.

Enhancements:

  • Add schema instructions to structured requests when the provider payload does not carry the schema, including fallback hops and JSON-object mode.
  • Align GMI chain-of-thought prompting and structured-send tool handling with the legacy runtime behavior.

Documentation:

  • Document schema fallback behavior for GMI sessions and supported LLM providers.

Tests:

  • Add regression coverage for structured-reply persistence, tool-hook fallbacks, cognitive-memory shutdown, schema prompting, chain-of-thought behavior, fallback hops, and stalled-stream cancellation.

…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.
@jddunn
jddunn requested a review from Victor-Evogor as a code owner October 8, 2026 21:57
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@sourcery-ai

sourcery-ai Bot commented Oct 8, 2026

Copy link
Copy Markdown

Sorry @jddunn, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 1 day and 6 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@sourcery-ai

sourcery-ai Bot commented Oct 8, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Fixes 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

Change Details Files
Prevent rejected structured sends from mutating session state or memory, allowing clean retries.
  • Added parity coverage for parse and schema-validation failures.
  • Verified failed exchanges are absent from messages, memory observations, and subsequent provider requests.
src/api/__tests__/gmi-runtime.parity.test.ts
Align GMI session behavior with the underlying agent and generation APIs for hooks, memory lifecycle, and structured prompting.
  • Warn and continue when onBeforeToolExecution resolves without a result, using the tool’s original arguments.
  • Ensure agent.close() waits for and closes cognitive memory created by the session’s first turn.
  • Place schemas in the system prompt when the provider path lacks schema support.
  • Avoid adding chain-of-thought instructions to structured sends after tools are stripped.
src/api/agent.ts
src/api/generateObject.ts
src/api/session.ts
src/api/__tests__/gmi-runtime.parity.test.ts

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai

coderabbitai Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Warning

Review limit reached

  • Run on-demand review

This review includes 18 billable files and costs up to $4.50.

  • Ask an admin to make reviews automatic

Open in CodeRabbit

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.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Repository: framerslab/agentos/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Team
  • Run ID: ede4acac-7db8-495e-8dc7-ac7ef7013d74
📥 Commits

Reviewing files that changed from the base of the PR and between 7afa875 and adb7b2b.

📒 Files selected for processing (18)
  • docs/GMI.md
  • docs/features/LLM_PROVIDERS.md
  • src/api/__tests__/gmi-runtime.memory.test.ts
  • src/api/__tests__/gmi-runtime.parity.test.ts
  • src/api/__tests__/gmi-runtime.session.test.ts
  • src/api/__tests__/helpers/stubProviders.ts
  • src/api/agent.ts
  • src/api/generateText.ts
  • src/api/gmi.ts
  • src/api/runtime/__tests__/agent-session-responseformat-fallback.test.ts
  • src/api/runtime/__tests__/gmiPersona.test.ts
  • src/api/runtime/__tests__/responseFormatForProvider.test.ts
  • src/api/runtime/completionGateway.ts
  • src/api/runtime/gmiPersona.ts
  • src/api/runtime/gmiSession.ts
  • src/api/runtime/responseFormatForProvider.ts
  • src/cognition/substrate/GMI.ts
  • src/cognition/substrate/__tests__/GMI.completion-gateway.test.ts
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

PR Summary by Qodo

test(api): Keep failed GMI structured sends out of session history

🧪 Tests 🕐 10-20 Minutes

Grey Divider

AI Description

• Add a regression test for structured GMI sends that fail JSON parsing or schema validation.
• Verify failed exchanges reach neither session history nor memory observation, so retries start
 clean.
Diagram

graph TD
  S["Session send"] --> P["Stub provider"] --> J{"JSON parses?"} -->|yes| V{"Schema valid?"} -->|yes| H["Session history"] --> M["Memory observer"]
  J -->|no| R["Reject turn"] -->|retry| S
  V -->|no| R
Loading
High-Level Assessment

The existing end-to-end GMI parity suite is an appropriate place to test retry isolation across provider responses, session history, and memory observation. The supplied diff adds only the regression test; it does not change production behavior.

Files changed (1) +19 / -0

Tests (1) +19 / -0
gmi-runtime.parity.test.tsTest clean retries after invalid structured responses +19/-0

Test clean retries after invalid structured responses

• Adds scripted non-JSON, schema-invalid, and valid responses to a structured GMI session test. It asserts that rejected turns are absent from history and memory observation, the retry request contains no rejected exchange, and the valid turn is retained.

src/api/tests/gmi-runtime.parity.test.ts

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Action required

1. Refused schema answers remain in history ✓ Resolved
Description
runGmiTurn commits the writer and calls observeTurn as soon as the model step finishes, while
sendGmiTurn invokes parseStructured only afterward. Consequently each malformed or
schema-invalid response is already present in session.messages() and has reached
memoryProvider.observe when the new assertions run, so this test fails instead of verifying the
intended retry behavior.
Code

src/api/tests/gmi-runtime.parity.test.ts[R92-93]

+    expect(session.messages()).toEqual([]);
+    expect(observe).not.toHaveBeenCalled();
Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
Issue description
The new structured-send regression test expects malformed or schema-invalid responses to leave no session history and trigger no memory observation, but `runGmiTurn` commits the turn and observes it before `sendGmiTurn` performs `parseStructured`. The test therefore fails at the new history and observation assertions, and refused exchanges remain available for later retries.
Fix Focus Areas
- src/api/runtime/gmiSession.ts[370-378]
- src/api/runtime/gmiSession.ts[451-453]
- src/api/__tests__/gmi-runtime.parity.test.ts[89-97]
Recommended Fix
Move structured-response parsing and Zod validation into the turn completion path before the writer is committed or `observeTurn` is called, or defer those side effects until validation succeeds. On parse or validation failure, abort the turn writer, skip memory observation, and propagate the existing `ObjectGenerationError`; retain the current successful-response history and object result behavior so this regression test passes.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Tip of the day
💡 Did you know, you can show, collapse, or hide each part of a finding: code, evidence, and all

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

jddunn added 18 commits October 8, 2026 14:59
…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.
…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.
@jddunn
jddunn merged commit 4628852 into master Oct 9, 2026
8 checks passed
github-actions Bot pushed a commit that referenced this pull request Oct 9, 2026
## [0.13.8](v0.13.7...v0.13.8) (2026-10-09)

### fix

* **gmi:** structured sends, tool hooks and close() follow-ups (#175) ([4628852](4628852))

### feat

* **evaluation:** score a transcript by its word error rate (#187) ([3fc3fc5](3fc3fc5))
@jddunn jddunn mentioned this pull request Oct 9, 2026
6 of 13 tasks
jddunn added a commit that referenced this pull request Oct 9, 2026
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.
github-actions Bot pushed a commit that referenced this pull request Oct 9, 2026
## [0.13.11](v0.13.10...v0.13.11) (2026-10-09)

### fix

* **gmi:** follow-ups from the review of #175 (#193) ([d9f0dd8](d9f0dd8))
@jddunn
jddunn deleted the fix/gmi-followups-2 branch October 10, 2026 18:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant