[GH-ISSUE #2684] [Issue]: Agent API requests omit connection customParameters/stop and don't finite-guard temperature (agent-only failures) #1328

Closed
opened 2026-10-21 05:31:37 +07:00 by bsakaguchi · 2 comments
Owner

Originally created by @kolacheee on GitHub (Jun 20, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2684

Originally assigned to: @SpicyMarinara on GitHub.

Summary

The agent path never threads the connection's customParameters (nor defaultParameters/stop) into agent requests, and it doesn't finite-guard the agent temperature. So a connection that requires a mandatory provider param works on main chat but fails on every agent call, and a non-numeric/out-of-range stored temperature (via API/import) reaches the provider — and on the batch path poisons every co-grouped agent via Math.min.

Expected behavior

Agent requests on a given connection should carry the same mandatory provider parameters the main chat path sends, and should never send a non-finite/out-of-range temperature.

Actual behavior

  • Agent providers are built via createLLMProvider(provider, baseUrl, apiKey, maxContext, openrouterProvider, maxTokensOverride) — which has no parameter for the connection's customParameters/defaultParameters/stop. The executor's chatComplete option literals pass only { model, temperature, maxTokens, stream, tools?, onToken?, signal } and never set customParameters, so applyCustomParameters (which only merges options.customParameters) is a no-op on the agent path. The main path threads customParameters end-to-end.
  • temperature is read as (config.settings.temperature as number) ?? 0.3 with no Number.isFinite guard (unlike maxTokens/contextSize, which are normalized). settings is z.record(z.unknown()) with no numeric validation, so a stored "high"/-1 passes through. On the batch path, Math.min(...) over a non-numeric/NaN member yields NaN, poisoning the whole batch request.

How it breaks the pipeline

Code trace (staging @ b826f8f4):

  • customParameters dropped: agent-resolution.ts:135/:203 (createLLMProvider); provider-registry.ts:26-35 (no customParameters param); agent-executor.ts:333,:375,:467,:547,:696 (option literals omit customParameters); base-provider.ts:590-593 (applyCustomParameters only merges options.customParameters). Main path threads it at generate.routes.ts:5839/:5993/:6049.
  • temperature unguarded: agent-executor.ts:299 (single), :654 (batch Math.min), :430 (error path); schema agent.schema.ts:53 (settings: z.record(z.unknown())). Compare normalizeAgentMaxTokens (:194, Number.isFinite). On Anthropic a NaN→null temperature 400s; the batch Math.min(...NaN) = NaN fails every batched agent.

Steps to reproduce

customParameters: Configure a connection whose customParameters carries an upstream-required field (e.g. OpenRouter {"provider":{"order":[...]}} or a proxy-required body key) and use it for agents. Main chat sends it and succeeds; agent/batch chatComplete omits it → 400 / mis-routed. Agent results come back as errors while the main response is fine.

temperature: Persist a custom agent whose settings JSON has "temperature":"high" (or a negative value) via the REST API/import. Run it in a batch with another agent → Math.min(..., "high"/NaN) poisons the batch temperature → the whole batch 400s.

Suggested fix

  • Thread the connection's customParameters (and defaultParameters/stop where applicable) into the agent path — bake them into the provider in createLLMProvider, or pass them through ResolvedAgent into each executeAgent/executeAgentBatch chatComplete options object so applyCustomParameters merges them like the main path.
  • Add a normalizeAgentTemperature(value, fallback=0.3) helper (mirroring normalizeAgentMaxTokens: coerce, fall back when !Number.isFinite, clamp to range) and use it at agent-executor.ts:299, :430, and the batch reducer :654 before Math.min; optionally validate temperature in agent.schema.ts.

Environment

  • Marinara Engine version: 2.0.0 (staging @ b826f8f4)
  • Install type: source
  • OS + version: All (code-level defect, platform-independent)
  • Browser or app shell: All

Additional context

Found via a systematic multi-agent audit of the agent subsystem. The temperature path is mainly a power-user/import hardening gap (no UI field); the dropped-customParameters path affects any agent on a connection that needs a mandatory provider param. Part of a set of agent-pipeline issues filed together.

Template check

Please uncheck (untick) the box below before submitting so we know you read the template. It is intentionally pre-checked:

  • I DID NOT read this template and provide the requested details.
Originally created by @kolacheee on GitHub (Jun 20, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2684 Originally assigned to: @SpicyMarinara on GitHub. ## Summary The agent path never threads the connection's `customParameters` (nor `defaultParameters`/`stop`) into agent requests, and it doesn't finite-guard the agent `temperature`. So a connection that requires a mandatory provider param works on main chat but **fails on every agent call**, and a non-numeric/out-of-range stored `temperature` (via API/import) reaches the provider — and on the batch path poisons every co-grouped agent via `Math.min`. ## Expected behavior Agent requests on a given connection should carry the same mandatory provider parameters the main chat path sends, and should never send a non-finite/out-of-range `temperature`. ## Actual behavior - Agent providers are built via `createLLMProvider(provider, baseUrl, apiKey, maxContext, openrouterProvider, maxTokensOverride)` — which has **no** parameter for the connection's `customParameters`/`defaultParameters`/`stop`. The executor's `chatComplete` option literals pass only `{ model, temperature, maxTokens, stream, tools?, onToken?, signal }` and never set `customParameters`, so `applyCustomParameters` (which only merges `options.customParameters`) is a no-op on the agent path. The main path threads `customParameters` end-to-end. - `temperature` is read as `(config.settings.temperature as number) ?? 0.3` with no `Number.isFinite` guard (unlike `maxTokens`/`contextSize`, which are normalized). `settings` is `z.record(z.unknown())` with no numeric validation, so a stored `"high"`/`-1` passes through. On the batch path, `Math.min(...)` over a non-numeric/NaN member yields `NaN`, poisoning the whole batch request. ## How it breaks the pipeline Code trace (staging @ `b826f8f4`): - customParameters dropped: `agent-resolution.ts:135`/`:203` (`createLLMProvider`); `provider-registry.ts:26-35` (no customParameters param); `agent-executor.ts:333`,`:375`,`:467`,`:547`,`:696` (option literals omit `customParameters`); `base-provider.ts:590-593` (`applyCustomParameters` only merges `options.customParameters`). Main path threads it at `generate.routes.ts:5839`/`:5993`/`:6049`. - temperature unguarded: `agent-executor.ts:299` (single), `:654` (batch `Math.min`), `:430` (error path); schema `agent.schema.ts:53` (`settings: z.record(z.unknown())`). Compare `normalizeAgentMaxTokens` (`:194`, `Number.isFinite`). On Anthropic a `NaN`→`null` temperature 400s; the batch `Math.min(...NaN)` = NaN fails every batched agent. ## Steps to reproduce **customParameters:** Configure a connection whose `customParameters` carries an upstream-required field (e.g. OpenRouter `{"provider":{"order":[...]}}` or a proxy-required body key) and use it for agents. Main chat sends it and succeeds; agent/batch `chatComplete` omits it → 400 / mis-routed. Agent results come back as errors while the main response is fine. **temperature:** Persist a custom agent whose settings JSON has `"temperature":"high"` (or a negative value) via the REST API/import. Run it in a batch with another agent → `Math.min(..., "high"/NaN)` poisons the batch temperature → the whole batch 400s. ## Suggested fix - Thread the connection's `customParameters` (and `defaultParameters`/`stop` where applicable) into the agent path — bake them into the provider in `createLLMProvider`, or pass them through `ResolvedAgent` into each `executeAgent`/`executeAgentBatch` `chatComplete` options object so `applyCustomParameters` merges them like the main path. - Add a `normalizeAgentTemperature(value, fallback=0.3)` helper (mirroring `normalizeAgentMaxTokens`: coerce, fall back when `!Number.isFinite`, clamp to range) and use it at `agent-executor.ts:299`, `:430`, and the batch reducer `:654` before `Math.min`; optionally validate `temperature` in `agent.schema.ts`. ## Environment - Marinara Engine version: 2.0.0 (staging @ `b826f8f4`) - Install type: source - OS + version: All (code-level defect, platform-independent) - Browser or app shell: All ## Additional context Found via a systematic multi-agent audit of the agent subsystem. The temperature path is mainly a power-user/import hardening gap (no UI field); the dropped-`customParameters` path affects any agent on a connection that needs a mandatory provider param. Part of a set of agent-pipeline issues filed together. ## Template check Please **uncheck (untick)** the box below before submitting so we know you read the template. It is intentionally pre-checked: - [ ] I DID NOT read this template and provide the requested details.
Author
Owner

@kolacheee commented on GitHub (Jun 21, 2026):

Veracity self-review — correction / clarification
Automated post-filing review of this issue against the current working tree. The reported bug remains valid; the notes below refine its scope, accuracy, or suggested fix for whoever implements it.

Clarification after re-verifying against the current tree. The customParameters and temperature claims are confirmed accurate and still present. Three corrections to keep a fixer on track:

  1. The stop/stopSequences parenthetical overstates parity and should be de-scoped (or split into its own issue). stopSequences is parsed/stored (generate-route-utils.ts:867-868, prompt.schema.ts:63) and ChatOptions.stop exists (base-provider.ts:96) and providers send body.stop = options.stop (openai.provider.ts:854, 1089) — BUT a full-tree search shows nothing ever sets stop: in a ChatOptions object on the MAIN path either (the main-path override block at generate.routes.ts:3265-3279 never reads params.stopSequences; the only stop: matches in server/src are the unrelated haptic service). So stop is a no-op on BOTH paths today. Threading stop into the agent path alone changes nothing — the main-path stopSequences→options.stop conversion would have to be built first. Recommend dropping stop from this agent-parity fix. (customParameters parity is genuinely broken and stays in scope: main threads it at generate.routes.ts:5839 from conn.defaultParameters parsed at :3260/merged at :3279; agent path never sets options.customParameters.)

  2. Minor line-number drift (claims still valid): batch Math.min is at agent-executor.ts:650 (not :654 — that is the try {); error-path temperature read is at :426 (not :430 — that is durationMs); single-agent read at :299 is correct.

  3. Scope note for the temperature fix: a stored non-numeric temperature (e.g. "high") breaks the SINGLE agent path too, not just batch — (config.settings.temperature as number) ?? 0.3 returns the string unchanged because ?? only catches null/undefined, and it is passed straight to the provider (anthropic.provider.ts:270 sends it whenever !== undefined; NaN serializes to null → 400). So normalizeAgentTemperature must wrap :299 and :426 as well as the batch map at :650 — which the suggested fix already lists, so the fix stays complete. Note the main path already guards this via if (typeof params.temperature === "number") at generate.routes.ts:3265, which is the disparity. Also: customParameters/stopSequences are nested fields inside the connection's defaultParameters JSON blob (prompt.schema.ts:59, :63), not separate connection columns.

<!-- gh-comment-id:4761102202 --> @kolacheee commented on GitHub (Jun 21, 2026): > **Veracity self-review — correction / clarification** > _Automated post-filing review of this issue against the current working tree. The reported bug remains valid; the notes below refine its scope, accuracy, or suggested fix for whoever implements it._ Clarification after re-verifying against the current tree. The customParameters and temperature claims are confirmed accurate and still present. Three corrections to keep a fixer on track: 1) The `stop`/`stopSequences` parenthetical overstates parity and should be de-scoped (or split into its own issue). `stopSequences` is parsed/stored (generate-route-utils.ts:867-868, prompt.schema.ts:63) and `ChatOptions.stop` exists (base-provider.ts:96) and providers send `body.stop = options.stop` (openai.provider.ts:854, 1089) — BUT a full-tree search shows nothing ever sets `stop:` in a ChatOptions object on the MAIN path either (the main-path override block at generate.routes.ts:3265-3279 never reads `params.stopSequences`; the only `stop:` matches in server/src are the unrelated haptic service). So `stop` is a no-op on BOTH paths today. Threading `stop` into the agent path alone changes nothing — the main-path stopSequences→options.stop conversion would have to be built first. Recommend dropping `stop` from this agent-parity fix. (customParameters parity is genuinely broken and stays in scope: main threads it at generate.routes.ts:5839 from conn.defaultParameters parsed at :3260/merged at :3279; agent path never sets options.customParameters.) 2) Minor line-number drift (claims still valid): batch `Math.min` is at agent-executor.ts:650 (not :654 — that is the `try {`); error-path temperature read is at :426 (not :430 — that is `durationMs`); single-agent read at :299 is correct. 3) Scope note for the temperature fix: a stored non-numeric temperature (e.g. "high") breaks the SINGLE agent path too, not just batch — `(config.settings.temperature as number) ?? 0.3` returns the string unchanged because `??` only catches null/undefined, and it is passed straight to the provider (anthropic.provider.ts:270 sends it whenever `!== undefined`; NaN serializes to null → 400). So normalizeAgentTemperature must wrap :299 and :426 as well as the batch map at :650 — which the suggested fix already lists, so the fix stays complete. Note the main path already guards this via `if (typeof params.temperature === "number")` at generate.routes.ts:3265, which is the disparity. Also: `customParameters`/`stopSequences` are nested fields inside the connection's `defaultParameters` JSON blob (prompt.schema.ts:59, :63), not separate connection columns.
Author
Owner

@SpicyMarinara commented on GitHub (Jun 21, 2026):

Addressed on the issue-sweep branch. Agent resolution now carries connection default customParameters for chat fallback, default-for-agents, per-agent connections, and manual agent retry; every agent executor chatComplete call (single, retry, tools, final tool fallback, batch) passes them through. Agent temperatures now normalize to a finite 0..2 range with the existing 0.3 fallback before single-agent, error-debug, and batch Math.min paths. I intentionally left stop/stopSequences out per the verifier comment because the main path does not wire stop today either. Final repo checks will run after the sweep.

<!-- gh-comment-id:4761475475 --> @SpicyMarinara commented on GitHub (Jun 21, 2026): Addressed on the issue-sweep branch. Agent resolution now carries connection default customParameters for chat fallback, default-for-agents, per-agent connections, and manual agent retry; every agent executor chatComplete call (single, retry, tools, final tool fallback, batch) passes them through. Agent temperatures now normalize to a finite 0..2 range with the existing 0.3 fallback before single-agent, error-debug, and batch Math.min paths. I intentionally left stop/stopSequences out per the verifier comment because the main path does not wire stop today either. Final repo checks will run after the sweep.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#1328
No description provided.