Files
roboco/alembic/versions/012_align_agentrole_foundation.py
Renn F 229797ffe3 fix: unblock smoke run (gateway envelope + alembic + redis + MCP)
Four bugs surfaced by the 2026-05-11 smoke run, all on the path from
Main PM's first delegate to the cell PM accepting a subtask:

- gateway: TaskCompletenessError from _create_subtask_from_inputs leaked
  through Starlette as a 500; agents retried in a tight loop because
  they never saw field_hints. Wrap the call in _create_subtask_and_envelope,
  catch the error, return Envelope.incomplete_input with the
  interrogation-pattern reply the upfront completeness check produces.

- alembic: migration 012 used a 40-char revision id which exceeds
  alembic_version.version_num varchar(32). Upgrade fell back to create_all
  on every boot, silently skipping the migration. Rename to
  012_align_agentrole_foundation (30 chars). File rename + revision string.

- events/stream_bus: external Redis FLUSHALL while orchestrator is running
  (e.g. reset_runtime_state.sh) drops the consumer group; the listen loop
  then spams NOGROUP every block-cycle forever. Catch ResponseError with
  NOGROUP in the message and rebootstrap the group via
  _ensure_consumer_group, then continue. Self-heals without restart.

- mcp/flow_server: delegate took body: dict with no schema, so the LLM
  invented values like nature='standard' and the SDK threw 'unhashable
  type: dict' on nested args. Flatten to typed top-level parameters with
  docstring listing valid enum values for team / task_type / nature /
  estimated_complexity. PLR0913 per-file ignore added for roboco/mcp/**
  because MCP tool signatures ARE the LLM contract — bundling into a
  dataclass would hide the enum hints that prevent the invention bug.
2026-05-11 02:46:54 +02:00

40 lines
1.4 KiB
Python

"""Align postgres agentrole/team enums with foundation/identity.
Adds any enum value the foundation declares that postgres lacks. Postgres
enum values cannot be removed without a destructive recreation, so the
inverse direction (postgres has extras the foundation lacks) is handled
in foundation by keeping the legacy value (e.g., Team.MARKETING).
Revision ID: 012_align_agentrole_foundation
Revises: 011_drop_quarantined_state
Create Date: 2026-05-10
"""
from __future__ import annotations
from alembic import context, op
revision = "012_align_agentrole_foundation"
down_revision = "011_drop_quarantined_state"
branch_labels = None
depends_on = None
def upgrade() -> None:
if context.is_offline_mode():
# Offline mode: skip — only runs when connected to a real DB.
return
# Add 'system' to agentrole enum if missing. ALTER TYPE ... ADD VALUE
# IF NOT EXISTS is idempotent in postgres >= 9.6.
op.execute("ALTER TYPE agentrole ADD VALUE IF NOT EXISTS 'system'")
# Note: every foundation Team value is expected to be already in
# postgres (verified by scripts/verify_postgres_enums.py when DB
# access is available). If a future Team is added to foundation,
# add an ALTER TYPE call for it here.
def downgrade() -> None:
# Postgres does not support removing enum values without a destructive
# type recreation. This migration is forward-only by design.
pass