KB-CB73 rev 3

Directus Flows — SSOT v1.2

5 min read Revision 3

Directus Flows — SSOT

Version: 1.2 Date: 2026-03-19 S143 Nguồn: Audit Claude Code 2026-02-28 + S105-S107 additions + S142-S143 cleanup Tổng: ~50+ flows (26 documented below + 13 auto-ID ALL DISABLED S142-S143 + others) ⚠️ File này có thể lỗi thời. Dùng directus_list_flows MCP tool cho danh sách chính xác.


I. TỔNG QUAN

Directus Flows là cơ chế automation chính — thay thế custom backend code. Flows hoạt động theo event-driven hoặc cron schedule, KHÔNG cần code mới.

Limitation v11.5.1:

  • Không có isolated-vm → exec operations fail silently
  • Flows KHÔNG THỂ read/update/create trên cùng collection với trigger
  • Flows tạo qua API cần restart Directus mới active

Pattern chuẩn: condition-first (dùng condition operation làm gate thay vì exec).

⚠️ AUTO-ID FLOWS — TẤT CẢ ĐÃ DISABLED (S142-S143)

13 flows [AUTO-ID] * đã bị disable vì:

  1. Tất cả đều dùng hardcoded expired JWT token (900s lifetime) → 403 → 500 khi filter flow chặn request
  2. Tất cả đều thừa — PG triggers trg_auto_code_* + gen_code_*() đã thay thế hoàn toàn
  3. 7 collections đã fix: code field set required=false + PG DEFAULT ''

Quy tắc cho API callers: PHẢI gửi "code": "" rõ ràng khi tạo item. Omit field → Directus unique constraint chặn trước PG trigger.


II. DOT SYNC FLOWS (8 flows)

Đồng bộ data giữa Directus ↔ Agent Data.

Tasks CRUD → Agent Data (4 flows, ALL ACTIVE)

# Flow Trigger Operations
1 [DOT] Tasks Create → Agent Data event (items.create on tasks) Gate (log) → Read Item → Send to Agent Data (request)
2 [DOT] Tasks Update → Agent Data event (items.update on tasks) Gate (log) → Read Item → Send to Agent Data (request)
3 [DOT] Tasks Delete from Agent Data event (items.delete on tasks) Gate (log) → Delete from Agent Data (request)

Comments CRUD → Agent Data (3 flows, ALL ACTIVE)

# Flow Trigger Operations
4 [DOT] Comments Create → Agent Data event (items.create on task_comments) Gate (log) → Read Item → Send to Agent Data (request)
5 [DOT] Comments Update → Agent Data event (items.update on task_comments) Gate (log) → Read Item → Send to Agent Data (request)
6 [DOT] Comments Delete from Agent Data event (items.delete on task_comments) Gate (log) → Delete from Agent Data (request)

Knowledge Sync (2 flows, INACTIVE)

# Flow Status Lý do inactive
7 [DOT] Knowledge Sync to Agent Data ❌ INACTIVE Tránh circular sync
8 [DOT] Knowledge Delete from Agent Data ❌ INACTIVE Tương tự

Agent Data Utility (2 flows, ACTIVE)

# Flow Trigger Operations
9 [DOT] Agent Data Health Check webhook Check Info Endpoint (request)
10 [DOT] Agent Data Chat Test webhook Send Chat Query (request)

Sync Direction Rule

  • Tasks + Comments: Directus → Agent Data (Directus = source of truth)
  • Knowledge Documents: Agent Data → Directus (Agent Data = source of truth, sync DISABLED)
  • KHÔNG BAO GIỜ sync 2 chiều cùng 1 collection

Technical Details

  • FLOWS_ENV_ALLOW_LIST phải bao gồm: AGENT_DATA_URL, AGENT_DATA_API_KEY
  • AGENT_DATA_URL: http://agent-data:8000 (Docker internal)
  • Flow pattern: condition (always-pass gate) → item-read → request
  • items.create dùng $trigger.key (singular)
  • items.delete dùng $trigger.keys (plural, array)

III-VIII. KHÔNG THAY ĐỔI (xem v1.1)


IX. FLOW SUMMARY

Category Active Inactive Total
DOT Sync (Agent Data) 6 2 8
DOT Utility 2 0 2
AUTO-ID (DISABLED S143) 0 13 13
E1 Content Request 3 0 3
AI Task Management 3 0 3
Review & Governance 3 0 3
Checkpoint 1 1 2
Monitoring 3 0 3
Other 1 1 2
Total 22 17 39

X. DOT TOOLS CHO FLOWS

Tool Mô tả
dot-flow-setup-sync Setup DOT sync flows (Knowledge)
dot-flow-setup-tasks-sync Setup DOT sync flows (Tasks + Comments)
dot-rollback Xóa tất cả flows có prefix [DOT]

Cả 3 tools đều idempotent — chạy nhiều lần an toàn.