diff --git a/.planning/HANDOFF.json b/.planning/HANDOFF.json
index 0685543..1dd25da 100644
--- a/.planning/HANDOFF.json
+++ b/.planning/HANDOFF.json
@@ -1,51 +1,36 @@
{
"version": "1.0",
- "timestamp": "2026-05-28T15:02:40Z",
- "phase": "4",
- "phase_name": "Folders, Sharing, Quotas & Document UX",
- "phase_dir": ".planning/phases/04-folders-sharing-quotas-document-ux",
- "plan": 9,
- "task": null,
- "total_tasks": null,
+ "timestamp": "2026-06-03T16:33:39Z",
+ "phase": "7",
+ "phase_name": "Redo and Optimize LLM Integration",
+ "phase_dir": ".planning/phases/07-redo-and-optimize-llm-integration",
+ "plan": 0,
+ "task": 0,
+ "total_tasks": 15,
"status": "paused",
- "completed_tasks": [
- {"id": 1, "name": "File manager UX redesign — FileManagerView.vue", "status": "done"},
- {"id": 2, "name": "AppSidebar: Folders as clickable router-link to /", "status": "done"},
- {"id": 3, "name": "Root / shows root folders (loadFolder(null) fetches them)", "status": "done"},
- {"id": 4, "name": "Frontend test suite (Vitest) — folders store, FolderBreadcrumb, FolderTreeItem, FileManagerView", "status": "done"},
- {"id": 5, "name": "Bug fix: @click.stop on folder name div blocked navigation", "status": "done"},
- {"id": 6, "name": "Backend test suite — test_folders.py (35 tests)", "status": "done"},
- {"id": 7, "name": "Bug fix: duplicate folder name 409 for NULL parent_id (explicit ORM check)", "status": "done"},
- {"id": 8, "name": "Bug fix: delete_folder CTE UUID format mismatch (.hex fix)", "status": "done"},
- {"id": 9, "name": "Bug fix: quota UPDATE UUID format mismatch (.hex fix)", "status": "done"}
- ],
+ "completed_tasks": [],
"remaining_tasks": [
- {"id": 10, "name": "Commit all uncommitted changes", "status": "not_started"},
- {"id": 11, "name": "Phase 4 verification / UAT", "status": "not_started"},
- {"id": 12, "name": "Phase 5 (pluggable cloud storage backends)", "status": "not_started"}
+ {"id": "07-01", "name": "Foundation: migration 0005 + SystemSettings ORM + ai_config.py HKDF + Wave 0 stubs", "status": "not_started"},
+ {"id": "07-02", "name": "ProviderConfig + GenericOpenAIProvider + OpenAI singleton + registry get_provider + MAX_AI_CHARS removal", "status": "not_started"},
+ {"id": "07-03", "name": "Anthropic output_config + AnthropicProvider singleton + classifier wiring via load_provider_config", "status": "not_started"},
+ {"id": "07-04", "name": "Celery retry 30/90/270s + _ClassificationError + re-classify endpoint re-queues", "status": "not_started"},
+ {"id": "07-05", "name": "Admin AI Providers panel + DocumentCard badge + Re-analyze button + human UAT checkpoint", "status": "not_started"}
],
"blockers": [],
- "human_actions_pending": [],
+ "human_actions_pending": [
+ {
+ "action": "UAT checkpoint in Plan 07-05 Task 4: manually test admin AI Providers panel and DocumentCard badge end-to-end",
+ "context": "Plan 05 is autonomous=false with a blocking human checkpoint — executor will pause and request manual verification",
+ "blocking": false
+ }
+ ],
"decisions": [
- {"decision": "Remove @click.stop from folder name column wrapper div in FileManagerView", "rationale": "Parent @click handler returns null when renaming — stop is unnecessary and blocked navigation", "phase": "4"},
- {"decision": "Explicit ORM duplicate check before folder insert/rename instead of relying on IntegrityError", "rationale": "UniqueConstraint(user_id, parent_id, name) doesn't enforce uniqueness when parent_id IS NULL — SQL NULL != NULL semantics", "phase": "4"},
- {"decision": "Use uuid.hex (no dashes) in raw SQL CTE parameters", "rationale": "SQLite stores UUID as 32-char hex without dashes; str(uuid) gives dashes — CTE WHERE clause never matched", "phase": "4"}
+ {"decision": "D-03: Anthropic uses output_config.format.type='json_schema' (not tool_use)", "rationale": "Constrained decoding, no beta headers needed, SDK >=0.95.0", "phase": "7"},
+ {"decision": "D-07: Client lifecycle = instance-level singleton self._client in __init__", "rationale": "AsyncOpenAI/AsyncAnthropic manage httpx connection pool; recreating per call destroys pool reuse", "phase": "7"},
+ {"decision": "D-14: extra_hosts already present in docker-compose.yml — no changes needed", "rationale": "RESEARCH.md confirmed both backend and celery-worker already have host.docker.internal:host-gateway", "phase": "7"},
+ {"decision": "D-02/Gemini: supports_json_mode=False, falls back to parse_classification()", "rationale": "Gemini OpenAI-compat does not support json_object string mode", "phase": "7"}
],
- "uncommitted_files": [
- "backend/api/folders.py",
- "backend/tests/test_folders.py",
- "frontend/src/views/FileManagerView.vue",
- "frontend/src/components/layout/AppSidebar.vue",
- "frontend/src/stores/folders.js",
- "frontend/src/stores/documents.js",
- "frontend/src/router/index.js",
- "frontend/src/components/folders/FolderTreeItem.vue",
- "frontend/src/components/folders/__tests__/",
- "frontend/src/stores/__tests__/",
- "frontend/src/views/__tests__/",
- "frontend/vitest.config.js",
- "frontend/package.json"
- ],
- "next_action": "Run: git add -A && git commit. Then /gsd:verify-work 4 to validate phase 4 completion.",
- "context_notes": "Phase 4 plans 04-01 through 04-09 all complete. File manager UX redesign done. Test suite created and all passing (55 frontend, 35 backend). Three bugs fixed. Ready to commit and verify phase."
+ "uncommitted_files": [],
+ "next_action": "Run /gsd:execute-phase 7 after /clear — start with plan 07-01",
+ "context_notes": "Phase 7 planning 100% complete. All 5 plans created and verified (commit 3df6250). anthropic pin must be bumped to >=0.95.0 in Plan 02. POST /api/documents/{id}/classify already exists — Plan 04 changes behavior only. AdminAiConfigTab.vue per-user table must be preserved; Plan 05 adds global section ABOVE it."
}
diff --git a/.planning/phases/07-redo-and-optimize-llm-integration/.continue-here.md b/.planning/phases/07-redo-and-optimize-llm-integration/.continue-here.md
new file mode 100644
index 0000000..d71d255
--- /dev/null
+++ b/.planning/phases/07-redo-and-optimize-llm-integration/.continue-here.md
@@ -0,0 +1,76 @@
+---
+context: phase
+phase: 07-redo-and-optimize-llm-integration
+task: 0
+total_tasks: 15
+status: planned
+last_updated: 2026-06-03T16:33:39Z
+---
+
+# BLOCKING CONSTRAINTS — Read Before Anything Else
+
+_No constraints discovered through failure this session — planning only._
+
+
+Phase 7 planning is 100% complete. All 5 plans created, plan checker passed (4 blockers fixed in 1 revision round). Nothing has been executed yet. Next step is /gsd:execute-phase 7.
+
+
+
+This session (2026-06-03):
+- Phase 7 discuss-phase was already complete (07-CONTEXT.md existed)
+- Research completed → 07-RESEARCH.md (D-03 and D-07 resolved)
+- 07-VALIDATION.md created (13 Wave 0 test stubs mapped)
+- 07-PATTERNS.md created (14 files mapped to analogs)
+- 5 PLAN.md files created (07-01 through 07-05)
+- Plan checker ran — 4 blockers, 3 warnings found
+- Revision round fixed all 7 issues
+- Plan checker re-run → VERIFICATION PASSED
+- STATE.md and ROADMAP.md updated
+- All artifacts committed: 3df6250
+
+
+
+Execute all 5 plans in order:
+- 07-01 (Wave 1): Alembic migration 0005 + SystemSettings ORM + ai_config.py HKDF helpers + 13 xfail stubs
+- 07-02 (Wave 2): ProviderConfig + GenericOpenAIProvider + OpenAI singleton + registry + MAX_AI_CHARS removal + anthropic>=0.95.0 pin
+- 07-03 (Wave 3): AnthropicProvider output_config + classifier wiring via load_provider_config
+- 07-04 (Wave 4): Celery retry 30/90/270s + _ClassificationError + re-classify endpoint
+- 07-05 (Wave 5): Admin AI Providers panel + DocumentCard badge + Re-analyze button + human UAT checkpoint (autonomous=false)
+
+
+
+- D-03 (Anthropic structured output): Use output_config.format.type="json_schema" — constrained decoding, no beta headers, SDK >=0.95.0 required
+- D-07 (Client lifecycle): Instance-level singleton self._client in __init__ — AsyncOpenAI/AsyncAnthropic manage httpx pools internally; recreating per call destroys pool reuse
+- D-14 (extra_hosts): Already done in docker-compose.yml — no changes needed (verified by RESEARCH.md)
+- D-02/Gemini: GenericOpenAIProvider has supports_json_mode=False for Gemini preset — falls back to parse_classification()
+- Celery retry: _ClassificationError raised from _run(), caught in outer sync extract_and_classify() which calls self.retry() — NOT inside asyncio.run()
+- AdminAiConfigTab.vue: ADDITIVE change only — new global System AI Providers section goes ABOVE existing per-user assignment table (Pitfall 6)
+- MAX_AI_CHARS: Defined in 3 places (openai_provider.py L5, anthropic_provider.py L5, classifier.py L28) — all 3 removed across Plans 02+03
+
+
+
+None.
+
+
+## Required Reading (in order)
+1. `.planning/phases/07-redo-and-optimize-llm-integration/07-CONTEXT.md` — locked decisions D-01..D-18
+2. `.planning/phases/07-redo-and-optimize-llm-integration/07-RESEARCH.md` — resolved patterns (Anthropic output_config, singleton client, Celery retry, system_settings design)
+3. `.planning/phases/07-redo-and-optimize-llm-integration/07-01-PLAN.md` through `07-05-PLAN.md` — execution plans
+
+## Critical Anti-Patterns (do NOT repeat these)
+- **Wrong phase number**: User typed `/gsd-plan-phase 3` but meant Phase 7. Phase 3 is complete. Phase 7 is the active phase.
+- **Celery retry inside asyncio.run()**: self.retry() must be raised from the OUTER sync task body. Raising it inside asyncio.run(_run()) corrupts async state (RESEARCH Pitfall 3).
+- **AdminAiConfigTab.vue overwrite**: Existing per-user assignment table (ADMIN-05) must NOT be removed. New section is additive only (RESEARCH Pitfall 6).
+
+## Infrastructure State
+- Docker services: not running (stopped between sessions)
+- Last test run: 344 passed / 1 pre-existing failure (test_extract_docx missing module) — from Phase 6.2 execution
+- Git: clean working tree, commit 3df6250
+
+
+Session was planning-only. No code was written. Phase 7 planning artifacts are complete and committed. The codebase is unchanged from the end of Phase 6.2. Ready to execute.
+
+
+
+/clear, then: /gsd:execute-phase 7
+