|
| 1 | +# Zero Downtime Migration: v0.3 to v1.0 |
| 2 | + |
| 3 | +This guide outlines the strategy for migrating your Agent application from A2A protocol v0.3 to v1.0 without service interruption, even when running multiple distributed instances sharing a single database. |
| 4 | + |
| 5 | +--- |
| 6 | + |
| 7 | +> [!WARNING] |
| 8 | +> **Safety First:** |
| 9 | +> Before proceeding, ensure you have a backup of your database. |
| 10 | +
|
| 11 | +--- |
| 12 | + |
| 13 | +## 🛠 Prerequisites |
| 14 | + |
| 15 | +### Install Migration Tools |
| 16 | +The migration CLI is not included in the base package. Install the `db-cli` extra: |
| 17 | + |
| 18 | +```bash |
| 19 | +uv add "a2a-sdk[db-cli]" |
| 20 | +# OR |
| 21 | +pip install "a2a-sdk[db-cli]" |
| 22 | +``` |
| 23 | + |
| 24 | +--- |
| 25 | + |
| 26 | +## 🏗️ The 3-Step Strategy |
| 27 | + |
| 28 | +Zero-downtime migration requires an "Expand, Migrate, Contract" pattern. It means we first expand the schema, then migrate the code to coexist with the old format, and finally transition fully to the new v1.0 standards. |
| 29 | + |
| 30 | +### Step 1: Apply Schema Updates |
| 31 | + |
| 32 | +Run the `a2a-db` migration tool to update your tables. This adds new columns (`owner`, `protocol_version`, `last_updated`) while leaving existing v0.3 data intact. |
| 33 | + |
| 34 | +```bash |
| 35 | +# Run migration against your target database |
| 36 | +uv run a2a-db --database-url "your-database-url" |
| 37 | +``` |
| 38 | + |
| 39 | +> [!NOTE] |
| 40 | +> |
| 41 | +>For more details on the CLI migration tool, including flags, see the [A2A SDK Database Migrations README](../../../../src/a2a/migrations/README.md). |
| 42 | +
|
| 43 | +> [!NOTE] |
| 44 | +> All new columns are nullable. Your existing v0.3 code will continue to work normally after this step is completed. |
| 45 | +> |
| 46 | +> The v1.0 database stores are designed to be backward compatible by default. After this step, your new v1.0 code will be able to read existing v0.3 entries from the database using a built-in legacy parser. |
| 47 | +
|
| 48 | +#### ✅ How to Verify |
| 49 | +Confirm the schema is at the correct version: |
| 50 | + |
| 51 | +```bash |
| 52 | +uv run a2a-db current |
| 53 | +``` |
| 54 | +The output should show the latest revision ID (e.g., `38ce57e08137`). |
| 55 | + |
| 56 | +### Step 2: Rolling Deployment in Compatibility Mode |
| 57 | + |
| 58 | +In this step, you deploy the v1.0 SDK code but configure it to **write** data in the legacy v0.3 format. This ensures that any v0.3 instances still running in your cluster can read data produced by the new v1.0 instances. |
| 59 | + |
| 60 | +#### Update Initialization Code |
| 61 | +Enable the v0.3 conversion utilities in your application entry point (e.g., `main.py`). |
| 62 | + |
| 63 | +```python |
| 64 | +from a2a.server.tasks import DatabaseTaskStore, DatabasePushNotificationConfigStore |
| 65 | +from a2a.compat.v0_3.conversions import ( |
| 66 | + core_to_compat_task_model, |
| 67 | + core_to_compat_push_notification_config_model, |
| 68 | +) |
| 69 | + |
| 70 | +# Initialize stores with compatibility conversion |
| 71 | +# The '... # other' represents your existing configuration (engine, table_name, etc.) |
| 72 | +task_store = DatabaseTaskStore( |
| 73 | + ... # other arguments |
| 74 | + core_to_model_conversion=core_to_compat_task_model |
| 75 | +) |
| 76 | + |
| 77 | +config_store = DatabasePushNotificationConfigStore( |
| 78 | + ... # other arguments |
| 79 | + core_to_model_conversion=core_to_compat_push_notification_config_model |
| 80 | +) |
| 81 | +``` |
| 82 | + |
| 83 | +#### Perform a Rolling Restart |
| 84 | +Deploy the new code by restarting your instances one by one. |
| 85 | + |
| 86 | +#### ✅ How to Verify |
| 87 | +Verify that v1.0 instances are successfully writing to the database. In the `tasks` and `push_notification_configs` tables, new rows created during this phase should have `protocol_version` set to `0.3`. |
| 88 | + |
| 89 | +### Step 3: Transition to v1.0 Mode |
| 90 | + |
| 91 | +Once **100%** of your application instances are running v1.0 code (with compatibility mode enabled), you can switch to the v1.0 write format. |
| 92 | + |
| 93 | +> [!CAUTION] |
| 94 | +> **CRITICAL PRE-REQUISITE**: Do NOT start Step 3 until you have confirmed that no v0.3 instances remain. Old v0.3 code cannot parse the new v1.0 native database entries. |
| 95 | +
|
| 96 | +#### Disable Compatibility Logic |
| 97 | +Remove the `core_to_model_conversion` arguments from your Store constructors. |
| 98 | + |
| 99 | +```python |
| 100 | +# Revert to native v1.0 write behavior |
| 101 | +task_store = DatabaseTaskStore(engine=engine, ...) |
| 102 | +config_store = DatabasePushNotificationConfigStore(engine=engine, ...) |
| 103 | +``` |
| 104 | + |
| 105 | +#### Perform a Final Rolling Restart |
| 106 | + |
| 107 | +Restart your instances again. |
| 108 | + |
| 109 | +#### ✅ How to Verify |
| 110 | +Inspect the `tasks` and `push_notification_configs` tables. New entries should now show `protocol_version` as `1.0`. |
| 111 | + |
| 112 | +--- |
| 113 | + |
| 114 | +## 🛠️ Why it Works |
| 115 | + |
| 116 | +The A2A `DatabaseStore` classes follow a version-aware read/write pattern: |
| 117 | + |
| 118 | +1. **Write Logic**: If `core_to_model_conversion` is provided, it is used. Otherwise, it defaults to the v1.0 Protobuf JSON format. |
| 119 | +2. **Read Logic**: The store automatically inspects the `protocol_version` column for every row. |
| 120 | + * If `NULL` or `0.3`, it uses the internal **v0.3 legacy parser**. |
| 121 | + * If `1.0`, it uses the modern **Protobuf parser**. |
| 122 | + |
| 123 | +This allows v1.0 instances to read *all* existing data regardless of when it was written. |
| 124 | + |
| 125 | +--- |
| 126 | + |
| 127 | +## 🧩 Resources |
| 128 | +- **[a2a-db CLI](../../../../src/a2a/migrations/README.md)**: The primary tool for executing schema migrations. |
| 129 | +- **[Compatibility Conversions](../../../../src/a2a/compat/v0_3/conversions.py)**: Source for classes like `core_to_compat_task_model` used in Step 2. |
| 130 | +- **[Task Store Implementation](../../../../src/a2a/server/tasks/database_task_store.py)**: The `DatabaseTaskStore` which handles the version-aware read/write logic. |
| 131 | +- **[Push Notification Store Implementation](../../../../src/a2a/server/tasks/database_push_notification_config_store.py)**: The `DatabasePushNotificationConfigStore` which handles the version-aware read/write logic. |
| 132 | + |
0 commit comments