Files
PaperClipAI/server/src/services/native-runtime/muse-terminal-reconciliation.ts
T
DottaandPaperclip e6dcc6b095 Connect personal Muse through secure native execution and Vault OAuth (#16448)
Add company-scoped Muse native control, OAuth, wake receiver and recovery.

Recheck current authority after waits and before effects or receipt replay. Preserve task-read scope, assignment expiry, independent holds, nonblocking reassignment and truthful cleanup provenance.

Retain source trust on progress comments and verify current Muse V8 authority through real signed-JWT HTTP requests. Preserve the upstream trimmed ordinary authentication lookup.

Refs #16448.

Preserve captured canonical queue recovery and concurrent environment preparation while retaining the scoped Muse V8 exclusion. Normal migration 0354 and existing Muse SQL remain unchanged. Fresh current-head Greptile review is 5/5 with the project-write finding addressed. Required CI and independent technical review gate the merge; maintainer override is reserved for formal approval rules.

Recheck current Muse project-write authority after all receipt/task/run/admission waits, before creation or replay. Real PostgreSQL regressions reproduce four late effects/replays on the old route; the repaired three-file treatment passes 354 cases with no skips, and the scoped server typecheck passes. Ordinary/Dot behavior is preserved.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-10-17 22:44:36 -05:00

27 lines
1.6 KiB
TypeScript

import { heartbeatRuns, type Db } from "@paperclipai/db";
import { museRunnerBroker } from "../muse-runner-broker.js";
import { logger } from "../../middleware/logger.js";
function record(value: unknown): Record<string, unknown> {
return typeof value === "object" && value !== null && !Array.isArray(value)
? value as Record<string, unknown> : {};
}
/** Call only after run projection commits and outside issue/run transactions.
* Reconcile the original binding, including after a provider configuration change.
* The broker retains failed-worker and unsettled-native-effect uncertainty.
*/
export async function reconcileMuseNativeTerminalRun(db: Db, run: Pick<typeof heartbeatRuns.$inferSelect,
"id" | "companyId" | "agentId" | "runtimeMode" | "status" | "runnerProfileJson">): Promise<void> {
if (run.runtimeMode !== "native" || !["succeeded", "failed", "cancelled", "timed_out", "interrupted"].includes(run.status)) return;
const execution = record(record(run.runnerProfileJson).nativeExecutionInput);
const provider = record(execution.provider);
const binding = record(provider.binding);
if (execution.schema !== "paperclip.native-execution-input.v8" || provider.kind !== "muse"
|| binding.companyId !== run.companyId || binding.agentId !== run.agentId
|| typeof binding.bindingId !== "string" || !binding.bindingId) return;
await museRunnerBroker(db).reconcileTerminalAssignments(run.companyId, run.agentId, binding.bindingId).catch(err => {
logger.warn({ err, runId: run.id, bindingId: binding.bindingId }, "Muse terminal assignment reconciliation deferred to maintenance");
});
}