ARTEX/db/migrations/0021_planner_progress.sql
BaaRai c54f7045bb fix(planner): bound retries with backoff, expose state, resume planning, and migrate 0021 (#676)
- B1: count retrying rounds toward MaxPlanningFailures with exponential backoff
- B2: exclude planner-authored writes from fingerprint; capture start snapshot
  and include non-agent task_scope and linked assets
- B3: expose planner recovery state in task API DTO and task detail UI
- B4: clear recovery state again when Engine.Resume lands mid-round and add
  dedicated resume_planning control action + UI button
- B5: skip stale time.Ticker heartbeats fired during a long planning round
- B6: move planner_progress DDL from db/schema.sql to migration 0021
  (0020 reserved for security batch chat_type backfill)
- i18n: add matching vi.json translations alongside tr.json and zh-CN.json
- tests: initialize secrets-at-rest key in TestPlanningCredentialUpdateReopensPlanning
2026-11-30 03:16:35 +01:00

22 lines
1.3 KiB
SQL

-- Planner round outcomes, independent of task completion. A failed planning
-- round keeps the unmet goal and survives a restart without an infinite loop:
-- db/planner_progress.go counts failed cycles on unchanged input and moves the
-- task to needs_attention after MaxPlanningFailures.
--
-- This DDL used to run from schema.sql on every boot. A database that already
-- ran that version has the table, possibly with the earlier state constraint
-- (without 'retrying'); the constraint is replaced once here.
--
-- Numbered 0021, after 0020 on main: migrations are append-only and applied in
-- version order, so this file must land after every lower-numbered one.
CREATE TABLE IF NOT EXISTS planner_progress (
exploration_id BIGINT PRIMARY KEY REFERENCES explorations(id) ON DELETE CASCADE,
state TEXT NOT NULL CHECK(state IN ('active','waiting','stalled','needs_attention','retrying')),
reason TEXT NOT NULL,
fingerprint TEXT NOT NULL,
failures INTEGER NOT NULL DEFAULT 0,
next_check_at TIMESTAMPTZ,
updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
ALTER TABLE planner_progress DROP CONSTRAINT IF EXISTS planner_progress_state_check;
ALTER TABLE planner_progress ADD CONSTRAINT planner_progress_state_check CHECK(state IN ('active','waiting','stalled','needs_attention','retrying'));