Add bounded Stage PREPARE workflow with transactional leased outbox

This commit is contained in:
devops committed 2026-10-23 12:53:06 +00:00
1 parent 4b17a6fcc3
commit 09e8a890e0
9 files changed
+1150 -17

No files matched your search

@@ -1,5 +1,9 @@
import {
Controller,
Body,
Req,
Optional,
ValidationPipe,
Get,
Param,
Post,
@@ -13,6 +17,20 @@ import { JwtAuthGuard } from '../auth/jwt-auth.guard';
import { RolesGuard } from '../common/guards/roles.guard';
import { Roles } from '../common/decorators/roles.decorator';
import { OrchestrationService } from './orchestration.service';
import {
PrepareWorkflowService,
WorkflowIdentity,
} from './prepare-workflow.service';
import {
CreateOrchestrationTaskDto,
TransitionTaskDto,
GateDecisionDto,
} from './dto/orchestration.dto';
const workflowValidation = new ValidationPipe({
transform: true,
whitelist: true,
forbidNonWhitelisted: true,
});
// Explicit response allowlists: never serialize arbitrary JSON, signatures, URIs or BigInt.
function pick(row: any, keys: string[]) {
@@ -73,12 +91,37 @@ function project(row: any) {
@Roles('Admin', 'SUPER_ADMIN')
@Controller('admin/orchestration')
export class OrchestrationController {
constructor(private readonly service: OrchestrationService) {}
@Get('tasks') async all() {
return (await this.service.findAll()).map(project);
constructor(
private readonly service: OrchestrationService,
@Optional() private readonly workflow?: PrepareWorkflowService,
) {}
private actor(req: any): WorkflowIdentity {
const id = req?.user?.id ?? req?.user?.sub;
if (
typeof id !== 'string' ||
!id ||
!['Admin', 'SUPER_ADMIN'].includes(req?.user?.role)
)
throw new ForbiddenException('Authenticated workflow identity required');
return { id, role: req.user.role };
}
@Get('tasks/:id') async one(@Param('id') id: string) {
return project(await this.service.findOne(id));
private safe(row: any, req: any) {
const view = project(row);
if (!this.workflow) return view;
const w = this.workflow.project(row, this.actor(req));
return {
...view,
metadata: w.metadata,
availableActions: w.availableActions,
};
}
@Get('tasks') async all(@Req() req: any) {
return (await this.service.findAll()).map((row: any) =>
this.safe(row, req),
);
}
@Get('tasks/:id') async one(@Param('id') id: string, @Req() req: any) {
return this.safe(await this.service.findOne(id), req);
}
@Get('overview') async overview() {
const tasks = await this.service.findAll();
@@ -87,8 +130,17 @@ export class OrchestrationController {
{ id: 'tasks', title: 'Persisted task inventory', count: tasks.length },
],
measuredAt: new Date().toISOString(),
capabilities: { mutations: false, chat: false, runtime: false },
reason: 'security_hardening_pending',
capabilities: {
mutations: !!this.workflow,
prepare: !!this.workflow,
release: false,
gate2Decisions: false,
chat: false,
runtime: false,
},
reason: this.workflow
? 'bounded_stage_prepare_only'
: 'security_hardening_pending',
};
}
@Get('releases') async releases() {
@@ -120,15 +172,40 @@ export class OrchestrationController {
'No persisted model policy read contract available',
);
}
// The committed legacy core is not safe to expose. No env switch or role may bypass this boundary.
@Post('tasks') create() {
return this.deny();
// Only the separate bounded PREPARE service is exposed; legacy commands remain denied.
@Post('tasks') async create(
@Body(workflowValidation) dto: CreateOrchestrationTaskDto,
@Req() req: any,
) {
if (!this.workflow) return this.deny();
return this.safe(await this.workflow.create(dto, this.actor(req)), req);
}
@Put('tasks/:id/transition') transition() {
return this.deny();
@Put('tasks/:id/transition') async transition(
@Param('id') id: string,
@Body(workflowValidation) dto: TransitionTaskDto,
@Req() req: any,
) {
if (!this.workflow) return this.deny();
return this.safe(
await this.workflow.transition(id, dto, this.actor(req)),
req,
);
}
@Post('tasks/:id/gates/:gate/decide') decide() {
return this.deny();
@Post('tasks/:id/gates/:gate/decide') async decide(
@Param('id') id: string,
@Param('gate') gate: string,
@Body() body: unknown,
@Req() req: any,
) {
if (!this.workflow || gate !== '1') return this.deny();
const dto = await workflowValidation.transform(body, {
type: 'body',
metatype: GateDecisionDto,
});
return this.safe(
await this.workflow.decide(id, 1, dto, this.actor(req)),
req,
);
}
@Post('tasks/:id/budget') budget() {
return this.deny();