-- 2026-05-20 PR-Worker-Pool-Registry-1B: worker_jobs 테이블 신규. -- worker-pool-policy §8 방향 (b) — ProcessingQueue 무변경, worker 전용 큐 분리. -- §8 결정: document_id 컬럼 의도적 부재. memo/event recap + future code_review/long_summary -- /repo_analysis 모두 document 단위 아님. context 는 payload JSONB 안에. -- user_id 의미 = job owner user_id (실 사용자). worker bot 의 user_id 가 아님. -- 1C recap context 가 user_id 기준 memos/events JOIN. worker 인증은 worker_id + JWT 별도. -- §B.2 invariant 3: result = raw JSONB only (canonical promote 0, Notebook-Pilot-1 영역). -- §B.2 invariant 4: ProcessingQueue 무변경 — 이 테이블은 document FK 없음. -- claim 방식 = SELECT FOR UPDATE SKIP LOCKED (queue_consumer 의 단순 UPDATE 와 다름). -- status CHECK constraint = 신규 table 부터 enum 문자열 drift 차단. -- explicit /result failed 재시도 (attempts < max_attempts → pending 복귀) = 1B 영역. -- stale recovery (timeout 기반) = Notebook-Pilot-1 영역. CREATE TABLE IF NOT EXISTS worker_jobs ( id BIGSERIAL PRIMARY KEY, user_id BIGINT NOT NULL REFERENCES users(id) ON DELETE RESTRICT, job_type TEXT NOT NULL, status TEXT NOT NULL DEFAULT 'pending' CHECK (status IN ('pending', 'processing', 'completed', 'failed')), worker_id TEXT REFERENCES worker_capabilities(worker_id) ON DELETE SET NULL, payload JSONB NOT NULL DEFAULT '{}'::jsonb, result JSONB, error_message TEXT, attempts SMALLINT NOT NULL DEFAULT 0, max_attempts SMALLINT NOT NULL DEFAULT 3, created_at TIMESTAMPTZ NOT NULL DEFAULT now(), claimed_at TIMESTAMPTZ, completed_at TIMESTAMPTZ );