-- Add error_code column to work_queue for categorized failure handling.
-- This enables clients to distinguish between different failure modes
-- (rate limit, auth failure, timeout, stale worker) and respond appropriately.

ALTER TABLE work_queue ADD COLUMN IF NOT EXISTS error_code VARCHAR(50);

-- Index for querying tasks by error code (useful for metrics and debugging)
CREATE INDEX IF NOT EXISTS idx_work_queue_error_code ON work_queue(error_code) WHERE error_code IS NOT NULL;

COMMENT ON COLUMN work_queue.error_code IS 'Categorized error type: RATE_LIMITED, AUTH_FAILED, TIMEOUT, STALE_WORKER, AGENT_ERROR, INVALID_SPEC';
