Files
roboco/alembic/versions/084_modelprovider_gemini.py
21d6730400 feat(providers): Gemini CLI provider — ModelProvider.GEMINI (#660)
* feat(providers): Gemini CLI provider — ModelProvider.GEMINI

Mirrors the grok blueprint with source-verified divergences (all facts
pinned against google-gemini/gemini-cli @ 9681621c): no refresher
daemon — Google's refresh tokens are reusable, so the RO host mount is
COPIED to a writable container-local ~/.gemini and each container
refreshes in-process independently (the write-back crash risk on RO
never triggers); settings.json renders security.auth.selectedType
'oauth-personal', experimental.enableAgents=false (subagent ban),
autoConfigureMemory=false with a bounded heap; tool scoping rides the
tiered TOML Policy Engine (deny-only rules that yolo mode structurally
cannot beat); gemini -p with --output-format stream-json; usage parsed
from the run's own stdout stats — the adversarial pass caught the
parser reading the json-mode nested shape while the entrypoint runs
stream-json's FLAT shape (every real run would have priced $0 forever,
hidden by fixtures sharing the assumption) — now flat-primary with the
nested shape as cited fallback; rate-limit classified from structured
error.type only (model-echo immune), native exit 41 auth passthrough;
per-model pricing for the three GA models; migrations 084 (enum) + 085
(seed) complete the 082-085 finale chain. V1 excludes interactive
intake/secretary. Stack-merge required two behavior-preserving
complexity refactors in the shared park/usage plumbing (a park-pair
loop; a usage-reader dispatch dict).

* fix(providers): route gemini usage read through the containment barrier

Mirrors the codex/grok fix — _gemini_usage_json now delegates to
_read_usage_json_contained, so CodeQL's path-injection alert on the
gemini read is resolved by the same resolve-and-contain guard.

---------

Co-authored-by: Renn F <rennf93@users.noreply.github.com>
2026-07-23 03:53:21 +02:00

50 lines
2.1 KiB
Python

"""Add 'gemini' to the postgres modelprovider enum.
Gemini (``ModelProvider.GEMINI`` — Google's OAuth-authenticated ``gemini`` CLI)
is a new agent backend. Seeding its provider row (migration 085) and routing
agents to it requires the postgres ``modelprovider`` enum to carry the value.
Mirrors the enum-add pattern of migration 038 (grok); the row seed is split
into 085 because a newly added enum value cannot be used in the same
transaction that adds it.
RE-CHAIN CAVEAT: this task built against a checkout where 081 was head, so it
originally numbered these 082/083. Two sibling worktrees landed 082 (routing)
and 083 (codex `seed_openai_provider`) first — this pair was renumbered
084/085 on top of them post-hoc, in this worktree only, to keep a single
linear head: routing(082) -> codex(083) -> gemini(084/085). Neither 082 nor
083 exists in THIS checkout, so this worktree's own migration-graph-integrity
and enum-migration-parity tests fail on the missing siblings until the real
merge lands all three branches together.
Revision ID: 084_modelprovider_gemini
Revises: 083_seed_openai_provider
Create Date: 2026-07-23
"""
from __future__ import annotations
from alembic import op
revision = "084_modelprovider_gemini"
down_revision = "083_seed_openai_provider"
branch_labels = None
depends_on = None
def upgrade() -> None:
# The new value must be COMMITTED before migration 085 inserts a row using
# it: alembic runs the whole upgrade in a single transaction, and Postgres
# forbids using a freshly added enum value in the same transaction that
# added it (UnsafeNewEnumValueUsageError). autocommit_block commits the
# ALTER on its own so 'gemini' is usable downstream. Still renders the
# ALTER TYPE in offline --sql, so the enum-migration-parity test sees it.
# Idempotent via IF NOT EXISTS.
with op.get_context().autocommit_block():
op.execute("ALTER TYPE modelprovider ADD VALUE IF NOT EXISTS 'gemini'")
def downgrade() -> None:
# Postgres does not support removing enum values without a destructive
# type recreation. Forward-only by design (see migration 037).
pass