multica-ai/multica · error

load dry-run summary: %w

Error message

load dry-run summary: %w

What it means

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.

Source

Thrown at server/cmd/backfill_codex_usage_cache/main.go:202

    COALESCE(SUM(tu.input_tokens), 0)::bigint AS input_before,
    COALESCE(SUM(GREATEST(tu.input_tokens - tu.cache_read_tokens, 0)), 0)::bigint AS input_after,
    COALESCE(SUM(tu.input_tokens - GREATEST(tu.input_tokens - tu.cache_read_tokens, 0)), 0)::bigint AS overcount,
    COUNT(*) FILTER (WHERE tu.input_tokens < tu.cache_read_tokens)::bigint AS clamped_rows,
    MIN(tu.created_at) AS min_created_at,
    MAX(tu.created_at) AS max_created_at
FROM task_usage tu
JOIN agent_task_queue atq ON atq.id = tu.task_id
JOIN agent a ON a.id = atq.agent_id
WHERE tu.provider = 'codex'
  AND tu.cache_read_tokens > 0
  AND tu.input_tokens > 0
  AND COALESCE(tu.updated_at, tu.created_at) < $1
  AND (NULLIF($2, '')::uuid IS NULL OR a.workspace_id = NULLIF($2, '')::uuid)
GROUP BY a.workspace_id, (tu.created_at AT TIME ZONE 'UTC')::date
ORDER BY a.workspace_id, date_utc`
	rows, err := pool.Query(ctx, query, cfg.cutoff, cfg.workspaceID)
	if err != nil {
		return nil, totals{}, fmt.Errorf("load dry-run summary: %w", err)
	}
	defer rows.Close()

	var summaries []summaryRow
	var total totals
	for rows.Next() {
		var row summaryRow
		if err := rows.Scan(
			&row.WorkspaceID,
			&row.DateUTC,
			&row.Rows,
			&row.InputBefore,
			&row.InputAfter,
			&row.Overcount,
			&row.ClampedRows,
			&row.MinCreatedUTC,
			&row.MaxCreatedUTC,
		); err != nil {

View on GitHub (pinned to 2c0912b6ec)

Solutions

  1. Verify the database has the current schema (migrations applied) — the wrapped error usually names the missing relation/column.
  2. Check --workspace-id is a bare UUID (no braces/quotes) or omit it to cover all workspaces.
  3. If it was a dropped connection, fix connectivity and re-run; nothing has been modified yet.

Example fix

# before
./backfill_codex_usage_cache --cutoff ... --workspace-id '{0b6ba566-...}'
# load dry-run summary: ... invalid input syntax for type uuid

# after
./backfill_codex_usage_cache --cutoff 2026-06-01T12:00:00Z --workspace-id 0b6ba566-e0d1-4bdd-a269-2d0f92b3ff3e
Defensive patterns

Strategy: validation

Validate before calling

# Pre-flight: schema objects exist and workspace filter is a bare UUID
psql "$DATABASE_URL" -c '\d task_usage' >/dev/null || exit 1
[ -z "$WS" ] || [[ "$WS" =~ ^[0-9a-f-]{36}$ ]] || { echo 'bad workspace id'; exit 1; }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of multica-ai/multica@2c0912b6ec (2026-08-15). Data as JSON: /api/errors/5b99aa05bb3ea875. Report an issue: GitHub.