Skip to content

Failover Models and Gemini Model Support - #86

Closed
tylerwince wants to merge 2 commits into
openclaw:mainfrom
tylerwince:failover-gemini
Closed

tylerwince wants to merge 2 commits into
openclaw:mainfrom
tylerwince:failover-gemini

Conversation

@tylerwince

Copy link
Copy Markdown
Contributor

This adds two related improvements to the embedded agent runtime:

  • Configurable model failover: new agent.failoverModels array lets Clawdis try secondary/tertiary models when the primary errors (per‑turn only; no /model override persistence).
  • Gemini support hardening: sanitize tool schemas and session history for Google models so Gemini accepts function‑call payloads and ordering.

Gemini usage note:

  • Set GEMINI_API_KEY (from aistudio.google.com) in the gateway host environment.

Question for @steipete steipete

Should we add Gemini as an onboarding option and prompt for GEMINI_API_KEY there (similar to Anthropic API key), or keep it as an env‑only setup?

@steipete

steipete commented Jan 3, 2026

Copy link
Copy Markdown
Contributor

🦞 Codex Review

Findings

  • 🚨 HIGH: src/agents/pi-tools.ts:226 drops patternProperties but keeps additionalProperties: false, so TypeBox Record schemas become "no keys allowed"; Gemini tools like env and fields likely break.
  • ⚠️ Medium: With stripAnyOf true and existing type/properties, anyOf is removed without merging, so union-only fields can disappear from Gemini tool schemas.

Open Questions

  • Gemini tool schemas must keep map-style inputs; if yes, translate patternProperties → additionalProperties even when additionalProperties is false.

Summary
Adds agent failover model list, Google/Gemini-specific message + tool schema sanitization, expands hook channels.

Review by Clawd 🦞 via Codex

@steipete

steipete commented Jan 3, 2026

Copy link
Copy Markdown
Contributor

Thanks Tyler! On it. I don't think Gemini is a good option for this agent, so don't wanna offer it in the onboarding flow, but folks ofc can configure it themselves and the PR is useful.

Comment thread docs/configuration.md
"openai/gpt-4o"
],
allowedModels: [
"anthropic/claude-opus-4-5",

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.

need to think how this fits together with allowedModels.

@tylerwince

Copy link
Copy Markdown
Contributor Author

Happy to spend some more time working on this and/or split out the "FailoverModels" functionality from the Gemini functionality. I think it would be useful to have failover to minimax or something, especially if usage limits get hit for claude subscription.

@thewilloftheshadow

Copy link
Copy Markdown
Member

Models have had a big change in their config and failover works differently now!

dgarson referenced this pull request in dgarson/clawdbot Feb 4, 2026
chore: more logging reduction changes
slathrop referenced this pull request in slathrop/openclaw-js Feb 11, 2026
Tasks completed: 2/2
- Port commit #84 (QMD startup hardening + timeout config + test mock refactoring)
- Port commits #85 and #86 (forced sync queue + SQLITE_BUSY handling)

SUMMARY: .planning/phases/12-memory-qmd-hardening/12-08-SUMMARY.md
dgarson referenced this pull request in dgarson/clawdbot Feb 22, 2026
songliu0403-rgb pushed a commit to songliu0403-rgb/openclaw that referenced this pull request Feb 26, 2026
github-actions Bot referenced this pull request in Piboonsak/openclaw_github Mar 8, 2026
0x666c6f added a commit to 0x666c6f/openclaw that referenced this pull request Mar 26, 2026
…ace (openclaw#86)

* feat: add Notion API support for Morpho workspace

* fix: address PR review findings

* fix: address additional PR review findings

* fix: address remaining PR review findings

* fix: address final PR review findings

* fix: align Notion query handling with review feedback

* fix: address additional Notion API review feedback
@ridhoperdana

Copy link
Copy Markdown

Code Review: Failover Models & Gemini Support

Overall Assessment

This PR adds valuable capabilities for production resilience (model failover) and Google Gemini compatibility. Well-structured with good separation of concerns.


✅ Strengths

1. Failover Design

  • Per-turn only (no persistence) - correct choice to avoid masking chronic issues
  • Respects allowedModels allowlist
  • Proper deduplication and validation

2. Google/Gemini Compatibility

  • Targeted schema sanitization (const, patternProperties not supported)
  • Session message reordering for Google's stricter tool-call sequencing rules
  • Non-breaking - opt-in via model detection

3. Code Organization

  • Helper functions properly extracted (sanitizeSessionMessagesForGoogle, sanitizeSchemaForGoogle)
  • Types preserved throughout

🔒 Security Considerations

1. Failover Loop Risk (Low)

// The loop could retry across multiple providers on auth failures
// Consider: Max failover attempts or error categorization

Recommendation: Add opt-out for failover on authentication errors (4xx), as these won't resolve by switching models.

2. Google Schema Sanitization

  • Removing const and patternProperties may relax validation
  • sanitizeSchemaForGoogle adds additionalProperties: true in edge cases
    Impact: Acceptable for Gemini compatibility, but document this behavioral difference in docs/configuration.md.

🛠️ Maintainability

1. Error Accumulation

const errors: string[] = [];
// Later: throw new Error(`All models failed: ${errors.join("; ")}`);

Suggestion: Consider structured error logging or metrics for observability (e.g., which models failed, why).

2. Model Detection Logic

const modelApi = model && typeof model === "object" && "api" in model
  ? (model as { api?: string }).api
  : undefined;
const isGoogleModel = modelApi === "google-generative-ai" || provider === "google";

Consider: Extract to a named function for reusability and testability.

3. TypeScript Type Safety

const toolResult = msg as Extract<AppMessage, { role: "toolResult" }>;

Multiple casts in sanitizeSessionMessagesForGoogle. Suggestion: Add type guards or refactor to reduce runtime assertions.


📊 Performance Implications

1. Failover Overhead

  • Model catalog loaded during failover resolution
  • Each failover attempt re-santizes history for Google models
    Impact: Minimal for 1-2 failover attempts; acceptable tradeoff for resilience.

2. Schema Sanitization

  • Runs per-tool, per-agent invocation
  • sanitizeSchemaForGoogle recursively traverses entire schema
    Recommendation: Consider memoization if tool definitions are stable across runs (they likely are).

📋 Best Practices

1. Documentation ✅

  • Configuration updates in docs/configuration.md are clear
  • Examples provided for failoverModels

2. Error Messages ⚠️

throw new Error(`All models failed: ${errors.join("; ")}`);

Suggestion: Include guidance (e.g., "Check API keys, quotas, network connectivity").

3. Channel Types Update

channel?: "last" | "whatsapp" | "telegram" | "discord" | "signal" | "imessage";

This appears to be an unrelated change - consider splitting into a separate PR for clearer change tracking.


🎯 Recommendations

  1. High Priority: Document that failover does not persist (users may expect it to)
  2. Medium Priority: Add failover opt-out for auth errors (4xx status codes)
  3. Low Priority: Extract model detection to a utility function
  4. Nice-to-Have: Add telemetry/logging for failover events

Conclusion

LGTM with minor suggestions. The failover mechanism will significantly improve production reliability, and the Gemini compatibility work enables broader model choice. The code is clean, typed, and well-organized.

Would appreciate clarification on whether the channel type changes (signal, imessage) should be separated.

cryptolir referenced this pull request in cryptolir/openclaw May 11, 2026
…istory, transactions (#35)

Adds rain_get_positions, rain_get_position_by_market, rain_get_lp_position,
rain_get_portfolio_value, rain_get_pnl, rain_get_trade_history,
rain_get_transactions, rain_get_market_transactions to RAIN_TOOLS and
matching methods to RainRuntimeClient.

Ships with the dashboard endpoints (openclaw-dashboard feat/v2a-slices-3-4-reads).

Closes #86/#87 (MCP side).

Co-authored-by: Liran Peretz <[email protected]>
Co-authored-by: Claude Sonnet 4.6 <[email protected]>
@fyw3624

fyw3624 commented Jun 2, 2026

Copy link
Copy Markdown

#86 P7-AOC-CONV-PERM-1 · Closeout(Step 5 PASS)

分支:fix/p6a-it-l3-aoc-ingress-binding
总 smoke(WSL2):

bash scripts/group-deployment/aoc-p7-perm1-smoke.sh

Step 状态

Step 状态
1 DB migration DONE
2 DingTalk auth + session DONE
3 RBAC service DONE
4 Agent view API DONE
5 总 smoke + #87 readiness DONE

Step 5 验收(10 项)

  1. 未登录 /aoc/auth/me → 401
  2. mock 钉钉登录成功
  3. /aoc/auth/me 含 user / departments / roles / grants
  4. aoc-p7-perm1-rbac-smoke.sh PASS
  5. GET /aoc/me/agent-personas PASS
  6. POST /aoc/view/agent PASS(super_admin + reason)
  7. GET /aoc/view/current PASS
  8. super_admin 切换写入 aoc_super_admin_view_audit
  9. canPostConversation → denied_by_stage=P7-AOC-CONV-MSG-1
  10. 无消息/egress POST 路由(405);未扩 Profile 生产

交付物

明确未做

#87 UI、#88 消息、#90/#91 Session、#92/#93 Memory、#95/#96 Run、egress/ACK、影响 #84。

建议

#84 继续独立 observe-only,不混入 P7。

steipete added a commit that referenced this pull request Sep 18, 2026
Preserve failed session-store results until logical consumption so task authorization reports UNAVAILABLE with the original cause. Keep genuine misses and independent prepared targets intact. Regression proof previously returned an empty task page for an injected SQLITE_IOERR; investigated under CI class #86.
steipete added a commit that referenced this pull request Sep 18, 2026
Preserve failed session-store results until logical consumption so task authorization reports UNAVAILABLE with the original cause. Keep genuine misses and independent prepared targets intact. Regression proof previously returned an empty task page for an injected SQLITE_IOERR; investigated under CI class #86.
steipete added a commit that referenced this pull request Sep 18, 2026
Preserve failed session-store results until logical consumption so task authorization reports UNAVAILABLE with the original cause. Keep genuine misses and independent prepared targets intact. Regression proof previously returned an empty task page for an injected SQLITE_IOERR; investigated under CI class #86.
steipete added a commit that referenced this pull request Sep 18, 2026
)

Fix authenticated task lists appearing empty or partial when session metadata reads fail. Preserve typed read results per logical target and let the existing Gateway dispatcher return UNAVAILABLE with the recorded, redacted cause. Genuine empty authorized results and independent healthy targets remain successful.

Add regression coverage at the authenticated tasks.list boundary, preserve scalar and prepared-read failures, correct fixtures that relied on suppressed errors, and document the protocol behavior. Investigated under CI class #86; the original hosted log did not establish the particular failing metadata read.

Validation: 452 focused tests and changed checks passed in authoring. Exact-head CI run 35354876710 passed on f54beda. Both commits are patch-identical to the scoped-clean Codex review of record and ClawSweeper-reviewed revision, which has no actionable findings.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 19, 2026
…claw#151310)

Fix authenticated task lists appearing empty or partial when session metadata reads fail. Preserve typed read results per logical target and let the existing Gateway dispatcher return UNAVAILABLE with the recorded, redacted cause. Genuine empty authorized results and independent healthy targets remain successful.

Add regression coverage at the authenticated tasks.list boundary, preserve scalar and prepared-read failures, correct fixtures that relied on suppressed errors, and document the protocol behavior. Investigated under CI class openclaw#86; the original hosted log did not establish the particular failing metadata read.

Validation: 452 focused tests and changed checks passed in authoring. Exact-head CI run 35354876710 passed on f54beda. Both commits are patch-identical to the scoped-clean Codex review of record and ClawSweeper-reviewed revision, which has no actionable findings.
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.

5 participants