merge: integrate upstream main with local Makelore changes
This commit is contained in:
@@ -23,6 +23,7 @@ import {
|
||||
seedWorksSquareAIGatewayCredential,
|
||||
} from '../../services/works-square-ai-gateway';
|
||||
import type { ConversationPatchEnvelope, PrepareConversationInput } from '../contracts';
|
||||
import { PiAgentServerProcess } from './agent-server-process';
|
||||
import { PiManagedExtensionHost } from './extension-host';
|
||||
import { PiManagedInputRevisionCoordinator } from './managed-input-revision';
|
||||
import { runPiReleasePressureCleanup } from './release-proof-cleanup';
|
||||
@@ -44,7 +45,7 @@ type ProofMilestoneSource = 'main.telemetry' | 'pi.agent_start' | 'pi.assistant_
|
||||
|
||||
type TrackedProcess = {
|
||||
role: ProofWorkerRole;
|
||||
process: PiWorkerProcess;
|
||||
process: PiWorkerProcess | PiAgentServerProcess;
|
||||
};
|
||||
|
||||
type ObservedWorkerEvent = {
|
||||
@@ -91,6 +92,7 @@ type RealProofComposition = {
|
||||
tracked: TrackedProcess[];
|
||||
telemetry: PiRuntimeTelemetryEvent[];
|
||||
observedEvents: ObservedWorkerEvent[];
|
||||
agentServer: PiAgentServerProcess;
|
||||
extensionHost: PiManagedExtensionHost;
|
||||
pool: PiWorkerPool;
|
||||
scheduler: PiSubagentScheduler;
|
||||
@@ -788,25 +790,36 @@ async function createRealProofComposition(
|
||||
const observedEvents: ObservedWorkerEvent[] = [];
|
||||
const revisions = new PiManagedInputRevisionCoordinator();
|
||||
const extensionHost = new PiManagedExtensionHost();
|
||||
const userDataDir = path.join(root, 'user-data');
|
||||
const managedPaths = await ensurePiManagedPaths(userDataDir);
|
||||
const runtimeRoot = path.join(process.resourcesPath, 'pi-runtime');
|
||||
const agentServer = new PiAgentServerProcess({
|
||||
executablePath: process.execPath,
|
||||
serverPath: path.join(process.resourcesPath, 'resources', 'pi-agent-server.mjs'),
|
||||
runtimeRoot,
|
||||
configDir: managedPaths.configDir,
|
||||
});
|
||||
tracked.push({ role: 'parent', process: agentServer });
|
||||
const account = providerAccount(provider.baseUrl);
|
||||
const loadProviderInput = async () => ({ accounts: [account], modelSummaries: [] });
|
||||
const registry = new PiSessionRegistry({ projectStore });
|
||||
const pool = new PiWorkerPool({
|
||||
maxRunning: 4,
|
||||
maxIdle: 4,
|
||||
maxIdle: 8,
|
||||
processMode: 'shared',
|
||||
processBudget,
|
||||
revisionCoordinator: revisions,
|
||||
onTelemetry: (event) => telemetry.push(event),
|
||||
openWorker: createPiManagedWorkerOpener({
|
||||
registry,
|
||||
executablePath: process.execPath,
|
||||
cliPath: path.join(process.resourcesPath, 'pi-runtime', 'dist', 'cli.js'),
|
||||
userDataDir: path.join(root, 'user-data'),
|
||||
cliPath: path.join(runtimeRoot, 'dist', 'cli.js'),
|
||||
userDataDir,
|
||||
bundledSkillsDir: path.join(process.resourcesPath, 'resources', 'coding-skills'),
|
||||
extensionHost,
|
||||
loadProviderInput,
|
||||
resolveCredential: async () => 'release-proof-local-only',
|
||||
createProcess: trackedProcessFactory('parent', tracked),
|
||||
createProcess: (options) => agentServer.createWorker(options),
|
||||
onTelemetry: (event) => telemetry.push(event),
|
||||
}),
|
||||
});
|
||||
@@ -822,8 +835,8 @@ async function createRealProofComposition(
|
||||
const childOpener = createPiManagedSubagentChildOpener({
|
||||
projectStore,
|
||||
executablePath: process.execPath,
|
||||
cliPath: path.join(process.resourcesPath, 'pi-runtime', 'dist', 'cli.js'),
|
||||
userDataDir: path.join(root, 'user-data'),
|
||||
cliPath: path.join(runtimeRoot, 'dist', 'cli.js'),
|
||||
userDataDir,
|
||||
bundledSkillsDir: path.join(process.resourcesPath, 'resources', 'coding-skills'),
|
||||
extensionHost,
|
||||
loadProviderInput,
|
||||
@@ -834,7 +847,6 @@ async function createRealProofComposition(
|
||||
const scheduler = new PiSubagentScheduler({
|
||||
processBudget,
|
||||
openChild: childOpener,
|
||||
reclaimProcessCapacity: (signal) => pool.reclaimIdleWorker(signal),
|
||||
});
|
||||
extensionHost.configureSubagents({ scheduler });
|
||||
return {
|
||||
@@ -843,6 +855,7 @@ async function createRealProofComposition(
|
||||
tracked,
|
||||
telemetry,
|
||||
observedEvents,
|
||||
agentServer,
|
||||
extensionHost,
|
||||
pool,
|
||||
scheduler,
|
||||
@@ -899,7 +912,7 @@ async function inspectWindowsPiProcesses(hostToken: string): Promise<{
|
||||
if (process.platform !== 'win32') return { supported: false, processes: [] };
|
||||
const script = `$parentPid = ${process.pid}; `
|
||||
+ '$items = @(Get-CimInstance Win32_Process -Filter "ParentProcessId = $parentPid" '
|
||||
+ '| Where-Object { $_.CommandLine -match "pi-runtime[\\\\/]dist[\\\\/]cli\\.js" } '
|
||||
+ '| Where-Object { $_.CommandLine -match "(pi-agent-server\\.mjs|pi-runtime[\\\\/]dist[\\\\/]cli\\.js)" } '
|
||||
+ '| Select-Object ProcessId, CommandLine); '
|
||||
+ '$items | ConvertTo-Json -Compress';
|
||||
const { stdout } = await execFileAsync(
|
||||
@@ -916,7 +929,9 @@ async function inspectWindowsPiProcesses(hostToken: string): Promise<{
|
||||
const processId = Number(record.ProcessId);
|
||||
const commandLine = typeof record.CommandLine === 'string' ? record.CommandLine : '';
|
||||
if (!Number.isSafeInteger(processId) || !commandLine) return [];
|
||||
const role = commandLine.includes('--no-session') ? 'child' : 'parent';
|
||||
const role = commandLine.includes('pi-agent-server.mjs') || !commandLine.includes('--no-session')
|
||||
? 'parent'
|
||||
: 'child';
|
||||
return [{
|
||||
processId,
|
||||
role,
|
||||
@@ -1156,8 +1171,8 @@ async function startPressureRun(): Promise<PressureRun> {
|
||||
}));
|
||||
await waitFor(
|
||||
() => provider.activeCounts().parent === 4
|
||||
&& processIds(composition.tracked, 'parent', true).length === 4,
|
||||
'Four real persistent Pi parents did not become active',
|
||||
&& processIds(composition.tracked, 'parent', true).length === 1,
|
||||
'Four persistent Pi parent threads did not share one active Agent Server',
|
||||
);
|
||||
for (let index = 0; index < composition.projects.length; index += 1) {
|
||||
const project = composition.projects[index] as ProofProject;
|
||||
@@ -1185,7 +1200,7 @@ async function startPressureRun(): Promise<PressureRun> {
|
||||
}
|
||||
try {
|
||||
await waitFor(
|
||||
() => composition.processBudget.activeCount === 8
|
||||
() => composition.processBudget.activeCount === 4
|
||||
&& composition.scheduler.getDiagnostics().activeChildPermits === 4
|
||||
&& provider.activeCounts().child === 4
|
||||
&& processIds(composition.tracked, 'child', true).length === 4,
|
||||
@@ -1210,10 +1225,10 @@ async function startPressureRun(): Promise<PressureRun> {
|
||||
);
|
||||
}
|
||||
const active = pressureSnapshot(composition, provider, writeLeases);
|
||||
if (active.parentProcessIds.length !== 4
|
||||
if (active.parentProcessIds.length !== 1
|
||||
|| active.childProcessIds.length !== 4
|
||||
|| active.liveProcessIds.length !== 8) {
|
||||
throw new Error(`Expected 4 real parent and 4 real child processes: ${JSON.stringify(active)}`);
|
||||
|| active.liveProcessIds.length !== 5) {
|
||||
throw new Error(`Expected 4 parent threads in 1 Agent Server plus 4 child processes: ${JSON.stringify(active)}`);
|
||||
}
|
||||
return {
|
||||
active,
|
||||
@@ -1243,6 +1258,7 @@ async function startPressureRun(): Promise<PressureRun> {
|
||||
},
|
||||
{ name: 'scheduler.close', run: async () => await composition.scheduler.close() },
|
||||
{ name: 'pool.shutdown', run: async () => await composition.pool.shutdown() },
|
||||
{ name: 'server.shutdown', run: async () => await composition.agentServer.stop() },
|
||||
{
|
||||
name: 'leases.release',
|
||||
run: () => {
|
||||
@@ -1280,6 +1296,7 @@ async function startPressureRun(): Promise<PressureRun> {
|
||||
provider.releaseAll();
|
||||
await composition.scheduler.close().catch(() => undefined);
|
||||
await composition.pool.shutdown().catch(() => undefined);
|
||||
await composition.agentServer.stop().catch(() => undefined);
|
||||
for (const lease of heldWriteLeases.splice(0)) lease.release();
|
||||
await composition.extensionHost.close().catch(() => undefined);
|
||||
await provider.close().catch(() => undefined);
|
||||
@@ -1314,7 +1331,7 @@ export async function runFinalAsarExtensionProof(): Promise<PiReleaseExtensionPr
|
||||
);
|
||||
await waitFor(
|
||||
() => composition.scheduler.getDiagnostics().activeChildPermits === 1
|
||||
&& composition.processBudget.activeCount === 2
|
||||
&& composition.processBudget.activeCount === 1
|
||||
&& provider.activeCounts().child === 1
|
||||
&& processIds(composition.tracked, 'child', true).length === 1,
|
||||
'Final packaged parent did not dispatch a real ephemeral Pi child',
|
||||
@@ -1367,6 +1384,7 @@ export async function runFinalAsarExtensionProof(): Promise<PiReleaseExtensionPr
|
||||
provider.releaseAll();
|
||||
await composition.scheduler.close().catch(() => undefined);
|
||||
await composition.pool.shutdown().catch(() => undefined);
|
||||
await composition.agentServer.stop().catch(() => undefined);
|
||||
await composition.extensionHost.close().catch(() => undefined);
|
||||
await provider.close().catch(() => undefined);
|
||||
}
|
||||
@@ -1398,7 +1416,7 @@ export async function runFinalAsarExtensionProof(): Promise<PiReleaseExtensionPr
|
||||
providerRequests: requestCounts,
|
||||
subagentStatus: 'complete',
|
||||
subagentSummary: 'REAL_CHILD_COMPLETE',
|
||||
materializedExtension: 'makelore-runtime-v3.mjs',
|
||||
materializedExtension: 'makelore-runtime-v4.mjs',
|
||||
providerFirstEventDelayMs: PROOF_PROVIDER_FIRST_EVENT_DELAY_MS,
|
||||
managedTurns,
|
||||
managedWorkerMilestones: composition.telemetry,
|
||||
|
||||
Reference in New Issue
Block a user