From e7afb476ff0430ebbcffd07c37ce8019c465eb6c Mon Sep 17 00:00:00 2001 From: Hampton Lintorn-Catlin Date: Wed, 29 Apr 2026 15:18:20 -0400 Subject: [PATCH] Expand plan_versions.diff_unified to mediumtext MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The PUT /api/v1/plans/:id/content endpoint exposes a pre-existing schema limit: diff_unified was 'text' (~64KB on MySQL) while content_markdown is 'mediumtext' (~16MB). A whole-file PUT of any plan whose unified diff exceeds 64KB (easy with multi-thousand-line files) triggers ActiveRecord::ValueTooLong → 500. Reproduced locally with a 5,000-line / 189KB plan and 10 scattered edits. After the migration the same PUT returns 201 in ~390ms. Affects all four PlanVersion write paths (operations_controller, commit_session, plans_controller, replace_content) — schema-level fix benefits them all. Amp-Thread-ID: https://ampcode.com/threads/T-019dda86-f31b-7148-82b5-c5f1a59c4568 Co-authored-by: Amp --- ...91637_expand_plan_version_diff_unified.co_plan.rb | 12 ++++++++++++ db/schema.rb | 4 ++-- ...0260429000000_expand_plan_version_diff_unified.rb | 11 +++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20260429191637_expand_plan_version_diff_unified.co_plan.rb create mode 100644 engine/db/migrate/20260429000000_expand_plan_version_diff_unified.rb diff --git a/db/migrate/20260429191637_expand_plan_version_diff_unified.co_plan.rb b/db/migrate/20260429191637_expand_plan_version_diff_unified.co_plan.rb new file mode 100644 index 0000000..cc1d21c --- /dev/null +++ b/db/migrate/20260429191637_expand_plan_version_diff_unified.co_plan.rb @@ -0,0 +1,12 @@ +# This migration comes from co_plan (originally 20260429000000) +class ExpandPlanVersionDiffUnified < ActiveRecord::Migration[8.0] + # The default `text` column tops out at ~64KB on MySQL, which we hit + # whenever a PlanVersion's unified diff exceeds that — easy with the + # PUT /api/v1/plans/:id/content endpoint, where agents can submit + # whole-file rewrites of large plans. content_markdown is already + # mediumtext (~16MB); diff_unified should match so any persistable + # content can also persist its diff. + def change + change_column :coplan_plan_versions, :diff_unified, :text, limit: 16.megabytes - 1 + end +end diff --git a/db/schema.rb b/db/schema.rb index 13038f8..a1ef96d 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[8.1].define(version: 2026_04_22_202551) do +ActiveRecord::Schema[8.1].define(version: 2026_04_29_191637) do create_table "active_admin_comments", id: { type: :string, limit: 36 }, charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| t.bigint "author_id" t.string "author_type" @@ -180,7 +180,7 @@ t.text "content_markdown", size: :medium, null: false t.string "content_sha256", null: false t.timestamp "created_at", null: false - t.text "diff_unified" + t.text "diff_unified", size: :medium t.json "operations_json" t.string "plan_id", limit: 36, null: false t.text "prompt_excerpt" diff --git a/engine/db/migrate/20260429000000_expand_plan_version_diff_unified.rb b/engine/db/migrate/20260429000000_expand_plan_version_diff_unified.rb new file mode 100644 index 0000000..0d7b146 --- /dev/null +++ b/engine/db/migrate/20260429000000_expand_plan_version_diff_unified.rb @@ -0,0 +1,11 @@ +class ExpandPlanVersionDiffUnified < ActiveRecord::Migration[8.0] + # The default `text` column tops out at ~64KB on MySQL, which we hit + # whenever a PlanVersion's unified diff exceeds that — easy with the + # PUT /api/v1/plans/:id/content endpoint, where agents can submit + # whole-file rewrites of large plans. content_markdown is already + # mediumtext (~16MB); diff_unified should match so any persistable + # content can also persist its diff. + def change + change_column :coplan_plan_versions, :diff_unified, :text, limit: 16.megabytes - 1 + end +end