Skip to content

v0.6.97: migration fix for copilot_messages#4805

Merged
icecrasher321 merged 1 commit into
mainfrom
staging
May 30, 2026
Merged

v0.6.97: migration fix for copilot_messages#4805
icecrasher321 merged 1 commit into
mainfrom
staging

Conversation

@icecrasher321
Copy link
Copy Markdown
Collaborator

fix(copilot): seq migration (#4804)

@vercel
Copy link
Copy Markdown

vercel Bot commented May 30, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
docs Building Building Preview, Comment May 30, 2026 1:53am

Request Review

@cursor
Copy link
Copy Markdown

cursor Bot commented May 30, 2026

PR Summary

Low Risk
DDL is limited to IF NOT EXISTS guards on an existing migration; the other change is test-only with no runtime behavior change in this diff.

Overview
Makes migration 0219 safe to re-run on environments where copilot_messages.seq or its index may already exist, by using IF NOT EXISTS on the column add and on copilot_messages_chat_seq_idx. The backfill UPDATE from copilot_chats.messages JSON is unchanged.

Also adds a calculateCostSummary test for a three-level nested sub-workflow trace (synthetic workflow roots with aggregate costs) so only leaf agent costs are billed once and the cost ledger still reconciles with totalCost.

Reviewed by Cursor Bugbot for commit 15ca66f. Configure here.

@icecrasher321 icecrasher321 changed the title fix(copilot): seq migration (#4804) v0.6.97: migration fix for copilot_messages May 30, 2026
@icecrasher321 icecrasher321 merged commit 2f1f633 into main May 30, 2026
20 of 21 checks passed
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 30, 2026

Greptile Summary

This PR makes migration 0219_amused_leo.sql idempotent by adding IF NOT EXISTS to both the ADD COLUMN and CREATE INDEX statements, preventing failures when the migration was already partially applied (the scenario described in #4804). It also deletes an accidentally committed Vim swap file and adds a regression test for 3-level nested sub-workflow cost de-duplication.

  • Migration fix: ADD COLUMN IF NOT EXISTS "seq" and CREATE INDEX IF NOT EXISTS are now safe for re-runs; the intermediate UPDATE CTE is inherently idempotent (setting the same derived values twice is harmless).
  • Swap file cleanup: packages/db/.env.swp — a Vim temporary file that should never have been committed — is removed.
  • New test: validates that calculateCostSummary correctly skips workflow-typed aggregate containers at all nesting depths and bills only the leaf agent spans, matching the implementation's collectCostSpans logic exactly.

Confidence Score: 5/5

Safe to merge — all three changes are targeted and low-risk.

The migration change is purely additive idempotency guards with no schema logic altered; the UPDATE CTE was already safe to re-run. The swap file deletion is housekeeping. The new test accurately reflects the implementation's behaviour and adds useful regression coverage for nested sub-workflow cost accounting.

No files require special attention.

Important Files Changed

Filename Overview
packages/db/migrations/0219_amused_leo.sql Adds IF NOT EXISTS guards to ADD COLUMN and CREATE INDEX statements, making the migration safe to re-run if previously partially applied.
packages/db/.env.swp Deletes an accidentally committed Vim swap file — correct cleanup.
apps/sim/lib/logs/execution/logging-factory.test.ts Adds a 3-level nested sub-workflow test for calculateCostSummary that verifies workflow aggregate containers are never double-counted; assertions are mathematically consistent with the implementation.

Sequence Diagram

sequenceDiagram
    participant Drizzle as Drizzle Migration Runner
    participant PG as PostgreSQL

    Drizzle->>PG: ADD COLUMN IF NOT EXISTS "seq" integer
    alt Column already exists (re-run scenario)
        PG-->>Drizzle: no-op (no error)
    else Column does not exist
        PG-->>Drizzle: column created
    end

    Drizzle->>PG: WITH ordered / first_occurrence / ranked → UPDATE copilot_messages SET seq
    PG-->>Drizzle: rows updated (idempotent)

    Drizzle->>PG: CREATE INDEX IF NOT EXISTS copilot_messages_chat_seq_idx
    alt Index already exists (re-run scenario)
        PG-->>Drizzle: no-op (no error)
    else Index does not exist
        PG-->>Drizzle: index created
    end
Loading

Reviews (1): Last reviewed commit: "fix(copilot): seq migration (#4804)" | Re-trigger Greptile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant