sequenceDiagram
    %% The Catastrophe

    participant RA as Research Agent
    participant E as Episteme
    participant LO as Lead Orchestrator
    participant DA as Deploy Agent
    participant P as Production

    RA->>E: Store RFC finding
    Note right of E: RFC proposes ES256. Stored as PROPOSED.

    LO->>E: What's the JWT algorithm?
    Note right of E: ⚠️ No lifecycle filter. This is the bug.

    E-->>LO: ES256 (conf: 0.87)
    Note right of LO: ⚠️ Returns the proposal. Most recent wins.

    DA->>P: Deploy ES256 config
    Note right of P: ⚠️ Deployed with confidence. Tests passed.

    P->>P: 401 Unauthorized
    Note over P: ⚠️ Auth service expects RS256. Every token fails.


---

sequenceDiagram
    %% The Correct Path

    participant RA as Research Agent
    participant E as Episteme
    participant LO as Lead Orchestrator
    participant DA as Deploy Agent
    participant P as Production

    RA->>E: Store RFC finding
    Note right of E: Same RFC. Still stored as PROPOSED.

    LO->>E: What's the APPROVED algorithm?
    Note right of E: ✓ Lifecycle filter: approved only.

    E-->>LO: RS256 (conf: 0.92)
    Note right of LO: ✓ Returns the approved decision. Proposal excluded.

    DA->>P: Deploy RS256 config
    Note right of P: ✓ Deployed. Matches production expectation.

    P->>P: 200 OK
    Note over P: ✓ Auth works. No pager. Sleep continues.


---

sequenceDiagram
    %% The Correction Loop

    participant H as Human Supervisor
    participant E as Episteme
    participant G as Gardener

    H->>E: What did the agent query?
    Note right of E: SRE investigates the incident.

    E-->>H: Query audit trail
    Note right of H: ⚠️ Found it: no lifecycle filter used.

    H->>E: Mark assertion incorrect
    Note right of E: Correct the record.

    G->>E: Store negative constraint
    Note right of E: ✓ Future queries will see this constraint.


---

sequenceDiagram
    %% Persistent Learning

    participant H as Human Supervisor
    participant E as Episteme
    participant IA as Implementation Agent

    H->>E: Correct the agent
    Note right of E: Human stores: use axios, not requests.

    IA->>IA: New session begins
    Note over IA: 30 days later. Fresh context window.

    IA->>E: Pre-flight constraint check
    Note right of E: ✓ Before writing code, check constraints.

    E-->>IA: Constraint found: use axios
    Note right of IA: ✓ The correction from Day 1 persists.

    IA->>IA: Write correct code
    Note over IA: ✓ Agent uses axios. Constraint honored.


---

sequenceDiagram
    %% Time Travel Debugging

    participant H as Human Supervisor
    participant E as Episteme

    H->>E: Current state?
    Note right of E: Shows RS256 (post-fix). Useless for debugging.

    H->>E: What did we believe at 9pm?
    Note right of E: Time-travel query.

    E-->>H: ES256 (at 9pm)
    Note right of H: ⚠️ Found it. This was the state at incident time.

    E-->>H: Diff: RFC added at 2:30pm
    Note right of H: ✓ Clear timeline of what changed and when.
