Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -1019,9 +1019,9 @@ Tests mirror the boundaries, so a failure points at a boundary.
| Integration | Event ingestion → DB, ingestion → enqueue, worker retry/failure, approval + policy enforcement, execution + verification, audit writes, metrics, one incident one trace | Real Postgres + Redis (compose) |
| E2E (Playwright) | Full operator journey, plus the negative cases visible in the UI | Fixture model, seeded scenario, the built compose stack |

Determinism rules: a fixed seed produces an identical scenario (40 labs, 19
failures, one redelivery)
every run; the LLM is mocked in all CI tests with one opt-in job against a real
Determinism rules: a fixed seed produces an identical scenario (the training
event: 40 labs, 19 failures, one redelivery; shared outages: 15 labs, 13
failures) every run; the LLM is mocked in all CI tests with one opt-in job against a real
model; no test asserts on wall-clock timings or generated prose.

The negative suite is as important as the happy path: unrelated-but-similar
Expand Down
30 changes: 27 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@ LabOps Copilot shows one way to handle that, in eight steps:

## Try it

Sign in to the [live demo](https://labops.onrender.com). It already holds one
scenario: 40 simulated labs, of which 12 failed together because of one shared
image registry, plus a few unrelated failures.
Sign in to the [live demo](https://labops.onrender.com). It already holds 55
simulated labs from two scenarios: 12 labs that failed together because of one
shared image registry, two smaller outages, and failures that only look
related. The steps below follow the 12; [every path](#every-path-one-incident-each)
lists what each of the other incidents shows.

1. **Overview.** Counts, a failure timeline and labs by state. The burst of 12
is the tall bar. Light and [dark](docs/images/dashboard-dark.png) themes
Expand Down Expand Up @@ -79,6 +81,28 @@ image registry, plus a few unrelated failures.

7. **Audit.** Every step, with who or what did it and when.

### Every path, one incident each

Each incident on the demo takes a different route through the safety rules.
Open it from **Incidents** and do what the middle column says.

| Incident | Do this | What you should see |
|---|---|---|
| **PROVISION_TIMEOUT on image-registry** (12 labs) | Investigate, then Approve | The fix passes the rules and waits for you, with a 30-minute countdown. Approved, it runs, every lab is checked, and the incident closes. |
| the same, instead | Investigate, then Reject, or leave it 30 minutes | Nothing runs. A rejection reopens the incident; an expired approval sends it to a person. Either way, Investigate again for a fresh suggestion. |
| **PERMISSION_DENIED** (any of 4) | Investigate | The AI gets it wrong and suggests a retry. The rules refuse it: a retry cannot fix missing permissions. |
| **NETWORK_CONFIG** (any of 3) | Investigate | One failure on its own is not enough to go on, so the AI suggests nothing. |
| **DEPENDENCY_UNAVAILABLE on license-server** (6 labs) | Investigate, then Approve | The AI suggests re-checking the license server. You approve, it runs, and the check still fails: checking a server does not fix the labs. The incident stays open for a person. |
| the same, straight after | Investigate again | The same check is refused: it ran less than 5 minutes ago. |
| **QUOTA_EXCEEDED on subscription-quota** (5 labs) | Investigate | No safe automatic fix exists, so the AI hands it to a person. Nothing is offered for approval. |
| **PROVISION_TIMEOUT on artifact-cache** (two incidents) | Open both | Same error, same cache, but 25 minutes apart, so they are kept separate. One says how close it came to joining the other. |

Some failures cannot be triggered from the demo, because its AI stand-in
always answers correctly formed: a model that times out or returns garbage, one
that names a lab outside the incident, text in a log trying to give the AI
orders, two people approving at once. Each has an automated test; the
[acceptance map](docs/specs/labops-copilot/ACCEPTANCE.md) names them.

---

## How it keeps AI safe
Expand Down
112 changes: 96 additions & 16 deletions apps/api/src/modules/labs/simulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,20 @@ function shuffle<T>(items: readonly T[], random: () => number): T[] {
const MINUTE = 60_000;
const LAB_TYPES = ['azure-vm', 'aws-ec2', 'k8s-workshop'] as const;

type Failure = Pick<SimulatedEvent, 'errorCategory' | 'dependencyId' | 'message'>;

/** A lab's one provisioning outcome; its id is stable, so a redelivery reuses it. */
function provisionEvent(lab: SimulatedLab, occurredAt: string, failure?: Failure): SimulatedEvent {
return {
providerEventId: `${lab.id}-provision`,
labId: lab.id,
type: failure ? 'provision_failed' : 'provision_succeeded',
...(failure ?? { message: 'Provisioning completed' }),
occurredAt,
source: 'simulated',
};
}

// A training event: 40 labs; one shared dependency degrades and times out a
// burst of 12, while permission and network failures are scattered and
// unrelated. They must not merge with the burst, which is what makes it a test.
Expand Down Expand Up @@ -88,39 +102,27 @@ export function createTrainingEvent(seed: number, epoch: Date): Scenario {
const networkConfig = order.slice(16, 19);
const succeeded = order.slice(19);

const event = (
lab: SimulatedLab,
occurredAt: string,
failure?: Pick<SimulatedEvent, 'errorCategory' | 'dependencyId' | 'message'>,
): SimulatedEvent => ({
providerEventId: `${lab.id}-provision`,
labId: lab.id,
type: failure ? 'provision_failed' : 'provision_succeeded',
...(failure ?? { message: 'Provisioning completed' }),
occurredAt,
source: 'simulated',
});

const events: SimulatedEvent[] = [
...succeeded.map((lab) => event(lab, at(between(0, 30 * MINUTE)))),
...succeeded.map((lab) => provisionEvent(lab, at(between(0, 30 * MINUTE)))),
// The burst: one degraded dependency, all within a five-minute window.
...timeouts.map((lab) =>
event(lab, at(between(10 * MINUTE, 15 * MINUTE)), {
provisionEvent(lab, at(between(10 * MINUTE, 15 * MINUTE)), {
errorCategory: 'PROVISION_TIMEOUT',
dependencyId: registry.id,
message: 'VM provisioning timed out pulling the base image',
}),
),
// Unrelated: a per-lab role assignment problem, hours apart.
...permissionDenied.map((lab, i) =>
event(lab, at((60 + i * 90) * MINUTE + between(0, 10 * MINUTE)), {
provisionEvent(lab, at((60 + i * 90) * MINUTE + between(0, 10 * MINUTE)), {
errorCategory: 'PERMISSION_DENIED',
message: 'Deployment identity lacks the Contributor role',
}),
),
// Unrelated: per-lab subnet misconfiguration, also spread out.
...networkConfig.map((lab, i) =>
event(lab, at((45 + i * 120) * MINUTE + between(0, 10 * MINUTE)), {
provisionEvent(lab, at((45 + i * 120) * MINUTE + between(0, 10 * MINUTE)), {
errorCategory: 'NETWORK_CONFIG',
message: 'Subnet address range overlaps an existing range',
}),
Expand All @@ -146,11 +148,89 @@ export function createTrainingEvent(seed: number, epoch: Date): Scenario {
};
}

// Shared outages: 15 labs on three dependencies, for the paths the training
// event never takes. A license server outage (a dependency recheck, which
// fixes nothing, so verification fails), a quota exhausted (no automated fix:
// the model escalates to a human), and two timeouts on one cache 25 minutes
// apart: alike, but too far apart in time to merge.
export function createSharedOutages(seed: number, epoch: Date): Scenario {
const random = createPrng(seed);
const at = (offsetMs: number) => new Date(epoch.getTime() + offsetMs).toISOString();
const between = (min: number, max: number) => min + Math.floor(random() * (max - min));
const prefix = `sim-shared-outages-${seed}`;

const license = { id: `${prefix}-dep-license-server`, kind: 'license-server' };
const quota = { id: `${prefix}-dep-subscription-quota`, kind: 'subscription-quota' };
const cache = { id: `${prefix}-dep-artifact-cache`, kind: 'artifact-cache' };

const labs: SimulatedLab[] = Array.from({ length: 15 }, (_, i) => {
const n = String(i + 1).padStart(2, '0');
return {
id: `${prefix}-lab-${n}`,
name: `Workshop Lab ${n}`,
labType: LAB_TYPES[Math.floor(random() * LAB_TYPES.length)],
dependencyIds: [license.id, quota.id, cache.id],
};
});

const order = shuffle(labs, random);
const unavailable = order.slice(0, 6);
const quotaExceeded = order.slice(6, 11);
const [cacheFirst, cacheSecond] = order.slice(11, 13);
const succeeded = order.slice(13);

const cacheTimeout = {
errorCategory: 'PROVISION_TIMEOUT',
dependencyId: cache.id,
message: 'Provisioning timed out fetching lab artifacts',
} as const;

const events: SimulatedEvent[] = [
...succeeded.map((lab) => provisionEvent(lab, at(between(0, 30 * MINUTE)))),
...unavailable.map((lab) =>
provisionEvent(lab, at(between(10 * MINUTE, 15 * MINUTE)), {
errorCategory: 'DEPENDENCY_UNAVAILABLE',
dependencyId: license.id,
message: 'License server did not respond during software activation',
}),
),
...quotaExceeded.map((lab) =>
provisionEvent(lab, at(between(60 * MINUTE, 65 * MINUTE)), {
errorCategory: 'QUOTA_EXCEEDED',
dependencyId: quota.id,
message: 'Subscription vCPU quota exhausted for the region',
}),
),
// Past the 15-minute nearby limit, so time scores 0 and the pair stays
// below the join threshold: the near miss operators can inspect.
provisionEvent(cacheFirst, at(120 * MINUTE), cacheTimeout),
provisionEvent(cacheSecond, at(145 * MINUTE), cacheTimeout),
];

events.sort(
(a, b) =>
a.occurredAt.localeCompare(b.occurredAt) ||
a.providerEventId.localeCompare(b.providerEventId),
);

return {
name: 'shared-outages',
seed,
labs,
dependencies: [license, quota, cache],
events,
};
}

/** Fixed epoch so timestamps are reproducible; not tied to the current date. */
export const TRAINING_EVENT_EPOCH = new Date('2026-01-15T09:00:00.000Z');
// Later the same day: after the training event's last failure, on its own
// dependencies, so nothing from the two scenarios can correlate.
export const SHARED_OUTAGES_EPOCH = new Date('2026-01-15T15:00:00.000Z');

export const SCENARIOS = {
'training-event': (seed: number) => createTrainingEvent(seed, TRAINING_EVENT_EPOCH),
'shared-outages': (seed: number) => createSharedOutages(seed, SHARED_OUTAGES_EPOCH),
} as const;

export type ScenarioName = keyof typeof SCENARIOS;
12 changes: 8 additions & 4 deletions apps/api/src/seed-demo.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
// One-shot entrypoint: ingests the demo scenario, for a host where the demo
// One-shot entrypoint: ingests the demo scenarios, for a host where the demo
// routes are off (APP_ENV=production) and nothing else creates data. Safe to
// run on every boot: a replay is recognised by its dedup keys and adds nothing.

import { prisma } from './db.js';
import { runScenario } from './modules/demo/service.js';
import type { ScenarioName } from './modules/labs/simulator.js';
import { closeQueues } from './platform/jobs/queues.js';
import { logger } from './platform/observability/logger.js';

const SCENARIO = 'training-event';
// Between them, every path a reviewer can click through (docs/dev/DESIGN.md).
const SCENARIOS: ScenarioName[] = ['training-event', 'shared-outages'];
const SEED = 42;

async function main() {
const run = await runScenario(SCENARIO, SEED);
logger.info({ simulated: true, ...run }, 'demo scenario seeded');
for (const scenario of SCENARIOS) {
const run = await runScenario(scenario, SEED);
logger.info({ simulated: true, ...run }, 'demo scenario seeded');
}
}

main()
Expand Down
26 changes: 26 additions & 0 deletions apps/api/test/integration/modules/demo/routes.int.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,32 @@ describe('POST /api/demo/scenarios/:name', () => {
expect(audit[0].outcome).toBe('already_present');
});

it('runs the shared-outages scenario too', async () => {
const prefix = `sim-shared-outages-${SEED}-`;
try {
const response = await enabled.inject({
method: 'POST',
url: '/api/demo/scenarios/shared-outages',
payload: { seed: SEED },
});

expect(response.statusCode).toBe(201);
expect(response.json().data).toMatchObject({
scenarioRunId: `shared-outages:${SEED}`,
source: 'simulated',
labs: 15,
dependencies: 3,
eventsIngested: 15,
duplicatesSkipped: 0,
});
const labs = await prisma.lab.findMany({ where: { id: { startsWith: prefix } } });
expect(labs.filter((lab) => lab.status === 'failed')).toHaveLength(13);
} finally {
await prisma.lab.deleteMany({ where: { id: { startsWith: prefix } } });
await prisma.dependency.deleteMany({ where: { id: { startsWith: prefix } } });
}
});

it.each([
['an unknown scenario', '/api/demo/scenarios/apocalypse', { seed: SEED }],
['a negative seed', URL, { seed: -1 }],
Expand Down
Loading
Loading