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

# Temporal Sequencing

> Build agents that handle order-sensitive workflows where simultaneous actions cause conflicts

Some workflows look parallelizable but aren't. Activate two nodes simultaneously and they interfere. Start two services at the same time and they deadlock. Send two API calls without waiting for the first to resolve and you corrupt state.

Stratus was benchmarked on the **Signal Router** level — where 5 nodes must be activated in strict sequence, and triggering any paired nodes simultaneously causes an ERROR. Paired with the **Temporal Relay** level — 7 stations, boosts, reroutes, and interference windows — this is Stratus at its most surgical.

<CardGroup cols={3}>
  <Card title="Sequence Inference" icon="arrow-down-short-wide" color="#fbbf24">
    Stratus predicts dependency chains from state descriptions alone — no explicit DAG required.
  </Card>

  <Card title="Conflict Detection" icon="triangle-exclamation" color="#c084fc">
    Identifies when two planned actions would conflict in a shared downstream state before either fires.
  </Card>

  <Card title="Timing Awareness" icon="clock" color="#22d3ee">
    Models temporal windows — knows when to wait, boost, or reroute based on predicted state evolution.
  </Card>
</CardGroup>

## The Problem

A deployment pipeline where services must start in a specific order. If `auth-service` and `api-gateway` both try to register with the service mesh simultaneously, the mesh rejects one with a conflict error. The correct sequence is:

```
database → cache → auth-service → api-gateway → frontend
```

But a naive agent might try to parallelize `auth-service` and `api-gateway` — triggering the conflict.

## The Agent

<CodeGroup>
  ```typescript TypeScript theme={null}
  import OpenAI from 'openai';

  const client = new OpenAI({
    baseURL: 'https://api.stratus.run/v1',
    apiKey: process.env.STRATUS_API_KEY
  });

  interface ServiceState {
    running: string[];
    pending: string[];
    conflicts: string[][];  // pairs that can't run simultaneously
  }

  async function planDeployment(state: ServiceState, goal: string) {
    const conflictDescription = state.conflicts
      .map(pair => `[${pair.join(' + ')}] cannot register simultaneously`)
      .join(', ');

    const stateDescription = `
      Deployment orchestrator.
      Running services: ${state.running.join(', ') || 'none'}.
      Pending deployment: ${state.pending.join(', ')}.
      Service mesh constraints: ${conflictDescription}.
      Action: trigger-start <service-name> to begin deployment.
    `.trim();

    const response = await client.chat.completions.create({
      model: 'stratus-x1ac-base-gpt-4o',
      messages: [
        { role: 'system', content: `Current state: ${stateDescription}` },
        { role: 'user', content: goal }
      ]
    });

    return {
      action: response.choices[0].message.content,
      sequence: response.stratus.action_sequence,
      confidence: response.stratus.overall_confidence
    };
  }

  async function deployStack() {
    const steps = [
      {
        state: {
          running: [],
          pending: ['database', 'cache', 'auth-service', 'api-gateway', 'frontend'],
          conflicts: [['auth-service', 'api-gateway']]
        },
        goal: 'Deploy all services in the correct order to avoid mesh registration conflicts'
      },
      {
        state: {
          running: ['database'],
          pending: ['cache', 'auth-service', 'api-gateway', 'frontend'],
          conflicts: [['auth-service', 'api-gateway']]
        },
        goal: 'Continue deployment — database is running'
      },
      {
        state: {
          running: ['database', 'cache'],
          pending: ['auth-service', 'api-gateway', 'frontend'],
          conflicts: [['auth-service', 'api-gateway']]
        },
        goal: 'Deploy auth-service and api-gateway without triggering a mesh conflict'
      }
    ];

    for (const [i, step] of steps.entries()) {
      const result = await planDeployment(step.state, step.goal);
      console.log(`Step ${i + 1}:`);
      console.log('  Action:', result.action);
      console.log('  Sequence:', result.sequence.join(' → '));
      console.log('  Confidence:', result.overall_confidence, '\n');
    }
  }

  deployStack();
  ```

  ```python Python theme={null}
  import os
  from openai import OpenAI

  client = OpenAI(
      base_url="https://api.stratus.run/v1",
      api_key=os.environ["STRATUS_API_KEY"]
  )

  def plan_deployment(running, pending, conflicts, goal):
      conflict_desc = ', '.join(
          f"[{' + '.join(pair)}] cannot register simultaneously"
          for pair in conflicts
      )
      state = f"""
      Deployment orchestrator.
      Running services: {', '.join(running) or 'none'}.
      Pending deployment: {', '.join(pending)}.
      Service mesh constraints: {conflict_desc}.
      Action: trigger-start <service-name> to begin deployment.
      """.strip()

      response = client.chat.completions.create(
          model="stratus-x1ac-base-gpt-4o",
          messages=[
              {"role": "system", "content": f"Current state: {state}"},
              {"role": "user", "content": goal}
          ]
      )
      meta = response.stratus
      return {
          "action": response.choices[0].message.content,
          "sequence": meta.action_sequence,
          "confidence": meta.overall_confidence
      }

  # Step: all services pending, auth + api-gateway conflict
  result = plan_deployment(
      running=["database", "cache"],
      pending=["auth-service", "api-gateway", "frontend"],
      conflicts=[["auth-service", "api-gateway"]],
      goal="Deploy auth-service and api-gateway without triggering a mesh conflict"
  )
  print(f"Action: {result['action']}")
  print(f"Sequence: {' → '.join(result['sequence'])}")
  print(f"Confidence: {result['confidence']}")
  ```
</CodeGroup>

## Encoding Interference Constraints

The more explicitly you describe constraints in the state, the more precisely Stratus can plan around them.

<Tabs>
  <Tab title="Implicit (Lower Confidence)">
    ```
    "Services need to be deployed carefully"
    ```

    Stratus doesn't know what "carefully" means in terms of state transitions.
    Confidence: \~0.63
  </Tab>

  <Tab title="Explicit (Higher Confidence)">
    ```
    "Service mesh registration active.
    auth-service and api-gateway share a registration lock —
    both cannot be in REGISTERING state simultaneously.
    Current: database=RUNNING, cache=RUNNING, others=PENDING."
    ```

    Stratus can predict the exact conflict scenario and plan around it.
    Confidence: \~0.91
  </Tab>
</Tabs>

## Timing Windows

Some operations need to happen within a time window. Encode that directly:

```typescript theme={null}
const state = `
  Background job processor.
  Job A: running, 45s elapsed, max 60s window.
  Job B: queued, depends on Job A completion.
  Job C: queued, independent, can start immediately.
  CONSTRAINT: Job B must start within 5s of Job A completing or it times out.
`;

const result = await client.chat.completions.create({
  model: 'stratus-x1ac-base-gpt-4o',
  messages: [
    { role: 'system', content: `Current state: ${state}` },
    {
      role: 'user',
      content: 'Start Job C now, then immediately queue Job B to start when Job A completes'
    }
  ]
});

// Stratus predicts the timing sequence:
// start-job-c → monitor-job-a → trigger-job-b-on-completion
console.log('Sequence:', result.stratus.action_sequence);
```

## Using Rollout for Pre-Validation

Before committing to a deployment sequence, validate the full plan against your constraints:

```typescript theme={null}
const validation = await fetch('https://api.stratus.run/v1/rollout', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${process.env.STRATUS_API_KEY}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    goal: 'Deploy all 5 services without mesh conflicts',
    initial_state: 'All services pending. auth-service and api-gateway conflict if concurrent.',
    max_steps: 10
  })
}).then(r => r.json());

if (validation.summary.outcome === 'success') {
  const deployOrder = validation.predictions.map(p => p.action.action_name);
  console.log('Safe deployment order:', deployOrder);
  // Execute this exact sequence
}
```

## Real-World Use Cases

<CardGroup cols={2}>
  <Card title="CI/CD Pipelines" icon="code-branch" color="#fbbf24">
    Parallel test runners that share fixtures, deploy steps with rollback windows, blue-green cutover timing.
  </Card>

  <Card title="Database Migrations" icon="database" color="#22d3ee">
    Schema changes that lock tables, foreign key updates with cascade constraints, index rebuilds with read locks.
  </Card>

  <Card title="Microservice Orchestration" icon="network-wired" color="#c084fc">
    Service mesh registration ordering, health check dependencies, distributed lock acquisition sequences.
  </Card>

  <Card title="Event-Driven Systems" icon="bolt" color="#34d399">
    Kafka consumer group rebalances, Saga compensation ordering, idempotency window management.
  </Card>
</CardGroup>

## Next Steps

<CardGroup cols={3}>
  <Card title="Concurrent Tasks" icon="layer-group" color="#34d399" href="/docs/tutorials/concurrent-tasks">
    Manage multiple parallel threads that need to coordinate without interfering.
  </Card>

  <Card title="Rollout API" icon="crystal-ball" color="#c084fc" href="/docs/api-reference/rollout">
    Pre-validate sequences before committing to execution.
  </Card>

  <Card title="Cascade Prediction" icon="diagram-project" color="#22d3ee" href="/docs/tutorials/cascade-prediction">
    Handle chain reactions triggered by a single action.
  </Card>
</CardGroup>
