Skip to content

refactor(store): activity upsert and contact settle in bun - #2136

Merged
tschellenbach merged 10 commits into
mainfrom
bun-builders-3
Nov 19, 2026
Merged

tschellenbach merged 10 commits into
mainfrom
bun-builders-3

Conversation

@tschellenbach

@tschellenbach tschellenbach commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

Why

Batch 3 of 3: the two statements where the builder removes positional arguments or string building, not just moves SQL around. Stacked on #2135.

Changes

Statement Before After
writeActivity (activity.go) VALUES rows joined from strings, 11 arguments a row in one list a slice of activityUpsert models; nullzero writes an empty refusal code and time as NULL, as NULLIF did
settleContact (campaign_dispatch.go) one UPDATE with 20 positional arguments one Set per column, each with its own arguments; campaigns AS cp joins through TableExpr
RecordShipment (shipping.go) two arrays through unnest unchanged: NewValues would send two parameters a row instead of two arrays

The go skill (.claude/skills/go/SKILL.md) now says to query Postgres through bun's builders on a model, and names the cases this migration kept raw.

Validation

  • go test -tags integration passes for ./internal/store (full), ./internal/activity, ./internal/campaign, ./internal/usage/ledger, ./cmd/router and the API activity and campaign suites, plus go vet -tags integration ./....
  • cmd/router's startup suites ran with ROUTER_AUTH_KEK unset: a .env that still names it makes the router refuse to start, which those suites read as their own failure.

tschellenbach and others added 9 commits November 19, 2026 12:53
20270102090000_agent_config_tool_groups.sql shared its version with 20270102090000_ui_instructions.sql, and goose refuses to run with a duplicate, so the router could not migrate. It is 20270103090000 now.

TestARedactedCallStillReportsWhatItAndItsToolCost set redact_at on the global database, so under the sharded suite RedactToolOutput, which runs on the shard, found nothing.

Co-authored-by: Cursor <cursoragent@cursor.com>
…th bun

Config tokens, authorization attempts, OAuth clients, the tool re-approval read and the connector delete loop go through bun's builders. The attempt updates share openAttempt's conditions instead of repeating them.

Co-authored-by: Cursor <cursoragent@cursor.com>
The chat and channel inbound queues (all but their claims and the thread lock, whose SQL text tests match), balance notice deliveries and event destination rotation go through bun's builders. The models' jsonb types marshal themselves, so the hand-written json.Marshal and ?::jsonb casts go.

Co-authored-by: Cursor <cursoragent@cursor.com>
…th bun

ClaimImageJobs, Reship, Unshipped, TakeOverExpired and PutOffClassification go through bun's With, TableExpr and For. Reship and Unshipped had no test; they have now, and the tests pass on the raw SQL they replace too.

Co-authored-by: Cursor <cursoragent@cursor.com>
…ith bun

User organizations and settings, linked phones, active price entries, organization apps, tag keys, turns, grant locks, episode summaries, campaign counts and the ledger's forget and prune go through bun's builders. qualified() goes: bun names a model's columns itself.

reconcileGrantsQuery stays raw: a test EXPLAINs its text. OrganizationApps had no test; it has now, passing on the old statement too.

Co-authored-by: Cursor <cursoragent@cursor.com>
bun writes a JSON \u0000 as the text \\u0000, so a delivery whose headers jsonb cannot hold was queued and claimed instead of failing, and the provider's retry found it taken. The insert goes back to json.Marshal and ?::jsonb, which TestAMessageTheStoreFailsToQueueIsNotClaimed checks.

Co-authored-by: Cursor <cursoragent@cursor.com>
channel_thread_*, channel_deliveries, chat_channel_turns, connection_event_deliveries, hook_deliveries, data_move_cursors and limit_grant_uses/reconciles get models, and their statements move to the insert, select and delete builders. Tests cover GrantUsesCounted and SetChannelThreadStarter, which none did; both pass on the raw SQL too.

Co-authored-by: Cursor <cursoragent@cursor.com>
writeActivity's multi-row upsert goes through a slice model instead of joined VALUES strings, and settleContact's update puts each argument beside the SET it fills instead of in one list of twenty. RecordShipment stays raw: the builder would send two parameters a row instead of two arrays.

Co-authored-by: Cursor <cursoragent@cursor.com>
The go skill says to query Postgres through bun's builders on a model, and names the cases that stay raw: advisory locks, session settings, DDL, INSERT ... SELECT, recursive and window queries, SQL text a test matches, and jsonb that must refuse \u0000.

Co-authored-by: Cursor <cursoragent@cursor.com>
@github-actions github-actions Bot added the docs label Nov 19, 2026
Base automatically changed from bun-builders-2 to main November 19, 2026 20:53
@tschellenbach
tschellenbach marked this pull request as ready for review November 19, 2026 20:53
@tschellenbach
tschellenbach merged commit 68227e0 into main Nov 19, 2026
5 checks passed
@tschellenbach
tschellenbach deleted the bun-builders-3 branch November 19, 2026 20:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant