Skip to content
Open
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
8 changes: 8 additions & 0 deletions src/always-on/config/parseAlwaysOnConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export type AlwaysOnWorkspaceConfig = {
snapshotBaseDir?: string;
snapshotMaxBytes: number;
gitLfs: boolean;
maxPlansPerCycle: number;
};

export type AlwaysOnExecutionConfig = {
Expand Down Expand Up @@ -78,6 +79,7 @@ export function defaultAlwaysOnConfig(): AlwaysOnConfig {
workspace: {
snapshotMaxBytes: DEFAULT_SNAPSHOT_MAX_BYTES,
gitLfs: false,
maxPlansPerCycle: 3,
},
execution: {
maxTurns: 30,
Expand Down Expand Up @@ -340,6 +342,12 @@ function parseWorkspace(
diagnostics,
);
target.gitLfs = booleanField(raw, "gitLfs", target.gitLfs);
target.maxPlansPerCycle = positiveInteger(
raw.maxPlansPerCycle,
target.maxPlansPerCycle,
"alwaysOn.workspace.maxPlansPerCycle",
diagnostics,
);
}

function parseExecution(
Expand Down
3 changes: 2 additions & 1 deletion src/always-on/protocol/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ export type GateBlockReason =
| "recent_user_msg"
| "cooldown"
| "daily_budget"
| "lock_busy";
| "lock_busy"
| "cycle_full";

export type GateResult =
| { ok: true; lease?: AlwaysOnChannelLease }
Expand Down
1 change: 1 addition & 0 deletions src/always-on/runtime/AlwaysOnRuntime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ export class AlwaysOnRuntime {
projectKey: this.projectKey,
paths: this.paths,
stateStore: this.stateStore,
cycleStore: this.cycleStore,
leases: this.leases,
fire: this.fire,
uuid: this.uuid,
Expand Down
14 changes: 14 additions & 0 deletions src/always-on/runtime/DiscoveryScheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { AlwaysOnError } from "../protocol/errors.js";
import type { GateBlockReason } from "../protocol/types.js";
import type { AlwaysOnPaths } from "../storage/AlwaysOnPaths.js";
import { DiscoveryStateStore } from "../storage/DiscoveryStateStore.js";
import { WorkCycleStore } from "../storage/WorkCycleStore.js";
import type { ChannelLeaseRegistry } from "./ChannelLeaseRegistry.js";
import {
acquireDiscoveryLock,
Expand All @@ -23,6 +24,7 @@ export type DiscoverySchedulerDependencies = {
projectKey: string;
paths: AlwaysOnPaths;
stateStore: DiscoveryStateStore;
cycleStore: WorkCycleStore;
leases: ChannelLeaseRegistry;
fire: DiscoveryFire;
uuid: () => string;
Expand Down Expand Up @@ -113,6 +115,18 @@ export class DiscoveryScheduler {
return { outcome: "blocked", reason: evaluation.reason };
}

if (state.activeWorkCycleId) {
const activeCycle = await this.deps.cycleStore.getRecord(state.activeWorkCycleId);
if (
activeCycle &&
activeCycle.status === "active" &&
activeCycle.planIds.length >= this.deps.config.workspace.maxPlansPerCycle
) {
this.deps.logger.info("always-on gate blocked", { reason: "cycle_full" });
return { outcome: "blocked", reason: "cycle_full" as GateBlockReason };
}
}

const runId = this.deps.uuid();
const startedAt = this.deps.now();

Expand Down