Remove dry-run and create-only autoscaling modes
This commit is contained in:
@@ -19,7 +19,6 @@ export function scalingAdmission(operationId: string): string | null {
|
||||
else {
|
||||
const policy: ScalingPolicy = { ...JSON.parse(row.settings), id: row.id, mode: row.mode, revision: row.revision, nextActionAt: 0, pausedReason: null, updatedAt: '' };
|
||||
const requested = JSON.parse(intent.decision) as ScalingDecision;
|
||||
if (requested.action === 'destroy' && row.mode !== 'create-destroy') return 'Automatic removal is disabled.';
|
||||
const snapshot = scalingSnapshot(policy, Date.now(), operationId);
|
||||
if (requested.action === 'create') {
|
||||
snapshot.reservedNames = snapshot.reservedNames.filter(n => n !== requested.server);
|
||||
|
||||
@@ -150,7 +150,7 @@ export async function runAutoscaling(): Promise<boolean> {
|
||||
const evidence = JSON.stringify({ members: snapshot.members, reservations: snapshot.reservedNames, keyPool: snapshot.keyPool, blockers: snapshot.blockers });
|
||||
const fingerprint = createHash('sha256').update(JSON.stringify([policy.revision, decision, snapshot.members.map(m => [m.name, m.identity, m.state])])).digest('hex');
|
||||
const last = db().prepare('SELECT id,fingerprint FROM autoscaling_decisions WHERE policy_id=? ORDER BY evaluated_at DESC,rowid DESC LIMIT 1').get(policy.id) as { id: string; fingerprint: string } | undefined;
|
||||
const execute = liveScaling(policy.mode) && (decision.action === 'create' || policy.mode === 'create-destroy' && decision.action === 'destroy');
|
||||
const execute = liveScaling(policy.mode) && (decision.action === 'create' || decision.action === 'destroy');
|
||||
const decisionId = randomUUID();
|
||||
if (!execute && last?.fingerprint === fingerprint) db().prepare('UPDATE autoscaling_decisions SET last_seen_at=?,evidence=? WHERE id=?').run(now, evidence, last.id);
|
||||
else db().prepare('INSERT INTO autoscaling_decisions(id,policy_id,revision,evaluated_at,last_seen_at,fingerprint,decision,evidence) VALUES(?,?,?,?,?,?,?,?)')
|
||||
|
||||
@@ -34,4 +34,16 @@ export function ensureAutoscalingSchema(handle: Database.Database): void {
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS autoscaling_sample_retention ON autoscaling_samples(sampled_at);
|
||||
`);
|
||||
// Removed modes must not silently gain permission to destroy lobbies.
|
||||
// Keep ownership while delivered work settles through normal reconciliation.
|
||||
handle.transaction(() => {
|
||||
handle.prepare(`UPDATE autoscaling_authorizations SET revoked_at=?
|
||||
WHERE claimed_at IS NULL AND revoked_at IS NULL AND policy_id IN
|
||||
(SELECT id FROM autoscaling_policies WHERE mode IN ('dry-run','create-only'))`).run(Date.now());
|
||||
handle.prepare(`UPDATE autoscaling_policies SET mode='off', settings=json_set(settings,'$.mode','off'),
|
||||
revision=revision+1, paused_reason='This autoscaling mode was removed. Review and enable Create and destroy to resume.',
|
||||
owns_map=CASE WHEN EXISTS (SELECT 1 FROM autoscaling_decisions WHERE policy_id=autoscaling_policies.id AND resolved=0)
|
||||
THEN owns_map ELSE 0 END, updated_at=?
|
||||
WHERE mode IN ('dry-run','create-only')`).run(new Date().toISOString());
|
||||
})();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user