Skip to content

CXH-4061: fix MySQL []byte CEL comparisons dropping grants - #160

Open
c1-squire-dev[bot] wants to merge 3 commits into
mainfrom
connector-farm/CXH-4061-cf-261203nql5-CXH-4061-cf-261203nql5.11.2-impl
Open

c1-squire-dev[bot] wants to merge 3 commits into
mainfrom
connector-farm/CXH-4061-cf-261203nql5-CXH-4061-cf-261203nql5.11.2-impl

Conversation

@c1-squire-dev

@c1-squire-dev c1-squire-dev Bot commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

CXH-4061: normalize MySQL []byte driver values to strings at the CEL boundary

Linear: https://linear.app/ductone/issue/CXH-4061/baton-sql-fix-mysql-text-columns-comparing-unequal-in-cel-dropping-every-grant

What was asked

On MySQL, every non-numeric column reaches CEL as []byte (go-sql-driver/mysql text and binary
protocols), so a CEL comparison between a row value and a string literal is never equal. A
skip_if of the form .column != resource.ID is true for every row: every grant is skipped and
the sync exits 0 with no warning — silent data loss worse than a crash. The repo's own
examples/mysql-test.yml ships exactly that construct as its only MySQL grant mapping, and the
ticket measured 0 grants on 6 live user_roles rows; adding string(.role_name) to that one token
yielded 7 grants. PostgreSQL, SQL Server and Vertica already work because their drivers return
strings. The ask: normalize MySQL []byte row values to string at the single point where row
values cross into CEL, so user-authored comparisons compare strings on every driver, and preserve
NULL semantics (a NULL column must stay Go nil, never "NULL" or "").

What changed

One seam, three code touches, tests, and a one-line example revert:

  • pkg/bsql/query.go — normalizeRowValue(v any) any (unexported, placed beside the existing
    []byte precedents nextPageToken and toTime): two-value assertion v, ok := v.([]byte)
    converts byte slices to strings; untyped nil (a NULL column) falls through untouched, so
    == null guards keep working by construction.
  • Row-map construction (runQuery): rowMap[colName] = normalizeRowValue(values[i]) — the
    single boundary every CEL hand-off crosses, covering all five EvaluateBool chokepoints
    (grants, expandable grants, entitlements, event feed, provisioning replace) and every
    EvaluateString ternary. Pagination's lastRowID is deliberately left raw — nextPageToken
    already handles both []byte and string.
  • Provisioning replace path (same file): the replace SkipIf now evaluates against
    s.env.SyncInputs(rowMap) like every other site, instead of the raw row map (which made Evaluate
    inject an empty cols, so replace-path skip_if could not see columns at all). Expressions
    referencing resource still fail loudly there — resource is derived after the skip check —
    and that failure stays a wrapped error, not a silent skip.
  • examples/mysql-test.yml: the grant skip_if reverts to the plain form
    .role_name != resource.ID (the string() workaround that CXP-481 introduced is no longer
    needed), matching every other engine's example.
  • Tests: a table test for the helper ([]byte→string, untyped nil→nil, typed-nil slice
    pinned); a chokepoint test through the real rows.Scan path (SQLite BLOB-typed column = the
    MySQL-shaped []byte input) asserting the plain-form skip_if stops skipping and a NULL column
    matches only == null; NULL-semantics pins in the CEL package; provisioning replace-path tests
    (columns now visible; resource-referencing skip_if still errors loudly); identity pins proving
    string/int64/float64/bool/time.Time values pass through unchanged; and a guard pinning the
    example's plain form. The chokepoint test was mutation-checked: reverting the normalize line
    makes it fail.

How far this is verified

  • Targeted validation is green: validate-changes.sh (build + vet + test scoped to the touched
    packages pkg/bsql and pkg/bcel) passes, including the new tests and the existing pagination
    suite. Five independent implementations of the same specification were built and adversarially
    reviewed in isolated worktrees; this branch is the ranked winner, and its chokepoint test was
    mutation-checked to prove it fails without the fix (re-verified independently during review).
  • PR CI is green: all 10 checks terminal, none failing. The repo's review bot passed this
    exact head (b656cdc5) with no unresolved threads.
  • An independent reviewer that had seen none of the batch read this PR cold in a fresh
    environment and raised zero findings; it re-enumerated every CEL hand-off, verified
    identifier outputs stay byte-for-byte identical, and reproduced the mutation check itself.
  • A fresh-clone tester (VERA) verdict-ed the acceptance criteria: 5 WORKS, 0 BROKEN, and one row
    honestly UNTESTABLE — the live MySQL wire measurement (7 grants from 6 rows) needs a running
    MySQL this repo does not provide; that evidence is CI's MySQL engine tests, which are green.
  • Smoke: SMOKE PASS (partial) — the changed packages build and pass their own tests; this repo
    exposes no runnable mock, so nothing was started end to end.
  • connector-eval (advisory): not-applicable, "not a connector (cf_connector_kind: none)" —
    no baseline sync comparison exists for this repo.

What to look at hardest

  • Behavioral changes on []byte-returning engines, all reviewed and accepted as the fix's
    intent:
    (1) bytes-literal equality and size() on byte-typed columns now compare as CEL
    strings — a spec that used == b'...' on such a column previously content-matched bytes and
    now never matches (write the comparison against the string form, or use bytes()); .size()
    becomes a rune count on multi-byte text; (2) grantRowKey formats byte-typed event-feed
    primary keys differently (byte-list %v form → plain string) — IDs remain injective and cursor
    state is unaffected, but one deploy transition may re-emit a round of change events; (3) a
    typed-nil []byte (driver quirk, distinct from a NULL column) normalizes to "" — pinned
    explicitly in tests.
  • NULL preservation: the two-value assertion is the entire NULL story — no special case a
    future edit can break. Tests pin == null true and == ""/== "NULL" false.
  • No DSN/driver-configuration change (parseTime deliberately not added), no CEL-library change,
    no resource/entitlement/ID representation change — emitted values are byte-for-byte identical;
    only CEL's input type changes.

cf-implementer and others added 3 commits December 3, 2026 22:33
… so MySQL CEL comparisons work

Add normalizeRowValue and apply it at the runQuery row-map construction site so []byte driver values reach CEL as strings; NULL stays nil. Pass SyncInputs(rowMap) to the replace-path SkipIf EvaluateBool so column expressions are visible there, and revert the mysql-test.yml grant skip_if to the plain form. Adds chokepoint, NULL-semantics, replace-path and identity-pin tests.

Co-authored-by: c1-squire-dev[bot] <c1-squire-dev[bot]@users.noreply.github.com>
…n the BLOB chokepoint test

Co-authored-by: c1-squire-dev[bot] <c1-squire-dev[bot]@users.noreply.github.com>
…al review

Round-1 review fix-nows: assert both fixture rows are visited in the BLOB chokepoint test (closes the u1-branch false-pass window); correct the typed-nil comment (no supported driver delivers NULL as typed-nil []byte — database/sql reports NULL as untyped nil); pin that normalized columns compare as CEL strings, so bytes literals no longer match a row column (the deliberate consequence of normalization, named for the PR body).

Co-authored-by: c1-squire-dev[bot] <c1-squire-dev[bot]@users.noreply.github.com>
@c1-squire-dev c1-squire-dev Bot added the connector-farm Opened by connector-farm label Dec 3, 2026
@linear-code

linear-code Bot commented Dec 3, 2026

Copy link
Copy Markdown

CXH-4061

@github-actions

github-actions Bot commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor
Superseded — see the current review report for commit b656cdc58cdb

Connector PR Review: CXH-4061: fix MySQL []byte CEL comparisons dropping grants

Blocking Issues: 0 | Suggestions: 0 | Threads Resolved: 0
Criteria: Criteria status: loaded .claude/skills/ci-review.md from trusted base f426fc2db416.
Review mode: full
View review run

Review Summary

What changed

  • runQuery (pkg/bsql/query.go:968) now runs every scanned value through normalizeRowValue, which turns []byte into string and leaves untyped nil (NULL) alone. This is the single place row values enter CEL.
  • Pagination still uses the raw lastRowID, and nextPageToken handles both forms.
  • The provisioning replace-path skip_if (query.go:1101) now gets SyncInputs(rowMap). Before, Evaluate (pkg/bcel/bcel.go:69) replaced the missing cols with an empty map, so any .column reference in that skip_if failed. The new behavior is strictly a fix.
  • examples/mysql-test.yml goes back to the plain .role_name != resource.ID form.

Coverage
I scanned the full diff for security and correctness and followed the normalized row map into every downstream consumer:

  • Emitted IDs and strings: EvaluateString formats []byte with %s, so these values are byte-for-byte unchanged.
  • Event-feed cursors: cursorTimestamp → toTime already handles both []byte and string.
  • grantRowKey: the event-ID suffix changes once for byte-typed primary keys, from %v byte-list form to the plain string. The PR description discloses this.
  • Custom CEL functions: none in pkg/bcel take bytes. php_deserialize takes a string, so it now works directly on MySQL columns.
  • Existing string(.col) specs: docs/db2.md uses this form, and it still works because string() on a string is the identity.
  • Other bytes-dependent behavior: b'...' literal comparisons and .size() on byte columns now behave as strings. Both are disclosed and pinned in tests.

No dependency manifests changed. go-sql-driver/mysql v1.9.2 already parses numbers on the text protocol, so in practice only text and temporal columns are affected.

Repo-local criteria
The criteria were applied, but most don't fit: this is a generic SQL connector change with no HTTP client, spans or JSON structs (sections A–D), and no ID derivations or identifiers change (E and G).

  • Section S (empty-result data loss): the change reduces silent grant drops on MySQL and adds no swallowed errors. A replace-path skip_if that references resource still returns a wrapped error, and a test covers it.
  • Section F (provisioning): I read the full RunGrantProvisioning replace flow. Entity sourcing is unchanged.

Tests
They cover the helper, the real rows.Scan path with a BLOB column (the MySQL-shaped input), how NULL behaves in CEL, and the replace path.

Security Issues

None found.

Correctness Issues

None found.

Suggestions

None.

@github-actions

github-actions Bot commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Connector PR Review: CXH-4061: fix MySQL []byte CEL comparisons dropping grants

Blocking Issues: 0 | Suggestions: 0 | Threads Resolved: 0
Criteria: Criteria status: loaded .claude/skills/ci-review.md from trusted base f426fc2db416.
Review mode: full
View review run

Review Summary

What changed

  • runQuery (pkg/bsql/query.go:968) now runs every scanned value through normalizeRowValue, which turns []byte into string and leaves untyped nil (NULL) alone. This is the single place row values enter CEL.
  • Pagination still uses the raw lastRowID, and nextPageToken handles both forms.
  • The provisioning replace-path skip_if (query.go:1101) now gets SyncInputs(rowMap). Before, Evaluate (pkg/bcel/bcel.go:69) replaced the missing cols with an empty map, so any .column reference in that skip_if failed. The new behavior is strictly a fix.
  • examples/mysql-test.yml goes back to the plain .role_name != resource.ID form.

Coverage
I scanned the full diff for security and correctness and followed the normalized row map into every downstream consumer:

  • Emitted IDs and strings: EvaluateString formats []byte with %s, so these values are byte-for-byte unchanged.
  • Event-feed cursors: cursorTimestamp → toTime already handles both []byte and string.
  • grantRowKey: the event-ID suffix changes once for byte-typed primary keys, from %v byte-list form to the plain string. The PR description discloses this.
  • Custom CEL functions: none in pkg/bcel take bytes. php_deserialize takes a string, so it now works directly on MySQL columns.
  • Existing string(.col) specs: docs/db2.md uses this form, and it still works because string() on a string is the identity.
  • Other bytes-dependent behavior: b'...' literal comparisons and .size() on byte columns now behave as strings. Both are disclosed and pinned in tests.

No dependency manifests changed. go-sql-driver/mysql v1.9.2 already parses numbers on the text protocol, so in practice only text and temporal columns are affected.

Repo-local criteria
The criteria were applied, but most don't fit: this is a generic SQL connector change with no HTTP client, spans or JSON structs (sections A–D), and no ID derivations or identifiers change (E and G).

  • Section S (empty-result data loss): the change reduces silent grant drops on MySQL and adds no swallowed errors. A replace-path skip_if that references resource still returns a wrapped error, and a test covers it.
  • Section F (provisioning): I read the full RunGrantProvisioning replace flow. Entity sourcing is unchanged.

Tests
They cover the helper, the real rows.Scan path with a BLOB column (the MySQL-shaped input), how NULL behaves in CEL, and the replace path.

Security Issues

None found.

Correctness Issues

None found.

Suggestions

None.


Reviewed commit: b656cdc58cdb

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No blocking issues found — see the full review report

@c1-squire-dev
c1-squire-dev Bot marked this pull request as ready for review December 3, 2026 23:03
@c1-squire-dev
c1-squire-dev Bot requested a review from a team December 3, 2026 23:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

connector-farm Opened by connector-farm

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants