Skip to content

feat(autonomy): add budget guard, compensation registry, agent-jobs D…#14

Open
cryptoxdog wants to merge 1 commit into
mainfrom
feat/l9-autonomy-upgrades
Open

feat(autonomy): add budget guard, compensation registry, agent-jobs D…#14
cryptoxdog wants to merge 1 commit into
mainfrom
feat/l9-autonomy-upgrades

Conversation

@cryptoxdog

Copy link
Copy Markdown
Collaborator

…DL, and per-module autonomy workflow

  • .github/workflows/autonomy-ops.yml — NEW workflow (does not touch existing ci.yml)
  • src/core/budget-guard.ts — AgentBudgetGuard aligned with existing TokenBudget policy
  • src/core/compensation.ts — CompensationRegistry saga/rollback for external mutations
  • src/core/schema-additions.sql — agent_jobs, budget_violations, compensation_log DDL (additive; does not modify existing Drizzle schema.ts)
  • adr/0005-autonomy-runtime-controls.md — Architecture decision record for this upgrade

Summary

Type of Change

  • Bug fix
  • Feature / enhancement
  • Refactor (no behavior change)
  • Documentation
  • CI / governance change
  • Breaking change (see rollback plan below)

Governance Checklist

  • Governance setup verified — ran setup_workspace_symlinks.sh, symlinks resolve (§2)
  • Symlinks validatedls -la .cursor/rules .cursor/skills .cursor/commands all resolve
  • All CI gates green — no required checks failing or bypassed
  • Anti-patterns checked — reviewed CANONICAL_LAW.md §7 — none violated
  • CODEOWNERS notified — blast-radius files trigger auto-request; confirmed reviewers assigned
  • Workspace wiring intact§8 wiring requirements satisfied
  • TRACEABILITY_MAP.yaml updated — if this PR resolves an open unknown, mark as RESOLVED
  • Kernel ref discipline — thin callers use @v1, never @main or bare SHA

Breaking Change

  • This is a breaking change

If checked, describe the impact and migration path:

Rollback Plan


Related Issues

Closes #

…DL, and per-module autonomy workflow

- .github/workflows/autonomy-ops.yml — NEW workflow (does not touch existing ci.yml)
- src/core/budget-guard.ts — AgentBudgetGuard aligned with existing TokenBudget policy
- src/core/compensation.ts — CompensationRegistry saga/rollback for external mutations
- src/core/schema-additions.sql — agent_jobs, budget_violations, compensation_log DDL (additive; does not modify existing Drizzle schema.ts)
- adr/0005-autonomy-runtime-controls.md — Architecture decision record for this upgrade
Comment thread src/core/budget-guard.ts
`Admission rejected for job=${this.jobId} client=${this.clientId}: forecast $${this.forecastUsd.toFixed(4)} > cap $${this.capUsd.toFixed(4)}`,
);
}
logger.info({ jobId: this.jobId, clientId: this.clientId, capUsd: this.capUsd }, 'budget_guard:opened');
Comment thread src/core/budget-guard.ts
this.actualUsd += actualUsd;
this.reservedUsd = Math.max(0, this.reservedUsd - actualUsd);
this.forecastUsd = this.actualUsd + this.reservedUsd + nextEstimateUsd;
logger.debug({ jobId: this.jobId, actualUsd: this.actualUsd, forecastUsd: this.forecastUsd }, 'budget_guard:reconciled');
Comment thread src/core/compensation.ts
*/
register(stepId: string, action: () => Promise<void>): void {
this.entries.push({ stepId, clientId: this.clientId, action, registeredAt: new Date() });
logger.debug({ jobId: this.jobId, stepId, clientId: this.clientId }, 'compensation:registered');
Comment thread src/core/compensation.ts
try {
await entry.action();
results.push({ stepId: entry.stepId });
logger.info({ jobId: this.jobId, stepId: entry.stepId }, 'compensation:ok');
Comment thread src/core/compensation.ts
} catch (err) {
const message = err instanceof Error ? err.message : String(err);
results.push({ stepId: entry.stepId, error: message });
logger.error({ jobId: this.jobId, stepId: entry.stepId, message }, 'compensation:failed');
Comment thread src/core/budget-guard.ts
else if (pressure < 0.95) this.mode = 'narrow_scope';
else if (pressure < 1.00) this.mode = 'require_approval';
else this.mode = 'stop';
logger.warn({ jobId: this.jobId, mode: this.mode, pressure: pressure.toFixed(3) }, 'budget_guard:mode_changed');
Comment thread src/core/budget-guard.ts
* Moves: Open (admission) → Reserve → Reconcile → Enforce
*/

import { getConfig } from './config.js';
@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
C Security Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

💡 Need a hand with PR review? Try Gitar by Sonar!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant