logiSA 2.0 / DOCS

Design baseline · 28 SEP 2026 · 06 / 23

TDD · Intake & Process Routing

Technical design cho channel intake, business context và chọn Process Definition / Process Instance / Workflow con.

DESIGN DIAGRAMS · TARGET ARCHITECTURE 2.0

Flow · Intake, correlation và process routing

Gateway inbox được commit trước ACK. Core persist event trước khi Process Orchestrator gắn case và start/resume Workflow; ACK không có nghĩa nghiệp vụ hoàn tất.

Flow · Intake, correlation và process routing. Gateway inbox được commit trước ACK. Core persist event trước khi Process Orchestrator gắn case và start/resume Workflow; ACK không có nghĩa nghiệp vụ hoàn tất.

Luồng inbound đang triển khai · 30 SEP 2026

Mỗi tenant + account session + channel + thread type + nhóm/thread + sender có phiên gom độc lập. Callback đầu mở phiên; callback tiếp theo cùng khóa nối text/media/source messages và reset quiet timer (mặc định 60 giây, giới hạn 300 giây). Tài xế khác hoặc nhóm khác mở phiên riêng và tiếp tục nhận dữ liệu dù phiên khác đang chạy AI. Provider submission ID tách album nếu có; timer chỉ là fallback, không bảo đảm ranh giới hai album cùng tài xế/nhóm.

Đóng phiên → ghép một event → commit Gateway inbox → forward Core → commit event và core_master_jobs trong cùng transaction ngắn → ACK → worker Master → handler → OPS → review → outbox. Không giữ transaction khi đợi tin nhắn và không gọi Master trong intake HTTP. ACK xác nhận lưu bền vững event/job, không xác nhận đã có routing decision. Retry/lease theo job; các phiên khác không chờ AI của phiên trước. Phiên chưa đóng hiện còn trong RAM: shutdown chủ động flush, crash đột ngột có thể mất phần chưa chốt.

Acceptance hiện hành: xen kẽ hai tài xế trong một nhóm, một tài xế trong hai nhóm; mỗi phiên có đúng text/ảnh của mình; Core ACK vẫn nhanh khi Master đang chậm; duplicate không nhân đôi job/task; lỗi model retry có giới hạn và không tự gửi kết quả. Process/case routing bên dưới là thiết kế mở rộng, không khẳng định đã có generic live executor.

Responsibility boundary

Channel Intake chịu trách nhiệm nhận canonical event, scope validation, dedupe, durable persistence và ACK. Process Orchestrator chịu trách nhiệm resolve Business Case/Process Instance, intent và Workflow con cần start/resume. Intake không gán Role trực tiếp và không biến mỗi message thành Task.

Context đầu vào cho Process Orchestrator

ContextNguồn / quy tắc
Tenant, channel, session, threadGateway identity + registered scope; server xác thực, không tin tenant do model/message tự khai.
Group/thread metadataProvider ID là khóa; group title dùng làm tín hiệu mềm, không làm identity duy nhất.
Sender + directionSender ID/name, message direction, operator/bot identity; loại echo và self-generated command.
Text/mediaCaption chuẩn hóa, danh sách ảnh theo thứ tự và media type; dữ liệu không tin cậy. Cont/Seal chỉ nhận ảnh; video/audio trong album không gửi vào vision task và được đánh dấu unsupported/ignore theo policy.
Business correlationExplicit booking/container/order ID, active Business Case, open Process/Workflow Instances và correlation provenance.
ConfigurationEnabled Process Definitions, channel/group routing rules, versioned role/workflow catalog và tenant policy.

Routing algorithm

  1. Gateway gom callback trong phiên sender/thread độc lập trước khi tạo canonical event; giữ text/media/source metadata. Không giữ transaction trong thời gian đợi.
  2. Khi chốt phiên, commit event vào Gateway inbox. Core xác minh scope, chống duplicate, commit event + pending routing job rồi ACK trước AI.
  3. Resolve open Business Case/Process Instances bằng khóa nghiệp vụ + tenant + provenance. Không tạo instance mới chỉ vì có message mới.
  4. Áp dụng deterministic routing cho direction, configured group/session, explicit identifier và supported media. Dùng AI classification chỉ khi cần hiểu intent/ambiguity; trả structured proposal gồm intent, case candidates, process/workflow candidates, confidence và reason.
  5. Backend xác thực proposal: process definition đang bật, version hợp lệ, scope đúng, workflow thuộc process và Role owner hợp lệ. AI không được tạo Role/Workflow/Task type tự do.
  6. Quyết định là một trong: IGNORE có reason, ATTACH vào task/workflow đang chờ, START/RESUME Workflow trong case, MULTI_ROUTE khi nhiều intent độc lập, hoặc IGNORE khi mơ hồ.
  7. Ghi event correlation, decision audit, process/workflow/task changes atomically hoặc qua transactional outbox; chỉ ACK sau durable commit.

Message, Task và Workflow không đồng nhất

Data and idempotency keys

providerEventKey = tenant + session + channel + providerEventId; albumKey = providerAlbumId (fallback gồm tenant/session/thread/sender/time window); caseKey dựa trên business type + canonical business identifier; workflowRunKey = caseId + workflowDefinitionId + business trigger; taskKey = workflowInstanceId + taskDefinitionId + branch/iteration key. Không dedupe chỉ theo container number: một container có thể có nhiều event và nghiệp vụ.

Failure behavior

TDD acceptance

ScenarioExpected
Cùng provider event replay 10 lầnMột Message Event, không duplicate Workflow/Task; trả duplicate ACK.
Message mới về booking đang có Process InstanceGắn vào đúng case; chỉ start/resume Workflow đủ điều kiện.
Một message chứa intent booking và xe trễHai Workflow con độc lập trong cùng Process Instance nếu policy cho phép; mỗi workflow có một Role owner.
Sender/group đổi tên nhưng provider IDs giữ nguyênKhông đổi tenant/thread/case identity.
AI trả unknown process/role/workflow hoặc schema saiReject proposal; ghi nhận IGNORE có reason; không tạo executable object.
Hai Process Instance cùng mã nghiệp vụ nhưng khác tenantKhông đọc/attach chéo tenant.
Reply có thể khớp hai WAITING_INPUT workflowKhông tự attach; IGNORE nếu không xác định được correlation.

Observability

Trace nối provider event → intake → case correlation → routing decision → process instance → workflow instance → task. Metrics: inbox lag, duplicate rate, case match ambiguity, process/workflow start/resume, ignore rate, route latency. Log IDs/reason codes; không log token, raw image hoặc toàn bộ tin nhắn.

logiSA 2.0 · Public development cookbook · Design target; implementation status in Delivery.