Skip to content

fix(venice): tool calls continue after Gemini responses - #119593

Closed
wenyonglim wants to merge 6 commits into
openclaw:mainfrom
wenyonglim:fix/venice-gemini-thought-signature
Closed

wenyonglim wants to merge 6 commits into
openclaw:mainfrom
wenyonglim:fix/venice-gemini-thought-signature

Conversation

@wenyonglim

@wenyonglim wenyonglim commented Aug 5, 2026 •

Copy link
Copy Markdown

Closes #119591

What Problem This Solves

Fixes an issue where users selecting a Gemini model through Venice could chat normally, but the agent turn failed with HTTP 400 immediately after any OpenClaw tool completed.

Why This Change Was Made

Venice currently emits Gemini tool-call thought_signature values as a top-level field on each OpenAI-compatible tool call and requires the exact opaque value on the continuation request. The generic completions transport now retains that returned shape, while the Venice provider wrapper replays it only for same-route Gemini turns; existing Google nested-signature and cross-route behavior is unchanged.

User Impact

Venice Gemini users can complete browsing and other tool-using turns instead of receiving a generic processing error after the tool runs. Other Venice models and other OpenAI-compatible providers are unaffected.

Evidence

  • Before fix, a live venice/gemini-3-6-flash tool turn completed the tool and the continuation failed with HTTP 400 for missing thought_signature.
  • A direct two-request Venice API probe reproduced the contract: missing replay failed with HTTP 400; replaying the exact returned top-level signature succeeded with HTTP 200 and the expected answer.
  • After the patch was applied to a build of the installed 2026.7.1-2 release, an isolated OpenClaw turn at thinking=high called the read tool and completed successfully: both Venice requests returned HTTP 200, toolSummary.calls=1, failures=0, and the final answer was openclaw.
  • node scripts/run-vitest.mjs src/agents/openai-transport-stream.usage-and-calls.test.ts (45 passed)
  • pnpm exec vitest run --config test/vitest/vitest.full-extensions.config.ts extensions/venice/index.test.ts (4 passed)
  • pnpm check
  • pnpm build
  • git diff --check

AI assistance: Codex was used to trace the transport path, implement the focused change, and draft tests/PR text. The behavior and API contract were independently verified with the live Venice endpoint; all changed code was reviewed and the commands above were run locally.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling extensions: venice labels Aug 5, 2026
@wenyonglim
wenyonglim marked this pull request as ready for review August 5, 2026 11:47

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 138d146f19

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +1577 to +1578
const fromToolCall = tc.thought_signature;
return typeof fromToolCall === "string" && fromToolCall.length > 0 ? fromToolCall : undefined;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve Venice signatures through storage

Capturing tc.thought_signature makes Venice/Gemini signatures part of the transcript, but transcript storage only preserves arbitrary thoughtSignature bytes for Google-compatible OpenAI-completions routes; a Venice assistant message is still api: openai-completions, provider: venice, so redactTranscriptMessageForStorage falls through to normal secret-pattern redaction. When the opaque signature contains token-shaped bytes and the session is persisted/reloaded, extensions/venice/stream.ts replays the masked value as tool_calls[].thought_signature, which violates this exact-signature replay path and can make the next Venice tool continuation fail again. Please add Venice/Gemini to the preservation route before storing these top-level signatures.

AGENTS.md reference: AGENTS.md:L62-L62

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 86c3f20. Venice Gemini OpenAI-completions routes now preserve structurally valid opaque tool-call signatures through transcript redaction, with a credential-shaped regression case proving the exact bytes survive storage sanitization.

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P1 High-priority user-facing bug, regression, or broken workflow. labels Aug 5, 2026
@clawsweeper

clawsweeper Bot commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge. Reviewed August 5, 2026, 9:19 AM ET / 13:19 UTC.

ClawSweeper review

What this changes

The branch captures Venice Gemini’s top-level tool-call signature, preserves it in transcripts, and replays or downgrades historical tool-call batches before Venice Gemini continuations.

Merge readiness

⚠️ Needs maintainer review before merge - 3 items remain

Keep open. The PR has convincing exact-head live proof for the original Venice continuation failure, but the prior P1 remains: its replay and downgrade maps treat tool_call_id as transcript-global, so resumed mixed-provider history with a reused ID can send a stale signature or detach a later tool result.

Priority: P1
Reviewed head: 45b920aca9e1d9b29313f88f5bd1a21a98ed1080

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The PR has strong live proof for the original failure and a plausible owner-boundary fix, but a concrete P1 transcript-pairing defect must be repaired before merge.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): Redacted exact-head terminal evidence shows Venice Gemini tool continuations returning HTTP 200 after the change; it does not cover the remaining repeated-ID defect.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): Redacted exact-head terminal evidence shows Venice Gemini tool continuations returning HTTP 200 after the change; it does not cover the remaining repeated-ID defect.
Evidence reviewed 7 items Current main still lacks the Venice capture path: Current main only extracts Google nested/function signatures, not Venice's top-level tool_call.thought_signature; the central behavior is not implemented on main.
Exact-head pairing defect: The PR collects signatures in one map keyed only by ID and applies them to every serialized assistant call with that ID, so an older signed Venice call can contaminate a later foreign or unsigned call that reuses the ID.
Result rewriting has the same global-ID flaw: After downgrading a batch, the second map rewrites every later role: tool message with the same ID instead of only results belonging to that assistant batch.
Findings 1 actionable finding [P1] Pair replayed calls and results by assistant-turn occurrence
Security None None.

How this fits together

The OpenAI-compatible transport turns model output into agent transcript messages, and the Venice provider plugin patches outgoing requests. Persisted transcript history must retain provider-owned signature metadata while keeping each assistant tool-call batch paired with only its own tool results.

flowchart LR
  A[Provider stream response] --> B[OpenAI-compatible transport]
  B --> C[Persisted agent transcript]
  C --> D[Venice provider wrapper]
  D --> E{Assistant batch has Venice signature}
  E -->|Yes| F[Replay matching tool call]
  E -->|No or foreign| G[Downgrade that batch to text]
  F --> H[Venice continuation]
  G --> H
Loading

Before merge

  • Pair replayed calls and results by assistant-turn occurrence (P1) - This remains the prior P1 blocker. tool_call_id is reused across transcript turns, but both maps are global: an older signed Venice call can lend its signature to a later foreign/unsigned call, and a downgraded old batch can rewrite a later unrelated result. Bind each assistant batch to its own adjacent result run and add a repeated-ID regression.
  • Resolve merge risk (P1) - On persisted or mixed-provider sessions that reuse a tool-call ID, merging this branch can send Venice an opaque signature from a different assistant turn or leave a retained structured call without its matching result.
  • Complete next step (P2) - A narrow, mechanical repair can resolve the remaining P1 without choosing new product or API direction.

Findings

  • [P1] Pair replayed calls and results by assistant-turn occurrence — extensions/venice/stream.ts:60-80
Agent review details

Security

None.

PR surface

Source +161, Tests +307. Total +468 across 7 files.

View PR surface stats
Area Files Added Removed Net
Source 4 170 9 +161
Tests 3 307 0 +307
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 7 477 9 +468

Review metrics

Metric Value Why it matters
Production versus test delta production +170/-9; tests +307/-0 The production increase is justified by the provider replay contract, but the history-rewrite logic needs the turn-scoped repair before that added compatibility surface is safe.

Stored data model

Persistent data-model change detected: serialized state: extensions/venice/stream.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #119591
Summary: This PR is the candidate fix for the concrete Venice Gemini tool-continuation bug reported in the linked issue.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Repair turn-scoped pairing before merge (recommended)
    Replace both transcript-global ID maps with chronological assistant-batch pairing and add repeated-ID coverage before another exact-head review.

Technical review

Best possible solution:

Use an occurrence-aware, ordered transform that binds signatures to one assistant tool-call batch and rewrites only that batch’s contiguous tool-result run, with repeated-ID regressions for both stale-signature and stale-result cases.

Do we have a high-confidence way to reproduce the issue?

Yes for the reported bug: the supplied direct Venice probe and installed-release run establish the original failure, while current source shows why top-level signatures are not captured. The remaining repeated-ID defect is high-confidence source-reproducible and needs a regression test.

Is this the best way to solve the issue?

No. The provider-local wrapper is the correct ownership boundary, but its transcript-global ID maps violate turn-scoped tool-call/result ownership; an occurrence-aware repair is the safer solution.

Full review comments:

  • [P1] Pair replayed calls and results by assistant-turn occurrence — extensions/venice/stream.ts:60-80
    This remains the prior P1 blocker. tool_call_id is reused across transcript turns, but both maps are global: an older signed Venice call can lend its signature to a later foreign/unsigned call, and a downgraded old batch can rewrite a later unrelated result. Bind each assistant batch to its own adjacent result run and add a repeated-ID regression.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.99

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against d85920c03e25.

Labels

Label justifications:

  • P1: A real provider workflow can again fail after tool execution when a resumed transcript reuses tool-call IDs.
  • merge-risk: 🚨 compatibility: The branch changes how historical OpenAI-compatible tool-call payloads are replayed to Venice Gemini.
  • merge-risk: 🚨 session-state: The affected data is persisted assistant tool-call and tool-result transcript state.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (terminal): Redacted exact-head terminal evidence shows Venice Gemini tool continuations returning HTTP 200 after the change; it does not cover the remaining repeated-ID defect.
  • proof: sufficient: Contributor real behavior proof is sufficient. Redacted exact-head terminal evidence shows Venice Gemini tool continuations returning HTTP 200 after the change; it does not cover the remaining repeated-ID defect.

Evidence

Acceptance criteria:

  • [P1] node scripts/run-vitest.mjs extensions/venice/index.test.ts.
  • [P1] node scripts/run-vitest.mjs src/agents/openai-transport-stream.usage-and-calls.test.ts.
  • [P1] git diff --check.

What I checked:

  • Current main still lacks the Venice capture path: Current main only extracts Google nested/function signatures, not Venice's top-level tool_call.thought_signature; the central behavior is not implemented on main. (packages/ai/src/transports/openai-completions-transport.ts:1560, d85920c03e25)
  • Exact-head pairing defect: The PR collects signatures in one map keyed only by ID and applies them to every serialized assistant call with that ID, so an older signed Venice call can contaminate a later foreign or unsigned call that reuses the ID. (extensions/venice/stream.ts:60, 45b920aca9e1)
  • Result rewriting has the same global-ID flaw: After downgrading a batch, the second map rewrites every later role: tool message with the same ID instead of only results belonging to that assistant batch. (extensions/venice/stream.ts:120, 45b920aca9e1)
  • Regression coverage omits repeated IDs: The mixed-history regression uses three distinct IDs, so it cannot expose a collision across separate assistant turns. (extensions/venice/index.test.ts:253, 45b920aca9e1)
  • Established sibling invariant: The core transcript transform resets pending result IDs for each assistant tool-call turn, demonstrating that tool-call/result ownership is turn-scoped rather than transcript-global. (packages/ai/src/transcript-transform.ts:210, d85920c03e25)
  • Main and release provenance: The PR head is not an ancestor of current main; the latest shipped tag is v2026.7.1-2, which points to the pre-PR release commit. (d85920c03e25)

Likely related people:

  • Peter Steinberger: Recent local history attributes provider-policy consolidation and adjacent transport work to this area. (role: recent provider and transport contributor; confidence: medium; commits: 778edf0a, 4a8ce9c; files: extensions/venice/stream.ts, packages/ai/src/transports/openai-completions-transport.ts)
  • Josh Avant: Local history attributes provider replay-signature preservation work in the transcript-redaction surface. (role: transcript replay contributor; confidence: medium; commits: 5dffe21; files: src/agents/transcript-redact.ts)
  • Jason (Json): Current Venice wrapper blame traces to this commit, though it is weak evidence of ownership for the new Gemini behavior. (role: adjacent file contributor; confidence: low; commits: 4b7a989a8bfe; files: extensions/venice/stream.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Scope signature replay and text downgrade to assistant-turn occurrence rather than global tool-call ID.
  • Add regressions for an older signed and later foreign/unsigned reused ID, plus an older downgraded and later signed reused ID.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (2 earlier review cycles)
  • reviewed 2026-08-05T12:11:49.132Z sha 86c3f20 :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-05T13:11:31.171Z sha 45b920a :: needs changes before merge. :: [P1] Pair historical tool calls by occurrence, not only call ID

@wenyonglim

Copy link
Copy Markdown
Author

Exact-head live runtime proof

Tested commit b01fcd84da against Venice using the installed plugin build, with secrets and raw signatures omitted.

Scenario:

  1. Create a persisted session containing an OpenAI/GPT tool call.
  2. Resume the same session on venice/gemini-3-6-flash.
  3. Force a real read tool call and continuation.

Redacted terminal evidence:

provider=venice model=gemini-3-6-flash status=200
provider=venice model=gemini-3-6-flash status=200
toolSummary.calls=1
toolSummary.tools=[read]
toolSummary.failures=0
finalAssistantVisibleText=proof-8f41d2c7
replayInvalid=false
fallbackUsed=false

Local verification at the same head:

Venice extension tests: 1 file, 6 tests passed
oxfmt: pass
oxlint: pass
git diff --check: pass
TruffleHog: clean
autoreview: clean; no accepted/actionable findings

This specifically exercises the reviewer-identified mixed-provider persisted-history edge case. Exact same-route Venice signatures still win; only unsigned/foreign Gemini 3 history receives Google's documented validator-skip marker, and Gemini 2.5 is left unchanged.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@wenyonglim

Copy link
Copy Markdown
Author

Updated exact-head proof for the persisted-history edge case

Commit 45b920aca9 supersedes the earlier dummy-signature fallback.

While reproducing the real Signal failure, I found that Venice's Gemini 3.6 OpenAI bridge does not successfully accept Google's documented dummy thought-signature values for old unsigned calls. The complete request ends with a non-empty user turn, but Venice returns:

HTTP 400: Requests ending with a model turn are not supported.

The minimized trigger is one legacy unsigned function-call/result pair followed by a new user turn. Removing the signature entirely instead returns the expected missing-thought_signature 400. Therefore the safe compatibility behavior is:

  • preserve and replay exact same-route Venice/Gemini signatures structurally;
  • downgrade only unsigned, foreign, or mixed historical tool-call batches and their results to labelled plain-text history;
  • leave Gemini 2.5 unchanged.

Redacted live proof at the new head:

Real pre-failure Signal transcript captured as a 165-message request.
Structured dummy-signature history: HTTP 400
Same 98,422-token request with unsigned history downgraded to text: HTTP 200

Fresh installed-plugin run from an exact copy of the pre-failure transcript:
initial Venice/Gemini request: HTTP 200
subsequent tool-call continuations: HTTP 200 throughout
schema/signature failures: 0

Local verification:

Venice extension tests: 1 file, 6 tests passed
oxfmt: pass
oxlint: pass
git diff --check: pass
TruffleHog/autoreview: clean

Secrets, message bodies, and raw signatures were omitted from this evidence.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. and removed status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 5, 2026
@wenyonglim

Copy link
Copy Markdown
Author

Repeated-ID repair at exact head de767bc4b3

The real Signal failure reproduced ClawSweeper's P1 exactly. Venice Gemini reused call_0 on two separate assistant turns:

  • first occurrence: read, with one opaque signature;
  • second occurrence: write, with a different opaque signature.

The prior transcript-global map let the later signature overwrite the earlier one, so the outgoing request replayed the second signature on both calls. Venice then returned the misleading HTTP 400 Requests ending with a model turn are not supported, although the reconstructed request genuinely ended with a non-empty user turn.

This head now pairs source and wire tool-call batches chronologically by assistant occurrence and call ordinal, with exact id/name guards. A downgraded Gemini 3 batch rewrites only its immediately adjacent tool-result run; no later result can be captured merely because its ID was reused.

Focused proof:

node scripts/run-vitest.mjs extensions/venice/index.test.ts
Test Files  1 passed (1)
Tests       7 passed (7)

node scripts/run-oxlint.mjs extensions/venice/stream.ts extensions/venice/index.test.ts
pass

git diff --check
pass

autoreview --mode local --max-priority P1
clean: no accepted/actionable findings
overall: patch is correct (0.91)

New regressions cover:

  1. two signed turns that reuse call_0 with different signatures, asserting occurrence-specific replay;
  2. an unsigned first call_0 followed by a signed second call_0, asserting only the first call/result pair is downgraded.

The compatible 2026.7.1 plugin package is installed locally but the managed Gateway has deliberately not been restarted during this active conversation. Exact managed-runtime proof will follow after activation.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@wenyonglim

Copy link
Copy Markdown
Author

Follow-up on exact head 7e1699c:\n\n- The third live Signal failure exposed reused provider-local tool call IDs (call_0 on separate assistant turns). The previous transcript-global lookup could pair a later signature with an earlier call.\n- Replay is now scoped chronologically to each assistant tool-call batch and matched by occurrence, ordinal, ID, and tool name. Associated tool-result rewriting is likewise limited to the immediately contiguous batch.\n- Regression coverage includes two separate signed call_0 occurrences with distinct signatures, plus an unsigned-then-signed call_0 sequence.\n- Local verification: Venice tests 7/7 passed; extension typecheck passed; oxlint passed; diff check passed; autoreview found no P0/P1 findings (0.98 confidence).\n\nThe compatible 2026.7.1 plugin is installed locally but not activated; the managed Gateway has deliberately not been restarted during the live conversation.\n\n@clawsweeper re-review

@wenyonglim

Copy link
Copy Markdown
Author

Closing at the author's request after a third failure in the real Signal thread. The latest failure showed provider-local tool-call IDs being reused across assistant turns; despite passing isolated and exact-copy tests, the proposed compatibility layer was not proven reliable in the user's actual workflow. Withdrawing the PR rather than presenting it as solved. The underlying issue remains open for a cleaner future approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling extensions: venice merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: L status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Venice Gemini tool calls fail after tool execution

1 participant