Skip to content

fix: resolve top production error sources from 24h error sweep#235

Merged
Makisuo merged 1 commit into
mainfrom
fix/24h-error-sweep
Jul 20, 2026
Merged

fix: resolve top production error sources from 24h error sweep#235
Makisuo merged 1 commit into
mainfrom
fix/24h-error-sweep

Conversation

@Makisuo

@Makisuo Makisuo commented Jul 20, 2026

Copy link
Copy Markdown
Collaborator

What

Three fixes from a sweep of the last 24h of production errors (~120k events, almost all from the alerting worker):

  1. Alerting worker: bind TINYBIRD_SIGNING_KEY + TINYBIRD_WORKSPACE_ID (apps/alerting/alchemy.run.ts). TinybirdOrgTokenService requires both for Tinybird-scoped raw SQL; the api worker binds them but the alerting worker never did, so every scheduler tick failed alert-rule evaluation for Tinybird-scoped orgs with WarehouseConfigError: TINYBIRD_SIGNING_KEY is required for Tinybird-scoped raw SQL (~23k errors/day, ongoing until this deploys).

  2. query-engine: emit SETTINGS before a trailing FORMAT clause (packages/query-engine/src/profiles/query-profile.ts). appendSettings appended the clause to the end of DSL SQL that already terminates in FORMAT JSON, producing … FORMAT JSON SETTINGS …, which Tinybird rejects with DB::Exception: Syntax error … (FORMAT). This caused an ~85k-error burst on Jul 19. The WarehouseQueryService FORMAT-detection regex already accepts both orders; its comment is updated and both orders are now covered by tests.

  3. CLI local mode: chunk chDB inserts (apps/cli/src/server/inserts.ts, serve.ts). The whole NDJSON batch was inlined into one INSERT … FROM format(JSONEachRow, …) statement; large log batches exceeded chDB's default ~256KB max_query_size (Code: 62, ~700 errors/day). New buildInsertStatements splits batches on line boundaries under a 200KB escaped-payload budget; a single oversized line still goes out intact as its own statement.

Reviewer notes

  • Fix 1 is deploy-config only and takes effect on the next alerting deploy; error fingerprints 17797887319973565170 / 14262904916114617522 should stop afterwards.
  • Fix 2 keeps accepting the legacy FORMAT JSON SETTINGS … order in WarehouseQueryService so nothing regresses mid-rollout.
  • Not addressed here (separate issues found in the same sweep): the Postgres permission denied on alert_rules/issue_escalations/error_issue_states/oauth_connections (ops-side grants, started Jul 19 16:20 UTC) and quarantining orgs with permanently broken configs (dead Tinybird workspace org, deleted Clerk org).

Testing

  • packages/query-engine: 808 tests pass (new appendSettings FORMAT-ordering cases included)
  • apps/api: WarehouseQueryService.test.ts 34 tests pass (new canonical-order case)
  • apps/cli: 108 tests pass (new test/inserts.test.ts covers splitting, round-trip, escaped-byte budgeting, oversized lines)
  • bun typecheck green across all 29 packages

🤖 Generated with Claude Code


View with Codesmith Autofix with Codesmith
Need help on this PR? Tag /codesmith with what you need. Autofix is disabled.


Open in Devin Review

Three fixes from an error sweep of the last 24h (~120k events, almost all
from the alerting worker):

- alerting: bind TINYBIRD_SIGNING_KEY + TINYBIRD_WORKSPACE_ID (same as the
  api worker) — without them every scheduler tick fails alert-rule
  evaluation for Tinybird-scoped orgs with WarehouseConfigError (~23k/day)
- query-engine: appendSettings now inserts SETTINGS before a trailing
  FORMAT clause; Tinybird rejects `FORMAT JSON SETTINGS …` with a syntax
  error (caused an ~85k-error burst on Jul 19)
- cli: chunk chDB inserts on line boundaries under a 200KB escaped-payload
  budget so large OTLP batches no longer trip chDB's ~256KB max_query_size
  (Code: 62, ~700/day in local mode)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@pullfrog

pullfrog Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Your Pullfrog Router balance is exhausted.

You have a card on file but auto-reload is disabled, so runs paused once your balance went past the overdraft buffer.

Top up balance → · Enable auto-reload →

Pullfrog  | ⚠️ this action is pinned to a commit SHA, which freezes the cleanup step — switch to @v0 or keep the SHA fresh with Dependabot | Rerun failed job ➔View workflow run | via Pullfrog | Using Claude Opus𝕏

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Open in Devin Review

@Makisuo
Makisuo merged commit 0bbe00e into main Jul 20, 2026
7 of 9 checks passed
@Makisuo
Makisuo deleted the fix/24h-error-sweep branch July 20, 2026 10:43
Makisuo added a commit that referenced this pull request Jul 20, 2026
…gate non-prod alerting crons (#239)

Follow-up to the Jul 20 error sweep (#235/#237). Those fixes verifiably
worked (prod errors ~110k/day -> ~220/10h); this resolves the steady error
sources that remained:

- query-engine: classify Tinybird's "invalid authentication token.
  Workspace not found" as WarehouseAuthError (it previously fell through
  to the generic WarehouseQueryError and looked retryable).
- alerting ticks: new warehouse-org-quarantine (edge-cache bucket, 6h TTL)
  parks an org whose warehouse fails with an auth/config-class error and
  skips it in the errors/anomaly/digest ticks — three prod orgs with dead
  Tinybird workspace tokens were failing every 1-5min tick forever
  (~75 errors/10h prod, ~3k/10h across stages, plus secondary
  *PersistenceError cascades). TTL expiry retries automatically once the
  org's config is repaired. DigestService gains an EdgeCacheService dep.
- oauth: new oauth_connections.revoked_at (migration 0016), stamped in the
  shared refresh path and at the Cloudflare analytics poller's revoked
  sites (a mid-poll 401 never reaches the refresh path). pollAllOrgs
  filters revoked connections, so an org whose grant was revoked stops
  re-erroring every 5 minutes; reconnect (upsertConnection) and
  resetOrgState clear the stamp.
- alerting worker: skip all crons on non-prod stages unless
  MAPLE_ALERTING_ALLOW_NONPROD=1 — stg shares the prod DB, so its crons
  iterated real orgs with stage-local Tinybird/Clerk credentials
  (~10k errors/10h; same class of leak as the #237 email gating).

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
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