{"record":{"id":"5b99aa05bb3ea875","repo":"multica-ai/multica","slug":"load-dry-run-summary-w","errorCode":null,"errorMessage":"load dry-run summary: %w","messagePattern":"load dry-run summary: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/cmd/backfill_codex_usage_cache/main.go","lineNumber":202,"sourceCode":"    COALESCE(SUM(tu.input_tokens), 0)::bigint AS input_before,\n    COALESCE(SUM(GREATEST(tu.input_tokens - tu.cache_read_tokens, 0)), 0)::bigint AS input_after,\n    COALESCE(SUM(tu.input_tokens - GREATEST(tu.input_tokens - tu.cache_read_tokens, 0)), 0)::bigint AS overcount,\n    COUNT(*) FILTER (WHERE tu.input_tokens < tu.cache_read_tokens)::bigint AS clamped_rows,\n    MIN(tu.created_at) AS min_created_at,\n    MAX(tu.created_at) AS max_created_at\nFROM task_usage tu\nJOIN agent_task_queue atq ON atq.id = tu.task_id\nJOIN agent a ON a.id = atq.agent_id\nWHERE tu.provider = 'codex'\n  AND tu.cache_read_tokens > 0\n  AND tu.input_tokens > 0\n  AND COALESCE(tu.updated_at, tu.created_at) < $1\n  AND (NULLIF($2, '')::uuid IS NULL OR a.workspace_id = NULLIF($2, '')::uuid)\nGROUP BY a.workspace_id, (tu.created_at AT TIME ZONE 'UTC')::date\nORDER BY a.workspace_id, date_utc`\n\trows, err := pool.Query(ctx, query, cfg.cutoff, cfg.workspaceID)\n\tif err != nil {\n\t\treturn nil, totals{}, fmt.Errorf(\"load dry-run summary: %w\", err)\n\t}\n\tdefer rows.Close()\n\n\tvar summaries []summaryRow\n\tvar total totals\n\tfor rows.Next() {\n\t\tvar row summaryRow\n\t\tif err := rows.Scan(\n\t\t\t&row.WorkspaceID,\n\t\t\t&row.DateUTC,\n\t\t\t&row.Rows,\n\t\t\t&row.InputBefore,\n\t\t\t&row.InputAfter,\n\t\t\t&row.Overcount,\n\t\t\t&row.ClampedRows,\n\t\t\t&row.MinCreatedUTC,\n\t\t\t&row.MaxCreatedUTC,\n\t\t); err != nil {","sourceCodeStart":184,"sourceCodeEnd":220,"githubUrl":"https://github.com/multica-ai/multica/blob/2c0912b6ec764b373d44eeea1e80f0d9f11ab417/server/cmd/backfill_codex_usage_cache/main.go#L184-L220","documentation":"Returned when the dry-run summary SELECT fails before any row is read. This query joins task_usage → agent_task_queue → agent filtering provider='codex', cache_read_tokens>0, input_tokens>0, and updated_at/created_at before the cutoff, optionally scoped to --workspace-id. Failure means the query itself errored: missing relations/columns (schema drift), an invalid --workspace-id (not a UUID), or a dead connection.","triggerScenarios":"Running the tool against a database missing the task_usage/agent_task_queue/agent tables or their columns (partial migration); passing --workspace-id that is not a valid UUID; connection loss between ping and query.","commonSituations":"Pointing DATABASE_URL at a stale/staging schema; a workspace ID copied with whitespace or braces; running the Codex backfill on a database that predates Codex usage tracking.","solutions":["Verify the database has the current schema (migrations applied) — the wrapped error usually names the missing relation/column.","Check --workspace-id is a bare UUID (no braces/quotes) or omit it to cover all workspaces.","If it was a dropped connection, fix connectivity and re-run; nothing has been modified yet."],"exampleFix":"# before\n./backfill_codex_usage_cache --cutoff ... --workspace-id '{0b6ba566-...}'\n# load dry-run summary: ... invalid input syntax for type uuid\n\n# after\n./backfill_codex_usage_cache --cutoff 2026-06-01T12:00:00Z --workspace-id 0b6ba566-e0d1-4bdd-a269-2d0f92b3ff3e","handlingStrategy":"validation","validationCode":"# Pre-flight: schema objects exist and workspace filter is a bare UUID\npsql \"$DATABASE_URL\" -c '\\d task_usage' >/dev/null || exit 1\n[ -z \"$WS\" ] || [[ \"$WS\" =~ ^[0-9a-f-]{36}$ ]] || { echo 'bad workspace id'; exit 1; }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run migrations first; the summary query needs task_usage, agent_task_queue, and agent with current columns.","Pass --workspace-id as a bare UUID, or omit it for all workspaces.","Run the dry-run before --execute — it validates the whole read path with zero risk."],"tags":["database","backfill","query","schema","validation"],"backgroundTag":null,"analyzedSha":"2c0912b6ec764b373d44eeea1e80f0d9f11ab417","analyzedAt":"2026-08-15T13:25:18.241Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}