omp-antigravity-acp-provider 0.1.27 → 0.1.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/extension/auth-sync.ts +81 -30
- package/extension/commands.ts +2 -2
- package/extension/runtime.mjs +35 -11
- package/extension/session-cleanup.ts +23 -4
- package/extension/tier-connection.ts +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -18,7 +18,7 @@ This derivative adds OMP-specific provider registration, confirmed model/thinkin
|
|
|
18
18
|
The repository vendors the upstream **0.1.15** source under `extension/vendor/pi-antigravity-acp-provider` (MIT, see `extension/vendor/pi-antigravity-acp-provider/LICENSE`). The standalone artifact bundles its runtime code, supervisor and signed runtime manifest; end users need no production npm dependencies. It does not contain a copy of upstream's Git history. See [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md) for the original copyright and license notice.
|
|
19
19
|
## Status
|
|
20
20
|
|
|
21
|
-
Version 0.1.
|
|
21
|
+
Version 0.1.28 classifies macOS keychain failures explicitly, refuses a fresh Google login when the previous credential cannot be confirmed removed, and closes logout race windows so a quick re-login cannot lose its new keychain credential. It keeps the 0.1.26 session-lease, idle-runtime and 0.1.24 ownership fixes. Restart all OMP processes after upgrading so they participate in session ownership.
|
|
22
22
|
|
|
23
23
|
Version 0.1.26 supports all models advertised by the official ACP server. Earlier live inference was tested with macOS, OMP 18.12.5, upstream provider 0.1.15 and official ACP runtime 1.4.1. The 0.1.21–0.1.24 continuity fixes are verified offline, including OMP 18.13.3 catalog loading and the local OMP summarizer source. Other platforms and full interactive Refine plan behavior with a real model remain unverified.
|
|
24
24
|
|
|
@@ -57,7 +57,7 @@ Or, inside OMP:
|
|
|
57
57
|
|
|
58
58
|
Select **omp-antigravity-acp-provider** in the browser, install it, and restart OMP to load the provider.
|
|
59
59
|
|
|
60
|
-
OMP's marketplace installer currently copies Git content without installing npm dependencies. This marketplace therefore ships a small source launcher that retrieves the exact published **0.1.
|
|
60
|
+
OMP's marketplace installer currently copies Git content without installing npm dependencies. This marketplace therefore ships a small source launcher that retrieves the exact published **0.1.28** prebuilt npm adapter on first load. It disables npm install scripts and performs no local compilation. Node.js 22.19+ and npm must be on PATH. The standalone build bundles the required code and supervisor assets with no production dependencies: a clean test installation occupied approximately **2.6 MiB** (477 KiB tarball), down from roughly 150 MiB with the old dependency tree. This excludes the separately downloaded Google runtime. First preparation needs internet access; later loads reuse the installed cache without npm network access.
|
|
61
61
|
|
|
62
62
|
The launcher stores its versioned dependencies in `.runtime/` inside the installed marketplace plugin's cache directory. Uninstalling the marketplace plugin removes that cache when it is no longer referenced by another scope. Google credentials and the separately downloaded official ACP runtime are unaffected.
|
|
63
63
|
|
|
@@ -81,7 +81,7 @@ omp plugin install npm:omp-antigravity-acp-provider
|
|
|
81
81
|
To pin a specific release:
|
|
82
82
|
|
|
83
83
|
```sh
|
|
84
|
-
omp plugin install npm:omp-antigravity-acp-provider@0.1.
|
|
84
|
+
omp plugin install npm:omp-antigravity-acp-provider@0.1.28
|
|
85
85
|
```
|
|
86
86
|
|
|
87
87
|
Restart OMP after installation. The npm package includes the built adapter; users do not need esbuild or a manual build step. Disable any older ACP adapter for the same provider before loading this package.
|
package/extension/auth-sync.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
2
|
import { setTimeout as delay } from "node:timers/promises";
|
|
3
|
+
import { promisify } from "node:util";
|
|
3
4
|
import fs from "node:fs";
|
|
4
5
|
import path from "node:path";
|
|
5
6
|
import { clearAntigravityCredentials, hasAntigravityAuth, resolveAntigravityAcpDirectory } from "./runtime.mjs";
|
|
@@ -7,30 +8,54 @@ import type { TierConnection } from "./tier-connection.ts";
|
|
|
7
8
|
|
|
8
9
|
export const MARKER = "pi-antigravity-acp:managed-by-antigravity";
|
|
9
10
|
|
|
11
|
+
const execFileAsync = promisify(execFile);
|
|
12
|
+
|
|
13
|
+
// The real /usr/bin/security subprocess boundary, with its own binary
|
|
14
|
+
// parameter so tests can drive a stub executable through the same code path.
|
|
15
|
+
// Captured stderr is matched in memory only; it is never logged or persisted.
|
|
16
|
+
export function runSecurity(args: string[], bin = "/usr/bin/security"): Promise<void> {
|
|
17
|
+
return execFileAsync(bin, args, { stdio: ["ignore", "ignore", "pipe"], timeout: 3000 }).then(() => undefined);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// errSecItemNotFound reaches the caller as exit code 44 (OSStatus -25300
|
|
21
|
+
// truncated to 8 bits). The stderr wording separates it from any other
|
|
22
|
+
// OSStatus whose truncated code also lands on 44.
|
|
23
|
+
function isConfirmedMissing(error: unknown): boolean {
|
|
24
|
+
if (!error || typeof error !== "object") return false;
|
|
25
|
+
const detail = error as { killed?: unknown; signal?: unknown; code?: unknown; stderr?: unknown };
|
|
26
|
+
return detail.killed !== true && detail.signal == null && detail.code === 44
|
|
27
|
+
&& typeof detail.stderr === "string" && /could not be found/.test(detail.stderr);
|
|
28
|
+
}
|
|
29
|
+
|
|
10
30
|
// macOS keychain operations behind one mutable object so offline command
|
|
11
31
|
// tests can substitute them without touching the user's real keychain.
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
32
|
+
// present/remove resolve to true (present / removed), false (confirmed
|
|
33
|
+
// absent), or undefined (not macOS); any other subprocess failure rejects
|
|
34
|
+
// with a fixed credential-free message.
|
|
35
|
+
export function createKeychain(run: (args: string[]) => Promise<void>, platform: NodeJS.Platform = process.platform) {
|
|
36
|
+
const check = async (args: string[], failure: string): Promise<boolean | undefined> => {
|
|
37
|
+
if (platform !== "darwin") return undefined;
|
|
16
38
|
try {
|
|
17
|
-
|
|
39
|
+
await run(args);
|
|
18
40
|
return true;
|
|
19
|
-
} catch {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
};
|
|
41
|
+
} catch (error) {
|
|
42
|
+
if (isConfirmedMissing(error)) return false;
|
|
43
|
+
throw new Error(failure);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
return {
|
|
47
|
+
// Check existence only: the item's ACL does not authorize the security
|
|
48
|
+
// CLI, so a `find-generic-password -w` would pop the macOS keychain
|
|
49
|
+
// password dialog. Attribute-only lookups stay prompt-free.
|
|
50
|
+
present: (): Promise<boolean | undefined> => check(["find-generic-password", "-s", "gemini", "-a", "antigravity-acp"], "Unable to inspect the Antigravity keychain entry"),
|
|
51
|
+
// Local logout for macOS keychain storage. The Antigravity server owns
|
|
52
|
+
// this item; removing it is required for a complete logout when no token
|
|
53
|
+
// file exists.
|
|
54
|
+
remove: (): Promise<boolean | undefined> => check(["delete-generic-password", "-s", "gemini", "-a", "antigravity-acp"], "Unable to remove the Antigravity keychain entry"),
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export const keychain = createKeychain(runSecurity);
|
|
34
59
|
|
|
35
60
|
function emailFromTokenJson(raw: string): string | undefined {
|
|
36
61
|
try {
|
|
@@ -68,8 +93,8 @@ export function formatLogoutSummary(options: { keychainRemoved: boolean | undefi
|
|
|
68
93
|
(options.keychainRemoved === false ? " The macOS keychain entry was not present or not removable." : "");
|
|
69
94
|
}
|
|
70
95
|
|
|
71
|
-
export function authReady(): boolean {
|
|
72
|
-
return hasAntigravityAuth() || keychain.present() === true;
|
|
96
|
+
export async function authReady(): Promise<boolean> {
|
|
97
|
+
return hasAntigravityAuth() || (await keychain.present()) === true;
|
|
73
98
|
}
|
|
74
99
|
|
|
75
100
|
export interface OmpCommandContext {
|
|
@@ -167,12 +192,12 @@ export class OmpAuthCoordinator {
|
|
|
167
192
|
await Promise.race([Promise.allSettled(pending), delay(10_000)]);
|
|
168
193
|
}
|
|
169
194
|
for (let attempt = 0; attempt < 3; attempt++) {
|
|
170
|
-
if (keychain.present() === false) return true;
|
|
171
|
-
const removed = keychain.remove();
|
|
195
|
+
if ((await keychain.present()) === false) return true;
|
|
196
|
+
const removed = await keychain.remove();
|
|
172
197
|
if (removed !== true) return removed;
|
|
173
198
|
await delay(400);
|
|
174
199
|
}
|
|
175
|
-
return keychain.present() === false;
|
|
200
|
+
return (await keychain.present()) === false;
|
|
176
201
|
}
|
|
177
202
|
|
|
178
203
|
// /login must mean a fresh Google sign-in: drop stored credentials (and this
|
|
@@ -203,7 +228,11 @@ export class OmpAuthCoordinator {
|
|
|
203
228
|
// mappings. OMP retains its transcript for a fresh backend reconstruction.
|
|
204
229
|
await this.deps.logoutAllRuntimes();
|
|
205
230
|
clearAntigravityCredentials();
|
|
206
|
-
|
|
231
|
+
// The old keychain entry must be gone before a new sign-in can start; an
|
|
232
|
+
// unconfirmed removal refuses the login instead of silently reusing it.
|
|
233
|
+
if (await this.removeKeychainCredentialDurably() === false) {
|
|
234
|
+
throw new Error("Unable to confirm removal of the Antigravity keychain entry");
|
|
235
|
+
}
|
|
207
236
|
}
|
|
208
237
|
|
|
209
238
|
async performCommandLogout(ctx: OmpCommandContext): Promise<{ keychainRemoved: boolean | undefined; ompMarker: "removed" | "absent" | "unavailable" }> {
|
|
@@ -220,7 +249,16 @@ export class OmpAuthCoordinator {
|
|
|
220
249
|
// Removing the marker ourselves must not trigger the follow-up logout.
|
|
221
250
|
this.selfLogout = true;
|
|
222
251
|
let ompMarker: "removed" | "absent" | "unavailable";
|
|
223
|
-
try {
|
|
252
|
+
try {
|
|
253
|
+
ompMarker = await removeOmpCredentialRecord(ctx);
|
|
254
|
+
if (ompMarker !== "unavailable") {
|
|
255
|
+
// A generation event firing after the selfLogout window would compare
|
|
256
|
+
// against a stale markerPresent and schedule a redundant follow-up.
|
|
257
|
+
this.markerPresent = this.ompMarkerStored(ctx);
|
|
258
|
+
clearTimeout(this.followTimer);
|
|
259
|
+
this.followTimer = undefined;
|
|
260
|
+
}
|
|
261
|
+
} finally { this.selfLogout = false; }
|
|
224
262
|
if (ompMarker !== "unavailable") {
|
|
225
263
|
// Drop the config apiKey with the marker even without the watcher.
|
|
226
264
|
this.apiKeyFallback = false;
|
|
@@ -235,13 +273,16 @@ export class OmpAuthCoordinator {
|
|
|
235
273
|
clearTimeout(this.followRetry);
|
|
236
274
|
this.followRetry = setTimeout(() => {
|
|
237
275
|
this.followRetry = undefined;
|
|
238
|
-
if (this.ompMarkerStored(ctx) === false)
|
|
276
|
+
if (this.ompMarkerStored(ctx) === false) this.runFollowedLogout(ctx);
|
|
239
277
|
}, logoutFollow.retryMs);
|
|
240
278
|
this.followRetry.unref?.();
|
|
241
279
|
return;
|
|
242
280
|
}
|
|
243
281
|
await this.deps.logoutAllRuntimes();
|
|
244
282
|
await this.deps.closeAllRuntimes();
|
|
283
|
+
// A quick re-login can restore the marker while the steps above await;
|
|
284
|
+
// a restored or unknown marker keeps the new keychain entry untouched.
|
|
285
|
+
if (this.ompMarkerStored(ctx) !== false) return;
|
|
245
286
|
const keychainRemoved = await this.removeKeychainCredentialDurably();
|
|
246
287
|
// Keep the confirmation terse; /antigravity-acp account shows the details.
|
|
247
288
|
try {
|
|
@@ -249,6 +290,16 @@ export class OmpAuthCoordinator {
|
|
|
249
290
|
} catch { /* the host UI may already be gone */ }
|
|
250
291
|
}
|
|
251
292
|
|
|
293
|
+
// The follow-up runs detached from timer callbacks; a failure must not
|
|
294
|
+
// become an unhandled rejection, and the notice stays credential-free.
|
|
295
|
+
private runFollowedLogout(ctx: OmpCommandContext): void {
|
|
296
|
+
void this.finishFollowedLogout(ctx).catch(() => {
|
|
297
|
+
try {
|
|
298
|
+
ctx?.ui?.notify?.("Antigravity ACP: the logout OMP started could not be finished. Run /antigravity-acp logout to retry.", "error");
|
|
299
|
+
} catch { /* the host UI may already be gone */ }
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
|
|
252
303
|
watchOmpCredentials(ctx: OmpCommandContext | undefined): void {
|
|
253
304
|
if (this.watchingCredentials || !ctx) return;
|
|
254
305
|
const credentials = ctx.modelRegistry?.authStorage?.credentials;
|
|
@@ -296,7 +347,7 @@ export class OmpAuthCoordinator {
|
|
|
296
347
|
this.deps.onSyncProvider();
|
|
297
348
|
return;
|
|
298
349
|
}
|
|
299
|
-
|
|
350
|
+
this.runFollowedLogout(ctx);
|
|
300
351
|
}, logoutFollow.delayMs);
|
|
301
352
|
this.followTimer.unref?.();
|
|
302
353
|
});
|
package/extension/commands.ts
CHANGED
|
@@ -238,7 +238,7 @@ export function createAntigravityCommandHandler(deps: CommandControllerDeps) {
|
|
|
238
238
|
// fields, with OMP-specific lines in the same style.
|
|
239
239
|
ctx.ui.notify([
|
|
240
240
|
"Antigravity ACP account",
|
|
241
|
-
`Google account: ${antigravityAccountEmail() ?? (keychain.present() === true ? "signed in (token in macOS keychain; email not read)" : "not signed in")}`,
|
|
241
|
+
`Google account: ${antigravityAccountEmail() ?? ((await keychain.present()) === true ? "signed in (token in macOS keychain; email not read)" : "not signed in")}`,
|
|
242
242
|
`Authentication: ${auth.status}${auth.authType ? ` (${auth.authType})` : ""}`,
|
|
243
243
|
`Credential storage (preflight): ${describeCredentialStorage()}`,
|
|
244
244
|
`OMP marker record: ${marker}`,
|
|
@@ -302,6 +302,6 @@ export function createAntigravityCommandHandler(deps: CommandControllerDeps) {
|
|
|
302
302
|
}
|
|
303
303
|
|
|
304
304
|
const policy = deps.getToolPolicy();
|
|
305
|
-
ctx.ui.notify(`Antigravity ACP (OMP adapter)\nAuth storage: ${authReady() ? "configured (ACP-owned token file or macOS keychain)" : inspectAntigravityAuth().status}\nPermissions: ${snapshot.permissionMode}\nNative tools: ${policy.nativeTools}\nDebug tool updates: ${policy.debugToolUpdates ? "on" : "off"}\nTool routing: ${JSON.stringify([...deps.connections].map(connection => connection.toolRouting).filter(Boolean))}\nActive sessions: ${snapshot.bindings}\nConfirmed thinking: ${JSON.stringify([...deps.connections].map(connection => connection.confirmedThinking).filter(Boolean))}\nUsage: ${JSON.stringify(snapshot.metrics)}\n${JSON.stringify(snapshot.processes)}`, "info");
|
|
305
|
+
ctx.ui.notify(`Antigravity ACP (OMP adapter)\nAuth storage: ${(await authReady()) ? "configured (ACP-owned token file or macOS keychain)" : inspectAntigravityAuth().status}\nPermissions: ${snapshot.permissionMode}\nNative tools: ${policy.nativeTools}\nDebug tool updates: ${policy.debugToolUpdates ? "on" : "off"}\nTool routing: ${JSON.stringify([...deps.connections].map(connection => connection.toolRouting).filter(Boolean))}\nActive sessions: ${snapshot.bindings}\nConfirmed thinking: ${JSON.stringify([...deps.connections].map(connection => connection.confirmedThinking).filter(Boolean))}\nUsage: ${JSON.stringify(snapshot.metrics)}\n${JSON.stringify(snapshot.processes)}`, "info");
|
|
306
306
|
};
|
|
307
307
|
}
|
package/extension/runtime.mjs
CHANGED
|
@@ -60021,13 +60021,16 @@ var AntigravityRuntime = class {
|
|
|
60021
60021
|
await this.invalidateBinding(binding);
|
|
60022
60022
|
binding = await this.getBinding(key, model, acpModelId, options.apiKey, writer, tools, options.signal);
|
|
60023
60023
|
}
|
|
60024
|
-
if (
|
|
60025
|
-
|
|
60026
|
-
|
|
60027
|
-
|
|
60028
|
-
await
|
|
60024
|
+
if (binding.turnCompletion || binding.permission || binding.pendingTools.size > 0) {
|
|
60025
|
+
let ompPrefixFingerprint;
|
|
60026
|
+
if (context.messages.findLastIndex((message) => message.role === "user") >= binding.pendingContextCount || (ompPrefixFingerprint = this.ompMessagesFingerprint(context.messages.slice(0, binding.pendingContextCount))) !== binding.pendingContextFingerprint) {
|
|
60027
|
+
const prefixMatches = context.messages.length >= binding.pendingContextCount && (ompPrefixFingerprint ?? this.ompMessagesFingerprint(context.messages.slice(0, binding.pendingContextCount))) === binding.pendingContextFingerprint;
|
|
60028
|
+
const drained = prefixMatches && await drainCancelledTurn(binding, () => abortTurn(binding), options.signal);
|
|
60029
|
+
if (!drained || !binding.connection.process.alive || binding.needsReconstruction || !["cancelled", "end_turn"].includes(binding.ompTerminalStopReason)) {
|
|
60030
|
+
await this.invalidateBinding(binding);
|
|
60031
|
+
}
|
|
60032
|
+
binding = await this.getBinding(key, model, acpModelId, options.apiKey, writer, tools, options.signal);
|
|
60029
60033
|
}
|
|
60030
|
-
binding = await this.getBinding(key, model, acpModelId, options.apiKey, writer, tools, options.signal);
|
|
60031
60034
|
}
|
|
60032
60035
|
if (binding.turnCompletion && !binding.abortRequested && context.messages.length === binding.pendingContextCount && this.ompMessagesFingerprint(context.messages) === binding.pendingContextFingerprint) {
|
|
60033
60036
|
throw new AntigravityAcpError("invalid_input", "ACP request/continuation is already in progress for this session");
|
|
@@ -61077,7 +61080,7 @@ var TierConnection = class extends AntigravityAcpConnection {
|
|
|
61077
61080
|
}
|
|
61078
61081
|
async protectSession(id) {
|
|
61079
61082
|
if (this.cleanup && !this.cleanupLeases.has(id)) {
|
|
61080
|
-
this.cleanupLeases.set(id, await this.cleanup.acquire(id, false, this.process.pid));
|
|
61083
|
+
this.cleanupLeases.set(id, await this.cleanup.acquire(id, false, this.process.pid, 5e3));
|
|
61081
61084
|
}
|
|
61082
61085
|
}
|
|
61083
61086
|
async resumeSession(...args) {
|
|
@@ -61369,6 +61372,16 @@ var SessionCleanup = class {
|
|
|
61369
61372
|
collecting;
|
|
61370
61373
|
touched = /* @__PURE__ */ new Map();
|
|
61371
61374
|
intents = [];
|
|
61375
|
+
// Lock-wait budget clock, kept separate from the constructor's policy
|
|
61376
|
+
// clock: advancing retention time must never spend a lock budget, and
|
|
61377
|
+
// advancing a lock budget must never age out sessions.
|
|
61378
|
+
acquireRetry = {
|
|
61379
|
+
now: Date.now,
|
|
61380
|
+
sleep: (ms) => new Promise((resolve) => {
|
|
61381
|
+
const timer = setTimeout(resolve, ms);
|
|
61382
|
+
timer.unref?.();
|
|
61383
|
+
})
|
|
61384
|
+
};
|
|
61372
61385
|
report = { owned: 0, active: 0, mapped: 0, unmapped: 0, ownedBytes: 0, overBudget: false, removed: 0, reclaimedBytes: 0, retainedForRecovery: 0, failures: 0, deferred: 0 };
|
|
61373
61386
|
configure(mode, idleDays) {
|
|
61374
61387
|
const policy = loadCleanupPolicy(this.policyPath);
|
|
@@ -61395,7 +61408,8 @@ var SessionCleanup = class {
|
|
|
61395
61408
|
if (await sourceId(file2) !== id) return;
|
|
61396
61409
|
await this.transaction(async (registry2) => {
|
|
61397
61410
|
const mappings = await this.sessionStore.list();
|
|
61398
|
-
|
|
61411
|
+
const mappedAcpIds = new Set(mappings.filter((m) => m.piSessionId === id).map((m) => m.acpSessionId));
|
|
61412
|
+
for (const record3 of registry2.sessions) if (record3.owned && mappedAcpIds.has(record3.id)) {
|
|
61399
61413
|
record3.ompSource = { id, file: path10.resolve(file2), root, device: stat.dev, inode: stat.ino };
|
|
61400
61414
|
delete record3.sourceDeleted;
|
|
61401
61415
|
}
|
|
@@ -61460,9 +61474,9 @@ var SessionCleanup = class {
|
|
|
61460
61474
|
});
|
|
61461
61475
|
return pending;
|
|
61462
61476
|
}
|
|
61463
|
-
async acquire(id, owned, serverPid) {
|
|
61477
|
+
async acquire(id, owned, serverPid, lockWaitMs = 0) {
|
|
61464
61478
|
if (!UUID.test(id) || !Number.isSafeInteger(serverPid) || serverPid <= 0) throw new Error("Invalid ACP cleanup lease");
|
|
61465
|
-
|
|
61479
|
+
const action = (r) => {
|
|
61466
61480
|
let v = r.sessions.find((v2) => v2.id === id);
|
|
61467
61481
|
if (!v) {
|
|
61468
61482
|
v = { id, owned, lastUsed: this.now(), leases: [] };
|
|
@@ -61475,7 +61489,17 @@ var SessionCleanup = class {
|
|
|
61475
61489
|
delete v.orphanedAt;
|
|
61476
61490
|
this.touched.set(id, v.lastUsed);
|
|
61477
61491
|
return token2;
|
|
61478
|
-
}
|
|
61492
|
+
};
|
|
61493
|
+
const deadline = this.acquireRetry.now() + lockWaitMs;
|
|
61494
|
+
for (; ; ) {
|
|
61495
|
+
try {
|
|
61496
|
+
return await this.transaction(action);
|
|
61497
|
+
} catch (error62) {
|
|
61498
|
+
if (error62.code !== "ELOCKED" || lockWaitMs <= 0) throw error62;
|
|
61499
|
+
if (this.acquireRetry.now() >= deadline) throw new Error("Timed out acquiring the ACP cleanup lease", { cause: error62 });
|
|
61500
|
+
await this.acquireRetry.sleep(10);
|
|
61501
|
+
}
|
|
61502
|
+
}
|
|
61479
61503
|
}
|
|
61480
61504
|
async intent(action) {
|
|
61481
61505
|
if (this.intents.length >= 1024) throw new Error("Lifecycle retry queue full; preserving files");
|
|
@@ -38,6 +38,13 @@ export class SessionCleanup {
|
|
|
38
38
|
private collecting?: Promise<number>;
|
|
39
39
|
private readonly touched = new Map<string, number>();
|
|
40
40
|
private readonly intents: Array<(r: Registry) => void> = [];
|
|
41
|
+
// Lock-wait budget clock, kept separate from the constructor's policy
|
|
42
|
+
// clock: advancing retention time must never spend a lock budget, and
|
|
43
|
+
// advancing a lock budget must never age out sessions.
|
|
44
|
+
private acquireRetry: { now: () => number; sleep: (ms: number) => Promise<void> } = {
|
|
45
|
+
now: Date.now,
|
|
46
|
+
sleep: ms => new Promise<void>(resolve => { const timer = setTimeout(resolve, ms); timer.unref?.(); }),
|
|
47
|
+
};
|
|
41
48
|
private report = { owned: 0, active: 0, mapped: 0, unmapped: 0, ownedBytes: 0, overBudget: false, removed: 0, reclaimedBytes: 0, retainedForRecovery: 0, failures: 0, deferred: 0 };
|
|
42
49
|
constructor(private readonly stateDir: string, readonly acpDir = resolveAntigravityAcpDirectory(), private readonly now = Date.now, private readonly isLive = live) {
|
|
43
50
|
this.policyPath = path.join(stateDir, "cleanup.json");
|
|
@@ -60,7 +67,8 @@ export class SessionCleanup {
|
|
|
60
67
|
if (await sourceId(file) !== id) return;
|
|
61
68
|
await this.transaction(async registry => {
|
|
62
69
|
const mappings = await this.sessionStore.list();
|
|
63
|
-
|
|
70
|
+
const mappedAcpIds = new Set(mappings.filter(m => m.piSessionId === id).map(m => m.acpSessionId));
|
|
71
|
+
for (const record of registry.sessions) if (record.owned && mappedAcpIds.has(record.id)) {
|
|
64
72
|
record.ompSource = { id, file: path.resolve(file), root, device: stat.dev, inode: stat.ino };
|
|
65
73
|
delete record.sourceDeleted;
|
|
66
74
|
}
|
|
@@ -99,15 +107,26 @@ export class SessionCleanup {
|
|
|
99
107
|
void pending.finally(() => { if (tails.get(this.registryPath) === pending) tails.delete(this.registryPath); }).catch(() => {});
|
|
100
108
|
return pending;
|
|
101
109
|
}
|
|
102
|
-
async acquire(id: string, owned: boolean, serverPid: number) {
|
|
110
|
+
async acquire(id: string, owned: boolean, serverPid: number, lockWaitMs = 0): Promise<string> {
|
|
103
111
|
if (!UUID.test(id) || !Number.isSafeInteger(serverPid) || serverPid <= 0) throw new Error("Invalid ACP cleanup lease");
|
|
104
|
-
|
|
112
|
+
const action = (r: Registry): string => {
|
|
105
113
|
let v = r.sessions.find(v => v.id === id);
|
|
106
114
|
if (!v) { v = { id, owned, lastUsed: this.now(), leases: [] }; r.sessions.push(v); }
|
|
107
115
|
if (v.disposableFor) throw new Error("ACP session was finally released; reconstruct a new session from OMP history");
|
|
108
116
|
const token = randomUUID(); v.leases.push({ token, pid: process.pid, serverPid }); v.lastUsed = this.now(); delete v.orphanedAt;
|
|
109
117
|
this.touched.set(id, v.lastUsed); return token;
|
|
110
|
-
}
|
|
118
|
+
};
|
|
119
|
+
// Only the recovery path passes a budget; every other caller keeps the
|
|
120
|
+
// raw ELOCKED identity and fails fast instead of queueing behind contention.
|
|
121
|
+
const deadline = this.acquireRetry.now() + lockWaitMs;
|
|
122
|
+
for (;;) {
|
|
123
|
+
try { return await this.transaction(action); }
|
|
124
|
+
catch (error) {
|
|
125
|
+
if ((error as NodeJS.ErrnoException).code !== "ELOCKED" || lockWaitMs <= 0) throw error;
|
|
126
|
+
if (this.acquireRetry.now() >= deadline) throw new Error("Timed out acquiring the ACP cleanup lease", { cause: error });
|
|
127
|
+
await this.acquireRetry.sleep(10);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
111
130
|
}
|
|
112
131
|
private async intent(action: (r: Registry) => void) {
|
|
113
132
|
if (this.intents.length >= 1024) throw new Error("Lifecycle retry queue full; preserving files");
|
|
@@ -90,7 +90,7 @@ export class TierConnection extends AntigravityAcpConnection {
|
|
|
90
90
|
private async protectSession(id: string) {
|
|
91
91
|
if (this.cleanup && !this.cleanupLeases.has(id)) {
|
|
92
92
|
// Lease before the resume/load RPC, including while the server replays.
|
|
93
|
-
this.cleanupLeases.set(id, await this.cleanup.acquire(id, false, this.process.pid
|
|
93
|
+
this.cleanupLeases.set(id, await this.cleanup.acquire(id, false, this.process.pid!, 5000));
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
96
|
override async resumeSession(...args: Parameters<AntigravityAcpConnection["resumeSession"]>) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "omp-antigravity-acp-provider",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.28",
|
|
4
4
|
"ompAcpBundle": 1,
|
|
5
5
|
"description": "Google Antigravity ACP provider for Oh My Pi (OMP), with tool bridging and per-model thinking; derived from zacbemis/pi-antigravity-acp-provider",
|
|
6
6
|
"type": "module",
|