# Stage 22: Schema & THP Handshake (aq22_schema_handshake / DB-UNIT-11)

Negotiates pre-effect SDK and table versions, evolves supporting schemas safely, and casts normalized tables to flat task rows.

- Atomic micro-queue: `aq22_schema_handshake` (visibility: `public_commons`)
- Backing database unit: `DB-UNIT-11` (`Pre-Effect Handshakes, SWHID Parameter Bundles & Kleisli Wrappers Core`)
- Database cell: `queues-db.teleon.dev` (`teleon_core.teleon_surface_handshakes`, `teleon_core.component_parametric_configs`, `teleon_core.schema_migration_casters`)
- Claim row hydration: `single_self_contained_flat_task_row` (100% context inline, normalized writeback)
- Track 2 Sister queue (`SISTER-11`): `sq11-improve-handshakes-queue.teleon.dev` (Synthesize cross-version up/down-casters, compress middleware overhead, and maintain 10-host plugin parity.)
- Lanes: Version Negotiate, Additive Morphing, Flat-Row Cast

## Execution engines & AI Agent freedom contract

- **Deterministic (0 model calls)**: `thp_v1_hmac_and_schema_caster_v1` (Semver handshake & bidirectional row caster)
- **Hybrid (<=1 model call)**: `schema_drift_compat_advisor_v1`
- **AI Agent & Bot Fleet (1..6 calls)**: `cross_version_downgrade_shim_synthesizer_v1` (Schema gap detector & migration author)
  - Contract: **Instructions + Resources + Freedom to search for new resources and new ways not bound by instructions**

## Database invariants

- Unsupported versions fail closed prior to side effects unless a verified pure-function SchemaMigrationGate caster exists.
- Track-1 workers read pinned active_config_swhid snapshots and never mutate parameters mid-flight.

## External & internal bot fleet actions

- Detect repeated unmapped fields and propose additive supporting tables or columns
- Author pure upcasters/downcasters keeping public Teleon endpoints non-breaking
- Create custom schemas, flat-row hydrators, and micro-queues for new surfaces

## Sister self-tuning areas

- Synthesize pure-function downgrade/upgrade shims for rolling 12-month SDK versions (DIM-03)
- Tune edge KV handshake cache TTLs and pre-warmed parameter bundles (DIM-07)
- Expand universal plugin hooks across ZCode, Claude Code, T3 Code/Chat, Zed, and Cursor (DIM-03, DIM-06)
