Delete Windows Void rumination authority

This commit is contained in:
Meta Vens 2026-07-16 05:58:31 +01:00
commit 5b35fd9fd2
25 changed files with 42 additions and 3561 deletions

View file

@ -1,5 +1,3 @@
import { stat } from "node:fs/promises";
import { resolve } from "node:path";
import { createStateStorage } from "@voidbot/core";
@ -72,9 +70,6 @@ export async function scanActivePersonaTurns(
}
active.set(identityId, job.id);
}
if (await readRecentLock(resolve(config.storageRoot, "status", "moderation-rumination.lock"), 20, nowMs)) {
active.set("void", "lock:moderation-rumination");
}
return { active, staleRecovered };
} finally {
await storage.close();
@ -93,14 +88,3 @@ export function parsePersonaTurnIdentity(requestMessageId: string | undefined):
export function staleActiveTurnThresholdMs(codexExecTimeoutMs: number): number {
return Math.max(MIN_STALE_ACTIVE_JOB_MS, codexExecTimeoutMs * 3);
}
async function readRecentLock(path: string, maxAgeMinutes: number, nowMs: number): Promise<boolean> {
try {
const info = await stat(path);
const ageMs = nowMs - info.mtimeMs;
return ageMs >= 0 && ageMs < maxAgeMinutes * 60_000;
} catch (error) {
if (error && typeof error === "object" && "code" in error && error.code === "ENOENT") return false;
throw error;
}
}

View file

@ -39,7 +39,7 @@ function runTick(): Promise<void> {
console.log(`Persona scheduler tick completed (started ${startedAt}). ${JSON.stringify(result)}`);
if (Date.now() - lastPhysiologyAt >= physiologyIntervalMs) {
try {
const physiology = await runVoidPhysiologyOrgan({ statePath: resolve(config.storageRoot, "private", "void-self-state.cc"), statusDirectory: resolve(config.storageRoot, "status") });
const physiology = await runVoidPhysiologyOrgan({ statePath: resolve(config.storageRoot, "private", "void-self-state.cc") });
lastPhysiologyAt = Date.now();
console.log(`Void physiology pulse completed. ${JSON.stringify(physiology)}`);
if (physiology.memoryMaintenanceIntent) {

View file

@ -16,7 +16,6 @@ import { projectNativePersonaBody } from "./persona-standard-state-projector.js"
import { readGlobalAgentDoctrine } from "./global-agent-doctrine-source.js";
import { assemblePersonaTurn } from "./persona-turn-assembler.js";
import { submitPersonaTurn } from "./turn-actuator.js";
import { launchVoidModerationTurn } from "./void-moderation-turn-actuator.js";
import { readRepoActivity } from "./repo-activity-source.js";
import { projectRepoActivityObservation } from "./repo-activity-projector.js";
import { buildPersonaChannelPlan, newestPendingMentionChannel, personaChannelSpeedMultiplier } from "./turn-routing.js";
@ -32,10 +31,8 @@ export interface PersonaTurnStartReceipt {
failureReason?: string;
}
export function buildPersonaParticipantSpecs(identities: RepoDiscordIdentity[], includeVoid: boolean): PersonaParticipantSpec[] {
return [
...(includeVoid ? [{ id: "void", participantKind: "system_agent" as const, turnKind: "void_moderation" as const, repoName: "VoidBot", displayName: "Void", allowedChannelIds: [], channelSpeedMultiplier: 1 }] : []),
...identities.map((identity) => ({
export function buildPersonaParticipantSpecs(identities: RepoDiscordIdentity[]): PersonaParticipantSpec[] {
return identities.map((identity) => ({
id: identity.id,
participantKind: identity.identityKind === "native_persona" ? "native_persona" as const : "repo_face" as const,
turnKind: "repo_face_rumination" as const,
@ -44,8 +41,7 @@ export function buildPersonaParticipantSpecs(identities: RepoDiscordIdentity[],
allowedChannelIds: getRepoDiscordIdentityAllowedChannelIds(identity),
channelSpeedMultiplier: personaChannelSpeedMultiplier(identity),
identity,
})),
];
}));
}
export function pendingMentionsForPersona(state: { pendingMentions: RepoFacePendingMention[] }, identityId: string): RepoFacePendingMention[] {
@ -69,7 +65,6 @@ export async function dispatchPersonaParticipantTurn(input: {
queuedAt: string;
personaStateObservation?: PersonaStateObservation;
}): Promise<PersonaTurnStartReceipt> {
if (input.participant.turnKind === "void_moderation") return launchVoidModerationTurn({ queuedAt: input.queuedAt, storageRoot: input.config.storageRoot, pendingMentions: input.pendingMentions });
const identity = input.registryIdentities.find((entry) => entry.id === input.participant.identityId);
if (!identity) return { created: false, failureReason: `No registered Persona identity exists for ${input.participant.identityId}.` };
const channelPlan = buildPersonaChannelPlan(identity, input.config.repoFaceHeartbeats.defaultChannelId, newestPendingMentionChannel(input.pendingMentions));

View file

@ -75,7 +75,7 @@ export async function runPersonaSchedulerTick(input: {
const globalHeat = (await readSwarmControlState())?.globalHeat ?? config.repoFaceHeartbeats.globalHeat;
applySchedulerControls({ state, baseRecoveryMinutes: config.repoFaceHeartbeats.baseRecoveryMinutes, globalHeat });
const completedThisTick = new Set<string>();
const participantSpecs = buildPersonaParticipantSpecs(registry.identities, config.voidModerationHeartbeatEnabled);
const participantSpecs = buildPersonaParticipantSpecs(registry.identities);
reconcileInitiativeParticipants({ state, specs: participantSpecs, defaultChannelId: config.repoFaceHeartbeats.defaultChannelId, speedOverrides: config.repoFaceHeartbeats.speedOverrides, heatOverrides: config.repoFaceHeartbeats.heatOverrides, baseRecoveryMinutes: config.repoFaceHeartbeats.baseRecoveryMinutes, globalHeat, activeTurns: activeTurnScan.active, completedThisTick });
rescheduleStaleOverdueParticipants(state);
applyPendingMentionPriority(state);

View file

@ -1,15 +0,0 @@
import { stat } from "node:fs/promises";
export async function readVoidModerationActivity(input: {
lockPath: string;
observedAt?: Date;
recentWithinMs?: number;
}): Promise<{ active: boolean; lockPath: string; ageMs?: number }> {
try {
const info = await stat(input.lockPath);
const ageMs = (input.observedAt ?? new Date()).getTime() - info.mtimeMs;
return { active: ageMs >= 0 && ageMs < (input.recentWithinMs ?? 20 * 60_000), lockPath: input.lockPath, ageMs };
} catch {
return { active: false, lockPath: input.lockPath };
}
}

View file

@ -1,121 +0,0 @@
import { spawn } from "node:child_process";
import { mkdir, stat, writeFile } from "node:fs/promises";
import { resolve } from "node:path";
import type { RepoFacePendingMention } from "@voidbot/core";
export interface VoidModerationTurnInput {
queuedAt: string;
storageRoot: string;
pendingMentions: RepoFacePendingMention[];
workspaceRoot?: string;
handshakeTimeoutMs?: number;
}
export interface VoidModerationTurnReceipt {
created: boolean;
activeJobId?: string;
requestMessageId: string;
failureReason?: string;
}
interface VoidModerationActuatorDependencies {
launch?: (command: string, args: string[], options: { cwd: string; stdio: "ignore"; windowsHide: true }) => { pid?: number; unref(): void };
now?: () => number;
pause?: (milliseconds: number) => Promise<void>;
touchedAfter?: (path: string, timestampMs: number) => Promise<boolean>;
}
export async function launchVoidModerationTurn(
input: VoidModerationTurnInput,
dependencies: VoidModerationActuatorDependencies = {},
): Promise<VoidModerationTurnReceipt> {
const workspaceRoot = resolve(input.workspaceRoot ?? process.cwd());
const runnerScript = resolve(workspaceRoot, "scripts", "run-void-moderator-rumination.ps1");
const statusDir = resolve(input.storageRoot, "status");
const lockPath = resolve(statusDir, "moderation-rumination.lock");
const statusPath = resolve(statusDir, "moderation-rumination.json");
const pendingMentionsPath = resolve(statusDir, "void-moderation-pending-mentions.json");
const now = dependencies.now ?? Date.now;
const launchedAt = now();
await mkdir(statusDir, { recursive: true });
await writeFile(pendingMentionsPath, `${JSON.stringify({ generatedAt: input.queuedAt, pendingMentions: input.pendingMentions }, null, 2)}\n`, "utf8");
const launchCommand = buildVoidModerationLaunchCommand({ pendingMentionsPath, runnerScript, workspaceRoot });
const launch = dependencies.launch ?? ((command, args, options) => spawn(command, args, options));
const child = launch("powershell.exe", [
"-NoProfile",
"-NonInteractive",
"-ExecutionPolicy",
"Bypass",
"-Command",
launchCommand,
], { cwd: workspaceRoot, stdio: "ignore", windowsHide: true });
child.unref();
const handshake = await waitForVoidModerationHandshake({
lockPath,
statusPath,
launchedAt,
timeoutMs: input.handshakeTimeoutMs ?? 60_000,
now,
pause: dependencies.pause,
touchedAfter: dependencies.touchedAfter,
});
const requestMessageId = `agent-turn:void:${input.queuedAt}`;
if (!handshake.started) return {
created: false,
activeJobId: child.pid ? `launcher-process:${child.pid}` : undefined,
requestMessageId,
failureReason: handshake.reason,
};
return { created: true, activeJobId: `process:void-moderation:${input.queuedAt}`, requestMessageId };
}
export function buildVoidModerationLaunchCommand(input: {
pendingMentionsPath: string;
runnerScript: string;
workspaceRoot: string;
}): string {
const argumentsList = ["-NoProfile", "-NonInteractive", "-ExecutionPolicy", "Bypass", "-File", input.runnerScript]
.map(toPowerShellSingleQuotedString)
.join(", ");
return [
`$env:VOID_RUMINATION_PENDING_MENTIONS_PATH = ${toPowerShellSingleQuotedString(input.pendingMentionsPath)};`,
`$arguments = @(${argumentsList});`,
`Start-Process -FilePath 'powershell.exe' -ArgumentList $arguments -WorkingDirectory ${toPowerShellSingleQuotedString(input.workspaceRoot)} -WindowStyle Hidden;`,
].join(" ");
}
export async function waitForVoidModerationHandshake(input: {
lockPath: string;
statusPath: string;
launchedAt: number;
timeoutMs: number;
now?: () => number;
pause?: (milliseconds: number) => Promise<void>;
touchedAfter?: (path: string, timestampMs: number) => Promise<boolean>;
}): Promise<{ started: true } | { started: false; reason: string }> {
const now = input.now ?? Date.now;
const pause = input.pause ?? ((milliseconds) => new Promise((resolvePause) => setTimeout(resolvePause, milliseconds)));
const touchedAfter = input.touchedAfter ?? wasTouchedAfter;
const deadline = now() + input.timeoutMs;
while (now() < deadline) {
if (await touchedAfter(input.lockPath, input.launchedAt)) return { started: true };
if (await touchedAfter(input.statusPath, input.launchedAt)) return { started: true };
await pause(250);
}
return { started: false, reason: "void_moderation_launch_handshake_missing" };
}
function toPowerShellSingleQuotedString(value: string): string {
return `'${value.replace(/'/g, "''")}'`;
}
async function wasTouchedAfter(path: string, timestampMs: number): Promise<boolean> {
try {
return (await stat(path)).mtimeMs >= timestampMs - 500;
} catch {
return false;
}
}

View file

@ -1,31 +1,23 @@
import { resolve } from "node:path";
import { applyVoidSelfStateOperation, loadVoidSelfStateTypedDocuments } from "@voidbot/core";
import { readVoidModerationActivity } from "./void-moderation-activity-source.js";
import { projectVoidPhysiology, type VoidPhysiologyProjection } from "./void-physiology-domain.js";
export interface VoidPhysiologyOrganResult extends VoidPhysiologyProjection {
ok: true;
observedAt: string;
statePath: string;
moderationLockPath: string;
}
export async function runVoidPhysiologyOrgan(input: {
statePath: string;
statusDirectory: string;
observedAt?: Date;
moderationActive?: boolean;
}, dependencies: {
loadState?: typeof loadVoidSelfStateTypedDocuments;
applyOperation?: typeof applyVoidSelfStateOperation;
readModerationActivity?: typeof readVoidModerationActivity;
} = {}): Promise<VoidPhysiologyOrganResult> {
const observedAt = input.observedAt ?? new Date();
const moderationLockPath = resolve(input.statusDirectory, "moderation-rumination.lock");
const [state, moderation] = await Promise.all([
(dependencies.loadState ?? loadVoidSelfStateTypedDocuments)({ canonicalPath: input.statePath }),
(dependencies.readModerationActivity ?? readVoidModerationActivity)({ lockPath: moderationLockPath, observedAt }),
]);
const projection = projectVoidPhysiology({ state, observedAt, moderationActive: moderation.active });
const state = await (dependencies.loadState ?? loadVoidSelfStateTypedDocuments)({ canonicalPath: input.statePath });
const projection = projectVoidPhysiology({ state, observedAt, moderationActive: input.moderationActive ?? false });
for (const operation of projection.operations) await (dependencies.applyOperation ?? applyVoidSelfStateOperation)({ canonicalPath: input.statePath }, operation);
return { ok: true, observedAt: observedAt.toISOString(), statePath: input.statePath, moderationLockPath, ...projection };
return { ok: true, observedAt: observedAt.toISOString(), statePath: input.statePath, ...projection };
}