Checkpoint recovered orchestration core with tested fail-closed boundaries

This commit is contained in:
devops committed 2026-10-23 08:01:08 +00:00
1 parent c7f1d25e98
commit 0952a482fb
18 files changed
+1918 -129

No files matched your search

@@ -1,9 +1,36 @@
import { ForbiddenException, Injectable } from "@nestjs/common";
import { PrismaService } from "../prisma/prisma.service";
import { KillSwitchLevel } from "./orchestration.domain";
export type GuardedAction="CREATE_TASK"|"RUN_AGENT"|"MUTATE_PRODUCTION"|"OBSERVE";
import { ForbiddenException, Injectable } from '@nestjs/common';
import { PrismaService } from '../prisma/prisma.service';
import { KillSwitchLevel } from './orchestration.domain';
export type GuardedAction =
| 'CREATE_TASK'
| 'CLAIM_TASK'
| 'RUN_AGENT'
| 'MUTATE_PRODUCTION'
| 'OBSERVE';
@Injectable()
export class KillSwitchService {
constructor(private readonly prisma:PrismaService){}
async assertAllowed(action:GuardedAction):Promise<void>{ const state=await (this.prisma as any).orchestrationKillSwitch.findUnique({where:{scope:"GLOBAL"}}); if(!state?.active)return; const blocked:Record<KillSwitchLevel,GuardedAction[]>={FREEZE_NEW_WORK:["CREATE_TASK"],STOP_AGENTS:["CREATE_TASK","RUN_AGENT"],DISABLE_MUTATIONS:["CREATE_TASK","RUN_AGENT","MUTATE_PRODUCTION"],EMERGENCY_HALT:["CREATE_TASK","RUN_AGENT","MUTATE_PRODUCTION","OBSERVE"]}; if(blocked[state.level as KillSwitchLevel]?.includes(action)) throw new ForbiddenException(`Orchestration kill switch ${state.level} blocks ${action}`); }
constructor(private readonly prisma: PrismaService) {}
async assertAllowed(action: GuardedAction): Promise<void> {
const state = await (this.prisma as any).orchestrationKillSwitch.findUnique(
{ where: { scope: 'GLOBAL' } },
);
if (!state?.active) return;
const blocked: Record<KillSwitchLevel, GuardedAction[]> = {
FREEZE_NEW_WORK: ['CREATE_TASK', 'CLAIM_TASK'],
STOP_AGENTS: ['CREATE_TASK', 'CLAIM_TASK', 'RUN_AGENT'],
DISABLE_MUTATIONS: ['CREATE_TASK', 'CLAIM_TASK', 'RUN_AGENT', 'MUTATE_PRODUCTION'],
EMERGENCY_HALT: [
'CREATE_TASK',
'CLAIM_TASK',
'RUN_AGENT',
'MUTATE_PRODUCTION',
'OBSERVE',
],
};
if (!Object.values(KillSwitchLevel).includes(state.level) ||
blocked[state.level as KillSwitchLevel].includes(action))
throw new ForbiddenException(
`Orchestration kill switch ${state.level} blocks ${action}`,
);
}
}