> ## Documentation Index
> Fetch the complete documentation index at: https://docs.thread.app/llms.txt
> Use this file to discover all available pages before exploring further.

# Action Execution

> Understand how Thread's automation engine triggers, generates, and executes actions

## Action Execution Overview

Thread's automation engine orchestrates the entire action lifecycle—from triggering to draft generation to customer delivery. Understanding this system helps you leverage automation effectively.

***

## The Action Lifecycle

```
Milestone Starts
    ↓
Trigger Evaluates
    ↓
AI Generates Draft (if applicable)
    ↓
Action Status: "Ready"
    ↓
CSM Reviews & Edits
    ↓
CSM Executes
    ↓
Customer Receives
    ↓
Customer Responds
    ↓
Action Status: "Completed"
```

***

## Trigger Types

### milestone\_start (Most Common)

**When it fires:** When the parent milestone's status changes to "in\_progress"

**Configuration:**

```typescript theme={null}
{
  trigger: {
    type: "milestone_start",
    delay_hours: 0  // or 24, 48, 72, etc.
  }
}
```

**Examples:**

<Tabs>
  <Tab title="Immediate (0 hours)">
    **Use for:** Welcome emails, milestone announcements

    ```
    Kickoff milestone starts → Welcome email triggers immediately
    ```

    **Action appears** in CSM review queue within minutes.
  </Tab>

  <Tab title="24 Hours">
    **Use for:** Follow-ups, reminders, secondary actions

    ```
    Kickoff milestone starts → Wait 24 hours → Follow-up email triggers
    ```

    **Action appears** in CSM review queue 24 hours after milestone start.
  </Tab>

  <Tab title="48-72 Hours">
    **Use for:** Non-urgent requests, giving customers breathing room

    ```
    Setup milestone starts → Wait 48 hours → Technical form triggers
    ```

    **Action appears** in CSM review queue 2-3 days later.
  </Tab>

  <Tab title="Week+">
    **Use for:** Long-term milestones, post-launch follow-ups

    ```
    Launch milestone starts → Wait 30 days → Success review triggers
    ```

    **Action appears** in CSM review queue 30 days later.
  </Tab>
</Tabs>

<Info>
  Delays are calculated from when the milestone **starts**, not when it's created. If you create a milestone but don't start it, triggers won't fire.
</Info>

### Manual

**When it fires:** Never automatically—CSM must manually trigger

**Configuration:**

```typescript theme={null}
{
  trigger: {
    type: "manual"
  }
}
```

**Use cases:**

* Meetings (CSM schedules when ready)
* Complex tasks requiring preparation
* Conditional actions (only for some customers)
* Executive business reviews

**How CSMs trigger:**

1. Navigate to Implementation Tab
2. Find manual action
3. Click "Generate Draft" or "Execute"
4. Action processes like auto-triggered actions

***

## Action Trigger Processing

### How Thread Processes Triggers

<Steps>
  <Step title="Milestone Status Change">
    CSM starts a milestone → status changes to "in\_progress"
  </Step>

  <Step title="Scan for Triggers">
    Thread scans all actions in this milestone for `milestone_start` triggers
  </Step>

  <Step title="Immediate Triggers Fire">
    Actions with `delay_hours: 0` immediately added to execution queue
  </Step>

  <Step title="Scheduled Triggers Queued">
    Actions with delays added to `scheduled_action_executions` table with target execution time
  </Step>

  <Step title="Cron Job Processes Schedule">
    Hourly cron job checks for actions whose execution time has arrived
  </Step>

  <Step title="Drafts Generated">
    For each triggered action, AI generates draft content (if applicable)
  </Step>

  <Step title="Ready for Review">
    Actions appear in CSM Implementation Tab with status "ready"
  </Step>
</Steps>

***

## Action Generation

### Which Actions Get AI Generation?

<CardGroup cols={2}>
  <Card title="AI-Generated" icon="robot">
    * Send Email (subject + body)
    * Collect Info (intro text)
    * Slack Message (message content)
  </Card>

  <Card title="Template-Based" icon="file-text">
    * Request Docs (uses configured template)
    * Schedule Meeting (uses configured agenda)
    * Collect Info fields (pre-configured)
  </Card>
</CardGroup>

### Generation Context

AI uses this context to generate drafts:

<AccordionGroup>
  <Accordion title="Account Data">
    * Company name
    * ARR
    * Close date
    * Primary contact info
    * Industry and size
    * Account notes
  </Accordion>

  <Accordion title="Template Context">
    * Milestone name and description
    * Action label and purpose
    * Content template/structure
    * Variables to interpolate
  </Accordion>

  <Accordion title="Handoff Intelligence">
    * Primary use case
    * Customer goals
    * Known risks/challenges
    * Stakeholders
    * Technical environment
  </Accordion>

  <Accordion title="Previous Actions">
    * What's been sent already
    * Customer responses
    * Timeline and progress
    * Established tone/style
  </Accordion>
</AccordionGroup>

### Generation Quality

**High quality when:**

* ✅ Rich account data available
* ✅ Detailed handoff Q\&A
* ✅ Clear action purpose in template
* ✅ Good content template with examples

**Lower quality when:**

* ❌ Minimal account data
* ❌ Skipped or sparse handoff
* ❌ Vague action purpose
* ❌ Generic content template

<Tip>
  The more context you provide (account notes, handoff answers, template details), the better the AI-generated drafts will be!
</Tip>

***

## Action Execution

### What Happens When CSM Clicks "Execute"

<Tabs>
  <Tab title="Send Email">
    1. Variable interpolation (`{{company_name}}` → "Acme Corp")
    2. Email sent via email service (Resend)
    3. From address: CSM email or org default
    4. Recipients: To/CC/BCC as configured
    5. Action status → "executed"
    6. Email logged in action history
  </Tab>

  <Tab title="Request Docs">
    1. Document upload interface created in customer portal
    2. Document types listed with instructions
    3. Customer portal updated with new action
    4. Customer notification (optional)
    5. Action status → "executed"
    6. Awaiting customer upload
  </Tab>

  <Tab title="Collect Info">
    1. Form created in customer portal
    2. All fields configured as specified
    3. Intro text and instructions displayed
    4. Customer portal updated
    5. Action status → "executed"
    6. Awaiting form submission
  </Tab>

  <Tab title="Schedule Meeting">
    1. Meeting details saved
    2. Calendar link activated (if configured)
    3. Customer can book time
    4. Action status → "executed"
    5. CSM marks complete after call
  </Tab>

  <Tab title="Slack Message">
    1. Message posted to configured channel
    2. Formatting applied (bold, links, etc.)
    3. Message delivered to Slack
    4. Action status → "executed"
    5. CSM or auto-marked complete
  </Tab>
</Tabs>

### Execution is Irreversible

<Warning>
  Once you click "Execute", the action is sent/created immediately. There's no "undo" button!
</Warning>

**What you CAN'T undo:**

* Emails already sent
* Forms/docs already in customer portal
* Slack messages already posted
* Meetings already scheduled

**What you CAN do after execution:**

* Send a follow-up email correcting mistakes
* Create a new form/doc request
* Post a follow-up Slack message
* Reschedule meetings

***

## Action Completion

### Auto-Completing Actions

These actions complete automatically when customer responds:

<Tabs>
  <Tab title="Request Docs">
    **Completes when:** All required documents uploaded

    **Process:**

    1. Customer uploads file in portal
    2. Thread validates file (type, size)
    3. If all required docs uploaded → status: "completed"
    4. CSM receives notification
    5. CSM can download and review docs
  </Tab>

  <Tab title="Collect Info">
    **Completes when:** Customer submits form

    **Process:**

    1. Customer fills out form fields
    2. Clicks "Submit"
    3. Validation runs (required fields, formats)
    4. If valid → status: "completed"
    5. CSM receives notification with submission
    6. CSM can view responses
  </Tab>
</Tabs>

### Manual-Completing Actions

These require CSM to mark complete:

<Tabs>
  <Tab title="Send Email">
    **Mark complete when:**

    * Customer replies (task done)
    * Reasonable time passed (move on)
    * Followed up via other channel

    **How:**

    1. Click action in Implementation Tab
    2. Click "Mark as Complete"
    3. Add completion note (optional)
    4. Confirm
  </Tab>

  <Tab title="Schedule Meeting">
    **Mark complete when:**

    * Meeting held
    * Rescheduled and new one scheduled
    * No longer needed

    **How:**

    1. After call ends, mark complete
    2. Add meeting notes to action
    3. Document outcomes and next steps
  </Tab>

  <Tab title="Slack Message">
    **Mark complete when:**

    * Message delivered
    * Customer acknowledged
    * Thread has replies

    **How:**

    * Usually mark complete immediately after posting
    * Or wait for customer response if expecting one
  </Tab>
</Tabs>

***

## Monitoring Action Execution

### Action Status Dashboard

**Key metrics:**

* **Ready count:** Actions needing CSM review
* **Executed count:** Actions sent, awaiting customer response
* **Overdue count:** Actions past expected completion
* **Blocked count:** Actions stuck on issues

### Execution Timeline

Each account shows execution timeline:

```
Day 1:  Kickoff starts → 3 actions triggered
Day 2:  2 actions executed, 1 pending customer response
Day 3:  Follow-up triggered → 1 action ready for review
Day 5:  Technical form triggered → ready for review
...
```

***

## Troubleshooting Execution

### "Action Didn't Trigger"

**Problem:** Milestone started but action didn't appear

**Possible causes:**

1. Action has delay—check scheduled executions
2. Trigger type is "manual"—CSM must trigger
3. System error—check logs or contact support

**Solutions:**

* Check `scheduled_action_executions` for delayed actions
* Manually trigger if needed
* Regenerate draft if missing

### "Draft Generation Failed"

**Problem:** Action triggered but no draft content

**Possible causes:**

1. OpenAI API error (temporary)
2. Insufficient context data
3. Invalid template configuration

**Solutions:**

* Click "Regenerate" to retry
* Add more account context
* Manually write content if urgent

### "Customer Didn't Receive Action"

**Problem:** Email sent or form created, but customer can't see it

**Possible causes:**

1. Email in spam folder
2. Portal not accessible
3. Wrong email address
4. Portal action not visible

**Solutions:**

* Ask customer to check spam
* Verify portal link working
* Check email address in account
* Verify action portal visibility setting

***

## Best Practices

<CardGroup cols={2}>
  <Card title="Use Delays Strategically" icon="clock">
    Space actions 24-72 hours apart to avoid overwhelming customers
  </Card>

  <Card title="Monitor Ready Queue" icon="eye">
    Check "ready" actions daily—don't let them pile up
  </Card>

  <Card title="Execute Promptly" icon="bolt">
    Review and execute within 24 hours of becoming ready
  </Card>

  <Card title="Mark Complete Quickly" icon="check">
    Don't leave executed actions lingering—mark done when done
  </Card>

  <Card title="Track Patterns" icon="chart-line">
    Note which actions frequently need editing or get skipped
  </Card>

  <Card title="Provide Feedback" icon="comment">
    Tell template owners what's working and what's not
  </Card>
</CardGroup>

***

## Next Steps

<CardGroup cols={2}>
  <Card title="Scheduled Actions" icon="calendar" href="/csm-guide/automation/scheduled-actions">
    Deep dive into delayed action execution
  </Card>

  <Card title="AI Generation" icon="robot" href="/csm-guide/automation/ai-generation">
    Learn how AI creates action drafts
  </Card>

  <Card title="Implementation Tab" icon="tasks" href="/csm-guide/accounts/implementation-tab">
    Master the CSM workspace for action review
  </Card>

  <Card title="Action Types" icon="bolt" href="/csm-guide/templates/action-types">
    Complete reference for all action types
  </Card>
</CardGroup>
