Summary
The order lifecycle is only half-wired: backend pieces exist for assign-agent, geolocation relay, OTP generate/verify, and customer stepper (QC-56), but critical agent and cancellation flows have no UI or API, and one status transition (agent_assigned → out_for_delivery) is never performed in production code. Customers see the stepper stall on Agent assigned; agents see a map + chat but cannot start delivery, complete delivery, or cancel from the app.
This issue tracks the missing work to complete the delivery workflow across agent, customer, and owner roles.
What existing open issues cover (and what they do not)
| Issue |
Covers |
Does not cover |
| #58 QC-56 |
Customer order detail stepper UI (read-only) |
Status transitions, agent actions |
| #59 QC-57 |
Customer live tracking map (subscribe to agent-location) |
Agent start/complete/cancel; out_for_delivery transition |
| #60 QC-58 |
Customer stepper live updates via Pusher order-status |
Creating status changes; agent OTP UI |
| #127 QC-68 |
Post-checkout navigation, cart clear, links on order detail |
Agent delivery panel, OTP, cancel |
| #141 |
Vague “workflow polish” |
No concrete delivery spec |
| #46–47 QC-44/45 (done) |
POST /api/otp/generate, POST /api/otp/verify APIs |
No agent frontend calling these routes |
| #43–45 QC-41–43 (done) |
Assign agent, delivery map, location relay |
Start delivery, complete delivery UI, cancel |
Conclusion: None of the open issues fully close the gap described below. Implement this epic (or split into sub-issues) after QC-56 merges; coordinate with QC-57/58 for customer-side updates.
Canonical status flow (intended)
placed → confirmed → awaiting_agent → agent_assigned → out_for_delivery → delivered
↘ cancelled (terminal)
Owner early cancel: placed|confirmed → cancelled (already via PATCH /api/orders/[id]/status, owner-only).
Defined in lib/order-status-transitions.ts:
- Owner:
placed/confirmed → cancelled; confirmed → awaiting_agent (request agent).
- Agent:
awaiting_agent → agent_assigned (assign); agent_assigned → out_for_delivery; out_for_delivery → delivered (via OTP verify today).
Gap analysis (current repo state)
1. agent_assigned → out_for_delivery — not implemented
- Transition exists in
AGENT_ORDER_TRANSITIONS but no API route or UI sets out_for_delivery.
- Customer stepper stays on Agent assigned until manual DB edit or jump to
delivered.
- Owner Kanban groups both statuses in “Out for Delivery” column, which masks the gap.
Needed:
2. Mark delivered — API only, no agent UI
Needed:
3. Cancel delivery — not available to agent or customer mid-flight
- Owner can cancel only from
placed or confirmed (OWNER_ORDER_TRANSITIONS).
- No path to cancel after
awaiting_agent, agent_assigned, or out_for_delivery.
- Customer order detail shows cancelled alert (QC-56) but no cancel button.
Needed (product rules — pick and document):
| Actor |
Suggested cancel rules |
| Customer |
Cancel while placed (before shop confirms)? Or until agent_assigned? Refund policy for Stripe? |
| Owner |
Cancel through awaiting_agent / before agent starts? Force cancel with reason? |
| Agent |
Abort delivery (unassign): agent_assigned/out_for_delivery → awaiting_agent, clear agentId? Or → cancelled? |
Implementation:
4. Agent release / reassignment (optional but common)
- Today: first accept wins (
assign-agent); no release.
- If agent abandons, order may stay
agent_assigned forever.
Needed:
5. Customer tracking UX (ties to QC-57/58)
- Location relay works from agent map (
DeliveryMap POSTs every 3s).
- Customer page has stepper but no map until QC-57.
- Stepper does not live-update until QC-58.
Needed (cross-link, not duplicate QC-57/58):
6. Payment / COD clarity on completion
- COD stays
pending until OTP verify (QC-54/45) — good.
- Agent UI should show: “Collect ₹X cash” for COD before verify.
- Stripe orders: verify only marks delivered (payment already
paid via webhook).
Proposed implementation phases
Phase A — Agent happy path (minimum viable delivery)
- Start delivery API + button (
out_for_delivery).
- OTP generate + verify UI on agent delivery page.
- Manual QA: accept → start → generate OTP → verify → customer stepper shows delivered.
Phase B — Cancellations & release
- Transition rules + cancel/release APIs per table above.
- Customer + owner + agent cancel/release UI.
- Refund note for Stripe (document or stub webhook reversal out of scope).
Phase C — Polish (can parallel QC-57/58)
- Customer tracking map when
out_for_delivery.
- Live stepper (QC-58).
- Agent orders list: CTA labels (“Continue delivery”, “Start delivery”).
Files likely touched
| Area |
Files |
| Transitions |
lib/order-status-transitions.ts, new lib/agent-order-status.ts or extend owner PATCH with role checks |
| APIs |
app/api/orders/[id]/status/route.ts (or new routes under app/api/orders/[id]/) |
| Agent UI |
app/(agent)/agent/delivery/[orderId]/page.tsx, new components/agent/AgentDeliveryPanel.tsx |
| Customer UI |
app/(customer)/customer/orders/[orderId]/page.tsx, optional cancel modal |
| Owner UI |
components/owner/OwnerOrdersKanban.tsx, components/order/OrderCard.tsx |
| Realtime |
lib/pusher-server.ts (reuse notifyOrderStatusUpdated) |
| Docs |
docs/IMPLEMENTATION_CONTEXT.md, scripts/test-*-api.mts |
Acceptance criteria
Agent
Customer
Owner
System
Test plan
npm run lint && npx tsc --noEmit
# API scripts (add as built):
npx tsx --env-file=.env.local scripts/test-agent-delivery-flow.mts
# Manual E2E
# 1. Customer places COD order
# 2. Owner confirms → request agent
# 3. Agent accepts → agent_assigned
# 4. Agent opens delivery → Start delivery → out_for_delivery
# 5. Customer order detail: stepper on Out for delivery; map moves (QC-57)
# 6. Agent Generate OTP → customer email
# 7. Agent Verify OTP → delivered; customer stepper complete; COD paid
# 8. (Phase B) Cancel paths per role
Depends on
Suggested follow-up splits (optional child issues)
- QC-69a Agent start-delivery API + UI
- QC-69b Agent OTP panel on delivery page
- QC-69c Cancel / release order APIs + multi-role UI
Summary
The order lifecycle is only half-wired: backend pieces exist for assign-agent, geolocation relay, OTP generate/verify, and customer stepper (QC-56), but critical agent and cancellation flows have no UI or API, and one status transition (
agent_assigned→out_for_delivery) is never performed in production code. Customers see the stepper stall on Agent assigned; agents see a map + chat but cannot start delivery, complete delivery, or cancel from the app.This issue tracks the missing work to complete the delivery workflow across agent, customer, and owner roles.
What existing open issues cover (and what they do not)
agent-location)out_for_deliverytransitionorder-statusPOST /api/otp/generate,POST /api/otp/verifyAPIsConclusion: None of the open issues fully close the gap described below. Implement this epic (or split into sub-issues) after QC-56 merges; coordinate with QC-57/58 for customer-side updates.
Canonical status flow (intended)
Owner early cancel:
placed|confirmed→cancelled(already viaPATCH /api/orders/[id]/status, owner-only).Defined in
lib/order-status-transitions.ts:placed/confirmed→cancelled;confirmed→awaiting_agent(request agent).awaiting_agent→agent_assigned(assign);agent_assigned→out_for_delivery;out_for_delivery→delivered(via OTP verify today).Gap analysis (current repo state)
1.
agent_assigned→out_for_delivery— not implementedAGENT_ORDER_TRANSITIONSbut no API route or UI setsout_for_delivery.delivered.Needed:
PATCH /api/orders/[id]/statusor dedicatedPOST /api/orders/[id]/start-delivery(agent-only, assigned agent, fromagent_assignedonly).order-statusPusher event.2. Mark delivered — API only, no agent UI
POST /api/otp/verifysetsdelivered,deliveredAt, CODpaymentStatus: paid, firesorder-status+order-delivered.POST /api/otp/generateemails 6-digit OTP to customer (SMTP required).app/(agent)/agent/delivery/[orderId]/page.tsx) has map + chat only — no OTP panel.Needed:
AgentDeliveryActions(or sheet/drawer on delivery page):email_unavailable./agent/ordersor history.out_for_delivery/delivered.3. Cancel delivery — not available to agent or customer mid-flight
placedorconfirmed(OWNER_ORDER_TRANSITIONS).awaiting_agent,agent_assigned, orout_for_delivery.Needed (product rules — pick and document):
placed(before shop confirms)? Or untilagent_assigned? Refund policy for Stripe?awaiting_agent/ before agent starts? Force cancel with reason?agent_assigned/out_for_delivery→awaiting_agent, clearagentId? Or →cancelled?Implementation:
POST /api/orders/[id]/cancelwith{ reason? }(role-scoped).order-statuson all cancel paths; stepper + Kanban update (QC-58).4. Agent release / reassignment (optional but common)
assign-agent); no release.agent_assignedforever.Needed:
POST /api/orders/[id]/release-agent(assigned agent only) →awaiting_agent,agentId: null, notifypresence-agentsagain?5. Customer tracking UX (ties to QC-57/58)
DeliveryMapPOSTs every 3s).Needed (cross-link, not duplicate QC-57/58):
start-deliveryanddeliveredtransitions emitnotifyOrderStatusUpdated(already pattern in verify/assign).order-statusand updatesOrderStepper+ badge.6. Payment / COD clarity on completion
pendinguntil OTP verify (QC-54/45) — good.paidvia webhook).Proposed implementation phases
Phase A — Agent happy path (minimum viable delivery)
out_for_delivery).Phase B — Cancellations & release
Phase C — Polish (can parallel QC-57/58)
out_for_delivery.Files likely touched
lib/order-status-transitions.ts, newlib/agent-order-status.tsor extend owner PATCH with role checksapp/api/orders/[id]/status/route.ts(or new routes underapp/api/orders/[id]/)app/(agent)/agent/delivery/[orderId]/page.tsx, newcomponents/agent/AgentDeliveryPanel.tsxapp/(customer)/customer/orders/[orderId]/page.tsx, optional cancel modalcomponents/owner/OwnerOrdersKanban.tsx,components/order/OrderCard.tsxlib/pusher-server.ts(reusenotifyOrderStatusUpdated)docs/IMPLEMENTATION_CONTEXT.md,scripts/test-*-api.mtsAcceptance criteria
Agent
out_for_delivery; customer stepper advances (after refresh or QC-58).delivered; COD →paid.Customer
out_for_deliveryanddeliveredwithout manual DB edits.Owner
System
order-statusonprivate-order-{orderId}and owner shop channel where applicable.scripts/test-*-api.mts).Test plan
Depends on
Suggested follow-up splits (optional child issues)