# DEB-360: Data Source Agent: Adhoc Query Lifecycle - I

> **Jira:** [DEB-360](https://divami.atlassian.net/browse/DEB-360)  
> **Source Report:** [20260315.md](../../reports/jira/20260315.md)

- **Status:** Start
- **Assignee:** Rahul Mishra
- **Priority:** Medium
- **Created:** 2026-03-13T15:53:23.794+0530
- **Updated:** 2026-03-13T16:37:10.061+0530

**Description:**

Implementation of the datasource and DB data sync (GMail)

**Architecture Diagram:**

```mermaid
sequenceDiagram
    participant Sched as Refresh Scheduler
    participant DSA as Data Source Agent (Gmail)
    participant Gmail as Gmail API
    participant DB as Agent DB
    participant RT as RT Decision Agent

    Sched->>DSA: Trigger data sync (scheduled / manual)
    DSA->>DSA: Idempotency check
    DSA->>Gmail: Fetch new / changed messages<br/>(incremental pull with cursor)
    Gmail-->>DSA: Email data
    DSA->>DSA: Parse & chunk emails
    DSA->>DB: Upsert records & update vector indexes
    DB-->>DSA: Sync confirmed
    DSA-->>RT: Acknowledge sync complete
    RT-->>RT: Update Org Snapshot if needed
```
