Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(pi): stabilize subagent runtime owner identity

DavidShen3b0762b68e58
diff --git a/packages/maker-core/src/agents/pi/__tests__/pi-subagent-runs.test.ts b/packages/maker-core/src/agents/pi/__tests__/pi-subagent-runs.test.ts
index 8a4f49b5d9..7a22b75714 100644
--- a/packages/maker-core/src/agents/pi/__tests__/pi-subagent-runs.test.ts
+++ b/packages/maker-core/src/agents/pi/__tests__/pi-subagent-runs.test.ts
@@ -732,6 +732,19 @@ describe('PI durable subagent run store', () => {
expect(piSubagentOwnerIdentity('not-an-owner')).toBeNull();
});
+ it('keeps the owner id stable when later start-time samples cross a rounding boundary', () => {
+ const nowSpy = vi.spyOn(Date, 'now')
+ .mockReturnValueOnce(1_700_000_100_499)
+ .mockReturnValueOnce(1_700_000_100_501);
+ const uptimeSpy = vi.spyOn(process, 'uptime').mockReturnValue(100);
+ restores.push(() => nowSpy.mockRestore(), () => uptimeSpy.mockRestore());
+
+ const first = piSubagentRuntimeOwnerId(process.pid, 'scope-stable');
+ const second = piSubagentRuntimeOwnerId(process.pid, 'scope-stable');
+
+ expect(second).toBe(first);
+ });
+
it('treats a recycled pid as a dead owner, so the orphan stays reclaimable', async () => {
const ownerPid = nextOwnerPid++;
stubAliveOwner(ownerPid);
diff --git a/packages/maker-core/src/agents/pi/pi-subagent-runs.ts b/packages/maker-core/src/agents/pi/pi-subagent-runs.ts
index 5048ad3409..5e3f88e94b 100644
--- a/packages/maker-core/src/agents/pi/pi-subagent-runs.ts
+++ b/packages/maker-core/src/agents/pi/pi-subagent-runs.ts
@@ -37,6 +37,8 @@ const KILL_CONFIRM_INTERVAL_MS = 200;
const RENAME_RETRY_ATTEMPTS = 10;
const RENAME_RETRY_STEP_MS = 25;
const RENAME_RETRY_MAX_MS = 100;
+/** Stable wall-clock second for this process incarnation. */
+const OWN_PROCESS_START_TIME_SEC = Math.round(Date.now() / 1000 - process.uptime());
let controlWriteSequence = 0;
function containedParentSessionId(sessionId: string): string {
@@ -1022,7 +1024,7 @@ export function piSubagentRuntimeOwnerId(hostPid: number, scopeId: string): stri
/** Wall-clock second this process started, in the form the owner id records. */
function ownProcessStartTimeSec(): number {
- return Math.round(Date.now() / 1000 - process.uptime());
+ return OWN_PROCESS_START_TIME_SEC;
}
export interface PiSubagentOwnerIdentity {