Route repo Face turns through MiMo provider

This commit is contained in:
Meta Vens 2026-07-03 00:14:56 +01:00
commit 9288ed6d8c
9 changed files with 262 additions and 16 deletions

View file

@ -53,6 +53,13 @@ LOCAL_LLM_ALLOW_PUBLIC=false
STORAGE_ROOT=.voidbot
ENABLED_PROVIDERS=owner_codex
OWNER_CODEX_MODE=local_exec_owner_only
OPENAI_API_BASE_URL=https://api.openai.com/v1
OPENAI_API_KEY=
OPENAI_API_KEY_FILE=
OPENAI_API_MODEL=gpt-4o-mini
OPENAI_API_TIMEOUT_MS=120000
OPENAI_API_AUTH_HEADER=Authorization
OPENAI_API_MAX_COMPLETION_TOKENS=4096
CODEX_EXECUTABLE=codex
CODEX_EXEC_ARGS=
CODEX_MODEL=gpt-5.4
@ -87,6 +94,7 @@ REPO_FACE_HEARTBEAT_TASK_NAME=VoidBot Repo Face Heartbeats
REPO_FACE_HEARTBEAT_INTERVAL_MINUTES=15
REPO_FACE_HEARTBEAT_MAX_JOBS_PER_TICK=2
REPO_FACE_HEARTBEAT_DEFAULT_CHANNEL_ID=
REPO_FACE_HEARTBEAT_PROVIDER=owner_codex
REPO_FACE_HEARTBEAT_CODEX_MODEL=gpt-5.3-codex-spark
REPO_FACE_HEARTBEAT_CODEX_MODELS=gpt-5.3-codex-spark,gpt-5.4-mini
REPO_FACE_TURN_CODEX_MODEL=gpt-5.4

View file

@ -206,7 +206,16 @@ export async function startBot(): Promise<void> {
}),
mcpServers: [buildVoidMcpServerConfig(process.cwd())],
}),
new OpenAiApiProvider(config.enabledProviders.includes("openai_api")),
new OpenAiApiProvider({
enabled: config.enabledProviders.includes("openai_api"),
baseUrl: config.openAiApi.baseUrl,
apiKey: config.openAiApi.apiKey,
apiKeyFile: config.openAiApi.apiKeyFile,
model: config.openAiApi.model,
timeoutMs: config.openAiApi.timeoutMs,
authHeader: config.openAiApi.authHeader,
maxCompletionTokens: config.openAiApi.maxCompletionTokens,
}),
new LocalLlmProvider({
enabled: config.enabledProviders.includes("local_llm"),
ownerDiscordId: config.ownerDiscordId,

View file

@ -231,7 +231,16 @@ async function buildProviderRegistry(systemMessagesCatalog: SystemMessageCatalog
}),
mcpServers: [buildVoidMcpServerConfig(process.cwd())],
}),
new OpenAiApiProvider(config.enabledProviders.includes("openai_api")),
new OpenAiApiProvider({
enabled: config.enabledProviders.includes("openai_api"),
baseUrl: config.openAiApi.baseUrl,
apiKey: config.openAiApi.apiKey,
apiKeyFile: config.openAiApi.apiKeyFile,
model: config.openAiApi.model,
timeoutMs: config.openAiApi.timeoutMs,
authHeader: config.openAiApi.authHeader,
maxCompletionTokens: config.openAiApi.maxCompletionTokens,
}),
new LocalLlmProvider({
enabled: config.enabledProviders.includes("local_llm"),
ownerDiscordId: config.ownerDiscordId,
@ -1128,6 +1137,12 @@ function repoFaceHeartbeatCodexOptions(job: JobRecord, role: "face" | "interpret
return {};
}
if (job.provider === "openai_api") {
return {
model: config.openAiApi.model,
};
}
if (role === "face") {
return {
model: config.repoFaceHeartbeats.turnCodexModel,

View file

@ -164,7 +164,7 @@ Git history and smoke artifacts carry routine proof. `state/evidence.jsonl` shou
## Likely Next Bounded Move
- The repo Face swarm is unpaused again as of 2026-06-09. The repair isolated the expensive `gpt-5.4` state-projector path behind local `REPO_FACE_STATE_PROJECTOR_ENABLED=false`, limited local heartbeat selection to one job per tick, pointed `REPO_FACE_HEARTBEAT_DEFAULT_CHANNEL_ID` back at Aquarium (`1501196543150264332`), and disabled idle cooling for the wake test. Epiphany posted in Aquarium through the registered webhook, so the room is no longer silent. Keep watching scheduled `GameCult Local Orchestrator` pulses before raising cadence or re-enabling the state projector.
- The repo Face swarm is currently paused by `state/agent-swarm-paused.json` after the 2026-06-14 routing-context concern. The MiMo direct-provider pass wired `openai_api` as an OpenAI-compatible Chat Completions provider, configured future repo Face/persona heartbeat jobs to use `mimo-v2.5-pro`, and kept owner Codex separate. The MiMo token-plan key in `gamecult-ops` works with the Europe token-plan base URL; live `.env` references the key file instead of copying the secret. Dry-run outputs live under `.voidbot/artifacts/mimo-dry-runs/`: Face prose was usable, the Interpreter followed the block format, and one low-output-budget run showed MiMo can spend the whole completion on `reasoning_content`, so live config uses a larger completion budget. Review dry-run quality and run an isolated no-post Face pass before unpausing scheduled live turns.
- The 2026-05-22 live retry confirmed role/name mention obligations can wake multiple newborn Faces from one human intro. Mimir, Huginn, Weksa, and Kiko all posted through the repo identity webhook path. If a Face speaks with its name but no avatar, inspect `.voidbot/private/repo-discord-identities.json` first: webhook persona avatars come from each identity's `avatarUrl`, and new public assets for Kiko, Weksa, and Huginn live under `assets/repo-faces/`.
- Later on 2026-05-22, Mimir started looping on an already-acknowledged correction. Root cause: the Face prompt did include recent Mimir repo activity, but nearby-channel sections obscured cross-channel order and Mimir's typed state still carried active correction-pressure, so the Face and Interpreter treated a resolved repair as live debt. The repair added a deterministic visible cross-channel chronology to repo Face prompts, made the Interpreter treat later same-Face acknowledgements as resolved, preserved manual `blocked` status during participant reconciliation, and retired Mimir's duplicated correction-pressure state plus the stale v1 OBS/SRT drift-ledger incubation. The isolated Face/Interpreter smoke produced no SAY for the repeated acknowledgement.
- Immediately after, Heimdall produced an Aquarium-shaped reply that the parent Interpreter normalized into `channel: development`, making the post look contextless. Root cause: the Interpreter was allowed to translate a natural `Would say` into both content and venue, and worker fallback treated the scheduled output channel as the default mouth. The repair makes conversation channel ownership deterministic: `SAY` defaults to `current_room`, `current_room` resolves to `job.guildContext.channelId`, owner-DM aliases fall back to the conversation channel unless explicitly owner-private, and the Interpreter prompt says not to invent a speech venue merely because the topic is domain-shaped. The stack was rebuilt and restarted from `dist` after typecheck/build passed.

View file

@ -89,6 +89,13 @@ const envSchema = z.object({
STORAGE_ROOT: z.string().min(1).default(".voidbot"),
ENABLED_PROVIDERS: z.string().min(1).default("owner_codex"),
OWNER_CODEX_MODE: z.string().min(1).default("local_exec_owner_only"),
OPENAI_API_BASE_URL: z.string().url().default("https://api.openai.com/v1"),
OPENAI_API_KEY: optionalNonEmptyString,
OPENAI_API_KEY_FILE: optionalNonEmptyString,
OPENAI_API_MODEL: z.string().min(1).default("gpt-4o-mini"),
OPENAI_API_TIMEOUT_MS: z.coerce.number().int().positive().default(120000),
OPENAI_API_AUTH_HEADER: z.string().min(1).default("Authorization"),
OPENAI_API_MAX_COMPLETION_TOKENS: z.coerce.number().int().positive().default(4096),
CODEX_EXECUTABLE: z.string().min(1).default("codex"),
CODEX_EXEC_ARGS: z.string().default(""),
CODEX_MODEL: z.string().min(1).default("gpt-5.4"),
@ -138,6 +145,7 @@ const envSchema = z.object({
REPO_FACE_HEARTBEAT_IDLE_NAP_AFTER_MINUTES: z.coerce.number().positive().default(360),
REPO_FACE_HEARTBEAT_SPEED_OVERRIDES: z.string().default(""),
REPO_FACE_HEARTBEAT_HEAT_OVERRIDES: z.string().default(""),
REPO_FACE_HEARTBEAT_PROVIDER: z.string().min(1).default("owner_codex"),
REPO_FACE_HEARTBEAT_CODEX_MODEL: z.string().min(1).default("gpt-5.4"),
REPO_FACE_HEARTBEAT_CODEX_MODELS: z.string().default("gpt-5.4"),
REPO_FACE_IMAGINATION_CODEX_MODEL: z.string().min(1).default("gpt-5.4"),
@ -184,6 +192,15 @@ export interface AppConfig {
databaseDsn: string;
enabledProviders: ProviderName[];
ownerCodexMode: OwnerCodexMode;
openAiApi: {
baseUrl: string;
apiKey?: string;
apiKeyFile?: string;
model: string;
timeoutMs: number;
authHeader: string;
maxCompletionTokens: number;
};
codexExecutable: string;
codexExecArgs: string[];
codexModel: string;
@ -236,6 +253,7 @@ export interface AppConfig {
};
speedOverrides: Record<string, number>;
heatOverrides: Record<string, number>;
provider: ProviderName;
codexModel?: string;
codexModels: string[];
imaginationCodexModel?: string;
@ -335,6 +353,14 @@ function parseProviders(value: string): ProviderName[] {
return providers as ProviderName[];
}
function parseProvider(value: string): ProviderName {
const provider = value.trim();
if (!isProviderName(provider)) {
throw new Error(`Unsupported provider: ${provider}`);
}
return provider;
}
function parseRepoPrefixRules(value: string): Record<string, string[]> {
const rules: Record<string, string[]> = {};
@ -445,6 +471,15 @@ export function loadConfig(env: NodeJS.ProcessEnv = process.env): AppConfig {
databaseDsn: parsed.DATABASE_DSN,
enabledProviders: parseProviders(parsed.ENABLED_PROVIDERS),
ownerCodexMode: parseOwnerCodexMode(parsed.OWNER_CODEX_MODE),
openAiApi: {
baseUrl: parsed.OPENAI_API_BASE_URL.replace(/\/+$/, ""),
apiKey: parsed.OPENAI_API_KEY,
apiKeyFile: parsed.OPENAI_API_KEY_FILE ? resolve(parsed.OPENAI_API_KEY_FILE) : undefined,
model: parsed.OPENAI_API_MODEL,
timeoutMs: parsed.OPENAI_API_TIMEOUT_MS,
authHeader: parsed.OPENAI_API_AUTH_HEADER,
maxCompletionTokens: parsed.OPENAI_API_MAX_COMPLETION_TOKENS,
},
codexExecutable: parsed.CODEX_EXECUTABLE,
codexExecArgs: parseList(parsed.CODEX_EXEC_ARGS),
codexModel: parsed.CODEX_MODEL,
@ -497,6 +532,7 @@ export function loadConfig(env: NodeJS.ProcessEnv = process.env): AppConfig {
},
speedOverrides: parseNumericMap(parsed.REPO_FACE_HEARTBEAT_SPEED_OVERRIDES),
heatOverrides: parseNumericMap(parsed.REPO_FACE_HEARTBEAT_HEAT_OVERRIDES),
provider: parseProvider(parsed.REPO_FACE_HEARTBEAT_PROVIDER),
codexModel: parsed.REPO_FACE_HEARTBEAT_CODEX_MODEL,
codexModels: parseList(parsed.REPO_FACE_HEARTBEAT_CODEX_MODELS).length > 0
? parseList(parsed.REPO_FACE_HEARTBEAT_CODEX_MODELS)

View file

@ -1,14 +1,49 @@
import { readFile } from "node:fs/promises";
import {
type Actor,
type ContextBundle,
type GuildContext,
type ProviderAdapter,
type ProviderArtifact,
type ProviderRequest,
type ProviderResponse,
} from "@voidbot/shared";
export interface OpenAiApiProviderOptions {
enabled: boolean;
baseUrl: string;
apiKey?: string;
apiKeyFile?: string;
model: string;
timeoutMs: number;
authHeader: string;
maxCompletionTokens: number;
}
interface ChatMessage {
role: "user" | "assistant" | "system";
content: string;
}
interface ChatCompletionResponse {
choices?: Array<{
message?: {
content?: unknown;
};
finish_reason?: unknown;
}>;
usage?: {
prompt_tokens?: unknown;
completion_tokens?: unknown;
total_tokens?: unknown;
};
id?: unknown;
model?: unknown;
}
export class OpenAiApiProvider implements ProviderAdapter {
public constructor(private readonly enabled: boolean) {}
public constructor(private readonly options: OpenAiApiProviderOptions) {}
public getName(): "openai_api" {
return "openai_api";
@ -16,19 +51,18 @@ export class OpenAiApiProvider implements ProviderAdapter {
public getCapabilities(): string[] {
return [
"public_generation",
"input_moderation_required",
"output_moderation_required",
"budget_controls_required",
"openai_compatible_chat_completions",
"direct_api_generation",
"persona_runtime",
];
}
public isEnabled(): boolean {
return this.enabled;
return this.options.enabled;
}
public isAllowedForActor(_actor: Actor, _guildContext: GuildContext): boolean {
return this.enabled;
return this.options.enabled;
}
public buildRequest(
@ -42,8 +76,74 @@ export class OpenAiApiProvider implements ProviderAdapter {
};
}
public async execute(_request: ProviderRequest): Promise<ProviderResponse> {
throw new Error("The OpenAI API provider scaffold exists, but the runtime adapter is not wired yet.");
public async execute(request: ProviderRequest): Promise<ProviderResponse> {
const model = readStringOption(request.options?.model) ?? this.options.model;
const messages: ChatMessage[] = [
{
role: "user",
content: request.contextBundle.prompt,
},
];
const requestBody = {
model,
messages,
stream: false,
max_completion_tokens: readPositiveIntegerOption(request.options?.maxCompletionTokens) ??
this.options.maxCompletionTokens,
};
const controller = new AbortController();
const timeoutHandle = setTimeout(() => controller.abort(), this.options.timeoutMs);
try {
const apiKey = await this.loadApiKey();
const response = await fetch(`${normalizeBaseUrl(this.options.baseUrl)}/chat/completions`, {
method: "POST",
headers: this.buildHeaders(apiKey),
body: JSON.stringify(requestBody),
signal: controller.signal,
});
const responseText = await response.text();
if (!response.ok) {
throw new Error(
`OpenAI-compatible chat request failed with ${response.status}: ${redactSecret(responseText, apiKey).slice(0, 2000)}`,
);
}
const payload = JSON.parse(responseText) as ChatCompletionResponse;
const outputText = normalizeModelText(payload.choices?.[0]?.message?.content);
if (!outputText) {
const finishReason = normalizeModelText(payload.choices?.[0]?.finish_reason) ?? "unknown";
throw new Error(
`OpenAI-compatible chat response did not include assistant content (finish_reason=${finishReason}).`,
);
}
return {
status: "completed",
summary: `OpenAI-compatible API response generated with ${model}.`,
outputText,
artifacts: buildArtifacts(requestBody, payload),
metadata: {
model,
provider_model: normalizeModelText(payload.model) ?? model,
finish_reason: normalizeModelText(payload.choices?.[0]?.finish_reason) ?? "unknown",
prompt_tokens: readNumericMetadata(payload.usage?.prompt_tokens),
completion_tokens: readNumericMetadata(payload.usage?.completion_tokens),
total_tokens: readNumericMetadata(payload.usage?.total_tokens),
},
};
} catch (error) {
if ((error as Error).name === "AbortError") {
throw new Error(
`Timed out waiting for OpenAI-compatible model "${model}" at ${this.options.baseUrl}.`,
);
}
throw error;
} finally {
clearTimeout(timeoutHandle);
}
}
public async estimateCost(_request: ProviderRequest): Promise<number> {
@ -51,7 +151,84 @@ export class OpenAiApiProvider implements ProviderAdapter {
}
public getAuditRedactions(): string[] {
return ["api_key"];
return ["api_key", "authorization"];
}
private async loadApiKey(): Promise<string> {
const direct = this.options.apiKey?.trim();
if (direct) {
return direct;
}
if (this.options.apiKeyFile) {
const fromFile = (await readFile(this.options.apiKeyFile, "utf8")).trim();
if (fromFile) {
return fromFile;
}
}
throw new Error("OpenAI-compatible API provider is enabled but no API key is configured.");
}
private buildHeaders(apiKey: string): Record<string, string> {
const headers: Record<string, string> = {
"Content-Type": "application/json",
};
const authHeader = this.options.authHeader.trim();
if (authHeader.toLowerCase() === "authorization") {
headers.Authorization = `Bearer ${apiKey}`;
} else {
headers[authHeader] = apiKey;
}
return headers;
}
}
function buildArtifacts(
requestBody: Record<string, unknown>,
payload: ChatCompletionResponse,
): ProviderArtifact[] {
return [
{
name: "openai-api-request.json",
contentType: "json",
content: `${JSON.stringify(requestBody, null, 2)}\n`,
},
{
name: "openai-api-response.json",
contentType: "json",
content: `${JSON.stringify(payload, null, 2)}\n`,
},
];
}
function normalizeBaseUrl(value: string): string {
return value.replace(/\/+$/, "");
}
function normalizeModelText(value: unknown): string | undefined {
return typeof value === "string" && value.trim().length > 0 ? value.trim() : undefined;
}
function readStringOption(value: unknown): string | undefined {
return normalizeModelText(value);
}
function readPositiveIntegerOption(value: unknown): number | undefined {
if (typeof value === "number" && Number.isInteger(value) && value > 0) {
return value;
}
if (typeof value === "string" && /^\d+$/.test(value.trim())) {
const parsed = Number(value);
return parsed > 0 ? parsed : undefined;
}
return undefined;
}
function readNumericMetadata(value: unknown): string {
return typeof value === "number" && Number.isFinite(value) ? String(value) : "0";
}
function redactSecret(text: string, secret: string): string {
return secret ? text.split(secret).join("[redacted]") : text;
}

View file

@ -602,7 +602,7 @@ async function queueRepoFaceTurn(input: {
const requestMessageId = `agent-turn:${identity.id}:${input.queuedAt}`;
const result = await input.storage.jobQueue.createJob({
command: HEARTBEAT_COMMAND,
provider: "owner_codex",
provider: input.config.repoFaceHeartbeats.provider,
runApprovalRequired: false,
postApprovalRequired: false,
requester: contextBundle.actor,

View file

@ -365,3 +365,4 @@
{"ts":"2026-06-14T12:43:35Z","type":"implementation","status":"ok","note":"Fixed repo Face cross-channel reply routing: prompt transcripts now include source channel ids for current, nearby, and chronology messages; Face prompts explicitly forbid answering nearby-room posts in the current room; worker post routing now derives the destination channel from reply_to message ids and also infers a non-current room when a bare Face output names that room label (e.g. general thread). Verified against Libby prompt showing Metacrat general messages followed by the bad Aquarium post."}
{"ts":"2026-06-14T17:40:23Z","type":"implementation","status":"ok","note":"Repo Face speech routing now carries typed active conversation contexts across current and nearby Discord channels. Heartbeat prompts emit ctx_<channel>_<message> records; SAY can include context; worker resolves context to source channel/reply target and rejects unknown or ambiguous unqualified SAY when multiple channels are active."}
{"ts":"2026-06-14T20:01:05Z","type":"implementation","status":"ok","note":"Closed the surviving repo Face context leak: channel: current_room no longer counts as explicit routing when multiple active conversation channels are visible, and bare parent-interpreter text is no longer wrapped into SAY fallback under multi-context jobs. Swarm paused while this fix is verified live."}
{"ts":"2026-07-02T23:14:18Z","type":"implementation","status":"ok","note":"Wired openai_api as an OpenAI-compatible direct chat provider and configured repo Face heartbeat jobs to use MiMo via openai_api. MiMo token-plan key works against https://token-plan-ams.xiaomimimo.com/v1. Dry-run Face prompts produced usable persona text; a 1200-token run spent all output on reasoning_content, so live config uses OPENAI_API_MAX_COMPLETION_TOKENS=8192. Live swarm remains paused."}

View file

@ -262,5 +262,5 @@ rejected_paths:
reason: sleep/distillation that collapses concrete claims into generic abstraction creates memory nonsense and then forces later cleanup compensators
current_status:
summary: VoidBot's bot/worker/provider/RAG/Postgres/Qdrant/CultCache structure is live, and the 2026-06-09 swarm repair pass resumed autonomous repo Face turns through `state/agent-swarm-paused.json`. Local runtime config now points `REPO_FACE_HEARTBEAT_DEFAULT_CHANNEL_ID` at Aquarium, disables the expensive repo Face state-projector pass, disables idle cooling during the wake test, and limits selection to one job per tick. Epiphany posted in Aquarium through the registered webhook, proving the room is no longer silent. GameCult Local Orchestrator remains the single pulse owner; Bifrost work routing remains paused by default.
next_action: Watch the next scheduled `GameCult Local Orchestrator` pulses with the swarm unpaused and rebuilt worker live. Verify repo Face turns keep using Aquarium as current room, do not revive the gpt-5.4 state-projector timeout path while `REPO_FACE_STATE_PROJECTOR_ENABLED=false`, and confirm the parent Interpreter either emits `SAY` blocks or the worker's bare-interpreter fallback routes compact unconditional speech safely.
summary: VoidBot's bot/worker/provider/RAG/Postgres/Qdrant/CultCache structure is live. Repo Face scheduling remains behind `state/agent-swarm-paused.json`, currently paused after the 2026-06-14 routing-context concern. Local runtime config points Face heartbeats at Aquarium, keeps the expensive state-projector pass disabled, and now routes future repo Face/persona heartbeat jobs through the direct `openai_api` provider configured for MiMo `mimo-v2.5-pro` instead of Codex. Dry-run MiMo calls against saved Face prompts produced usable persona text, but one low-output-budget run spent all tokens on `reasoning_content`, so the live OpenAI-compatible provider uses a larger completion budget. GameCult Local Orchestrator remains the single pulse owner; Bifrost work routing remains paused by default.
next_action: Keep the swarm paused while reviewing MiMo dry-run Face and parent-Interpreter outputs from `.voidbot/artifacts/mimo-dry-runs/`. If quality and structured routing look acceptable, run a bounded forced/isolated Face pass without Discord posting before unpausing scheduled live turns.