Skip to content

fix(migrations): make 038 run on utf8mb4_unicode_ci schemas - #1159

Open
linus-liu-web wants to merge 1 commit into
Tencent:mainfrom
linus-liu-web:fix/migration-038-collation
Open

linus-liu-web wants to merge 1 commit into
Tencent:mainfrom
linus-liu-web:fix/migration-038-collation

Conversation

@linus-liu-web

Copy link
Copy Markdown

What changed

migrations/038_generic_sop_host_credentials.sql aborts on the default Compose database:

ERROR 1267 (HY000) at line 8: Illegal mix of collations (utf8mb4_0900_ai_ci,IMPLICIT) and (utf8mb4_unicode_ci,IMPLICIT) for operation '='

compose.yaml starts MySQL with --collation-server=utf8mb4_unicode_ci, so generic_templates.id is utf8mb4_unicode_ci, while JSON_TABLE returns its agent_id column with the server's default collation utf8mb4_0900_ai_ci. The join a.agent_id = CONCAT(t.id, '-mr') fails with ERROR 1267, so the whole script aborts and no row is rewritten. On a MySQL server whose default collation is utf8mb4_0900_ai_ci the same statement succeeds, which is why this only shows up on Compose.

docs/deployment.md tells operators upgrading from an earlier release to apply this script after the Git credential migration, so the documented upgrade path is broken for Compose deployments whose built-in MR roles still carry the old instruction.

The fix compares both sides of the join under one explicit collation:

)) a ON a.agent_id COLLATE utf8mb4_unicode_ci = CONCAT(t.id, '-mr') COLLATE utf8mb4_unicode_ci

utf8mb4_unicode_ci exists on every server that supports JSON_TABLE, so the script now runs whether the schema inherited utf8mb4_unicode_ci (Compose default) or utf8mb4_0900_ai_ci (MySQL 8 server default). The comment above the statement records the reason.

Scope

  • Public adapter / deployment
  • Platform core / API / runner
  • Classic
  • Portable
  • Shared behavior contract
  • Installer / CLI
  • Documentation only

Compatibility

No schema change: the statement rewrites generic_templates.payload for the three built-in MR roles under the same predicate as before, and remains a no-op when no row carries the old instruction. The compared ids (generic-*-mr, issue-fix-production-mr) are ASCII, so the explicit collation does not change matching behavior.

Validation

Applied to MySQL 8.4 (the image compose.yaml pins) in scratch databases seeded with the three built-in template rows carrying the old AGENTFLOW_GIT_TOKEN instruction:

Schema collation Before After
utf8mb4_unicode_ci (Compose default) ERROR 1267 at the UPDATE 3 rows converted, 0 old strings left
utf8mb4_0900_ai_ci (MySQL 8 server default) 3 rows converted, no error 3 rows converted, 0 old strings left

An unrelated agent prompt in the same payload stayed unchanged, SELECT COUNT(*) ... WHERE payload LIKE '%AGENTFLOW_GIT_TOKEN%' returned 0 afterwards, and a second run updates nothing. python3 scripts/check-public.py passes.

  • Not run: the full Go suite (go test -p=2 ./...); no Go code changed.

Safety

  • I did not include credentials, internal endpoints, production data, or organization-specific infrastructure.
  • I preserved user files and unrelated changes.
  • I updated generated Classic host bundles when applicable. (n/a — no Classic change)
  • I documented third-party content and licensing changes when applicable. (n/a)

compose.yaml starts MySQL with --collation-server=utf8mb4_unicode_ci, so
generic_templates.id is utf8mb4_unicode_ci, while JSON_TABLE returns its string
columns with the server default utf8mb4_0900_ai_ci. The join in 038 compares the
two directly and aborts the whole script with

  ERROR 1267 (HY000): Illegal mix of collations
  (utf8mb4_0900_ai_ci,IMPLICIT) and (utf8mb4_unicode_ci,IMPLICIT) for operation '='

so the documented upgrade step leaves every row unchanged on Compose. Compare
both sides of the join under one explicit collation, which works on schemas that
inherited either collation.
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