← Back to Pull requests

fix(pgdb): strip NUL bytes from generated pk/sk values #163

Closed
unknown closed this pull request without merging on Aug 13, 2026 18:15 UTC
View on GitHub
unknown unknown commented on Aug 12, 2026 18:07 UTC
Author

What

A NUL byte (U+0000) in any field that feeds a message's dynamo-derived pk/sk survives into the generated pb$pk/pb$sk values (and PKSK()), while every plain string column already strips it. This PR applies the same strip to the joined pk/sk string in field_dynamo_pksk.tmpl, regenerates the example models, and adds regression tests.

Why

Postgres text values can never contain NUL, so a NUL-bearing key makes the row permanently unwritable:

  • Under pgx's simple protocol, the value is interpolated into the SQL text; the Query wire message's string is NUL-terminated, so the server's parser sees trailing bytes and rejects the whole statement with ERROR: invalid message format (SQLSTATE 08P01).

  • Under the extended protocol, the parameter is rejected with 22021.
  • Stripping at generation time matches the existing convention for plain string columns and keeps pk/sk consistent with their stripped column counterparts.

    Testing

  • TestRecord_NulByteInKeyField — pk/sk/PKSK contain no NUL for both dialects; fails without the template fix.

  • TestRecord_NulByteInSortKeyField — same, on a field-derived sort key (ScalarValue), since Pet's sk is a constant.

  • TestInsertMany_NulByteInKeyField — end-to-end upsert of a NUL-keyed row through InsertMany against pgtest succeeds.
  • Tradeoff note

    Stripping means two keys differing only by an embedded NUL now silently collide (last-writer-wins upsert) instead of failing loudly with 08P01. This matches the long-standing convention for plain string columns, and the previous behavior was that such rows could not be written at all, so no existing data changes keys.

    🤖 Generated with Claude Code

    Diff: 214 lines (+160 / -54) across 2 files Reviewer: pquerna Review duration: 1447m
    All Vouch review confidence checks passed
    Residual risk 0.14 = Change Risk (0.37) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.37 · 214 lines diff across 2 files
    0.37
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.321
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #163"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 36.6% (MEDIUM) · Higher = larger blast radius
    36.6%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 14.4% · Safe to merge
    14.4%