@gobing-ai/knowledge-kit 0.1.25 → 0.1.27
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/.claude-plugin/marketplace.json +1 -1
- package/dist/index.js +115 -21
- package/package.json +1 -1
- package/plugins/kk/plugin.json +1 -1
- package/plugins/kk/scripts/cn-lead-gate.ts +494 -0
- package/plugins/kk/scripts/daily-stages.ts +416 -134
- package/plugins/kk/scripts/kk-workflow-stages.ts +53 -3
- package/plugins/kk/skills/news-editorial/SKILL.md +20 -3
- package/plugins/kk/skills/news-editorial/references/selection.md +42 -0
- package/plugins/publishings/bilibili-pub/dist/index.js +33 -2
- package/plugins/publishings/bilibili-pub/dist/profile-check.js +33 -2
- package/plugins/publishings/cnblogs-pub/dist/index.js +33 -2
- package/plugins/publishings/cnblogs-pub/dist/profile-check.js +33 -2
- package/plugins/publishings/csdn-pub/dist/index.js +33 -2
- package/plugins/publishings/csdn-pub/dist/profile-check.js +33 -2
- package/plugins/publishings/infoq-pub/dist/index.js +33 -2
- package/plugins/publishings/infoq-pub/dist/profile-check.js +33 -2
- package/plugins/publishings/jike-pub/dist/index.js +33 -2
- package/plugins/publishings/jike-pub/dist/profile-check.js +33 -2
- package/plugins/publishings/juejin-pub/dist/index.js +33 -2
- package/plugins/publishings/juejin-pub/dist/profile-check.js +33 -2
- package/plugins/publishings/linkedin-pub/dist/index.js +84 -13
- package/plugins/publishings/linkedin-pub/dist/profile-check.js +50 -5
- package/plugins/publishings/linkedin-pub/src/index.ts +126 -9
- package/plugins/publishings/medium-pub/dist/index.js +33 -2
- package/plugins/publishings/medium-pub/dist/profile-check.js +33 -2
- package/plugins/publishings/shipinhao-pub/dist/index.js +33 -2
- package/plugins/publishings/shipinhao-pub/dist/profile-check.js +33 -2
- package/plugins/publishings/sspai-pub/dist/index.js +33 -2
- package/plugins/publishings/sspai-pub/dist/profile-check.js +33 -2
- package/plugins/publishings/substack-pub/dist/index.js +33 -2
- package/plugins/publishings/substack-pub/dist/profile-check.js +33 -2
- package/plugins/publishings/surfdash-pub/dist/index.js +53 -15
- package/plugins/publishings/surfdash-pub/src/index.ts +31 -4
- package/plugins/publishings/surfdash-pub/src/patch.ts +81 -12
- package/plugins/publishings/threads-pub/dist/index.js +33 -2
- package/plugins/publishings/threads-pub/dist/profile-check.js +33 -2
- package/plugins/publishings/wechatmp-pub/dist/index.js +65 -3
- package/plugins/publishings/wechatmp-pub/dist/profile-check.js +67 -3
- package/plugins/publishings/wechatmp-pub/src/index.ts +64 -1
- package/plugins/publishings/weibo-pub/dist/index.js +56 -8
- package/plugins/publishings/weibo-pub/dist/profile-check.js +55 -8
- package/plugins/publishings/weibo-pub/plugin.json +1 -1
- package/plugins/publishings/weibo-pub/src/index.ts +76 -8
- package/plugins/publishings/x-pub/dist/index.js +33 -2
- package/plugins/publishings/x-pub/dist/profile-check.js +33 -2
- package/plugins/publishings/xhs-pub/dist/index.js +33 -2
- package/plugins/publishings/xhs-pub/dist/profile-check.js +33 -2
- package/plugins/publishings/xiaoyuzhou-pub/dist/index.js +33 -2
- package/plugins/publishings/xiaoyuzhou-pub/dist/profile-check.js +33 -2
|
@@ -85,6 +85,10 @@ export const LINKEDIN_POST_SELECTORS = {
|
|
|
85
85
|
// clicking THAT does not open the composer (the run then timed out in the composer stage and
|
|
86
86
|
// reported "composer did not open … selector drift"). The has-text forms hit the clickable
|
|
87
87
|
// ancestor; the text form stays last for the previous UI.
|
|
88
|
+
// Measured 2026-11-25 (0437 recon, `.spur/run/dogfood/2026-11-25-linkedin/`): no `<button>` carries
|
|
89
|
+
// the text any more — the one visible trigger is `div[role=button][aria-label="Start a post"]`
|
|
90
|
+
// with obfuscated classes. The exact aria form leads so no descendant-text match can win.
|
|
91
|
+
'div[role="button"][aria-label="Start a post"]',
|
|
88
92
|
'button:has-text("Start a post")',
|
|
89
93
|
'div[role="button"]:has-text("Start a post")',
|
|
90
94
|
'text="Start a post"',
|
|
@@ -101,7 +105,6 @@ export const LINKEDIN_POST_SELECTORS = {
|
|
|
101
105
|
'.tiptap.ProseMirror',
|
|
102
106
|
'[role="dialog"] div[role="textbox"]',
|
|
103
107
|
'div.editor-content[contenteditable="true"]',
|
|
104
|
-
'div[role="textbox"][contenteditable="true"]',
|
|
105
108
|
],
|
|
106
109
|
mediaButton: [
|
|
107
110
|
'button[aria-label="Media"]',
|
|
@@ -134,6 +137,15 @@ const PREVIEW_POLL_MS = 250;
|
|
|
134
137
|
const LINK_PREVIEW_TIMEOUT_MS = 10_000;
|
|
135
138
|
|
|
136
139
|
const STEP_TIMEOUT_MS = 30_000;
|
|
140
|
+
/**
|
|
141
|
+
* Default budget for the read-only session preflight. The harness subtracts a print margin and a
|
|
142
|
+
* launch reserve from whatever it is given, so the 30 s STEP_TIMEOUT_MS became an ~18 s pass — and on
|
|
143
|
+
* 2026-11-24 that was short enough that a freshly signed-in profile reported "not confirmed", after
|
|
144
|
+
* which LinkedIn cleared `li_at` and the sign-in was lost. 90 s covers a cold headed feed load.
|
|
145
|
+
* An explicit `stepTimeoutMs` dep overrides it, so tests and callers that tune the step budget also
|
|
146
|
+
* tune the preflight.
|
|
147
|
+
*/
|
|
148
|
+
const PREFLIGHT_TIMEOUT_MS = 90_000;
|
|
137
149
|
const LOGIN_TIMEOUT_MS = 180_000;
|
|
138
150
|
/** Operator recovery command every session failure names — never a cookie, DOM dump or stack. */
|
|
139
151
|
export const LINKEDIN_LOGIN_INSTRUCTION = 'bun plugins/publishings/linkedin-pub/src/profile-check.ts login';
|
|
@@ -154,6 +166,45 @@ function stageFail(error: string, stage: string, metadata: Record<string, unknow
|
|
|
154
166
|
});
|
|
155
167
|
}
|
|
156
168
|
|
|
169
|
+
/**
|
|
170
|
+
* A stage failure raised before the Post click: nothing reached LinkedIn, so the receipt is
|
|
171
|
+
* `failed/none` and `--retry` resends without `--confirm-none` (0437 R4; same marker as
|
|
172
|
+
* `weibo-pub`'s `refuse`). Never used at or after the Post click — those stay `effect: unknown`.
|
|
173
|
+
*/
|
|
174
|
+
function preSubmitFail(error: string, stage: string, metadata: Record<string, unknown>): Result {
|
|
175
|
+
return stageFail(error, stage, { ...metadata, itcDelivery: { schemaVersion: 1, effect: 'none' } });
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* What the page held when the composer never opened (0437 R2): match counts of the trigger that was
|
|
180
|
+
* clicked, every composer candidate's count, the url and the frame count — so the next drift is
|
|
181
|
+
* diagnosable from the receipt alone. Counts only: no DOM text ever leaves the page.
|
|
182
|
+
*/
|
|
183
|
+
async function probeComposer(
|
|
184
|
+
page: Page,
|
|
185
|
+
trigger: string,
|
|
186
|
+
): Promise<{
|
|
187
|
+
trigger: string;
|
|
188
|
+
triggerMatches: number;
|
|
189
|
+
triggerVisible: number;
|
|
190
|
+
candidates: Record<string, number>;
|
|
191
|
+
url: string;
|
|
192
|
+
frames: number;
|
|
193
|
+
}> {
|
|
194
|
+
const count = (locator: { count(): Promise<number> }) => locator.count().catch(() => -1);
|
|
195
|
+
const triggerLocator = page.locator(trigger);
|
|
196
|
+
const candidates: Record<string, number> = {};
|
|
197
|
+
for (const selector of LINKEDIN_POST_SELECTORS.composer) candidates[selector] = await count(page.locator(selector));
|
|
198
|
+
return {
|
|
199
|
+
trigger,
|
|
200
|
+
triggerMatches: await count(triggerLocator),
|
|
201
|
+
triggerVisible: await count(triggerLocator.filter({ visible: true })),
|
|
202
|
+
candidates,
|
|
203
|
+
url: page.url(),
|
|
204
|
+
frames: typeof page.frames === 'function' ? page.frames().length : 0,
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
|
|
157
208
|
/** One short line, bounded: no DOM dump, cookie, token or stack ever reaches the Result. */
|
|
158
209
|
function boundedDetail(detail: string): string {
|
|
159
210
|
return detail.replace(/\s+/g, ' ').trim().slice(0, 300);
|
|
@@ -229,6 +280,36 @@ export const isLinkedinAuthenticated: IsAuthenticatedPredicate = async (page) =>
|
|
|
229
280
|
}
|
|
230
281
|
};
|
|
231
282
|
|
|
283
|
+
/**
|
|
284
|
+
* LinkedIn's session ticket. The readiness predicate only sees the rendered page, so a profile can
|
|
285
|
+
* pass it and still carry no session at all — the measured 2026-11-24 shape was `li_at` at 0 rows
|
|
286
|
+
* (`select count(*) from cookies where name='li_at'`) after two separate operator sign-ins. Name
|
|
287
|
+
* only: this module never reads, logs or returns the value.
|
|
288
|
+
*/
|
|
289
|
+
export const LINKEDIN_AUTH_COOKIE = 'li_at';
|
|
290
|
+
|
|
291
|
+
/** The cookie facts this assertion reads — everything but the value. */
|
|
292
|
+
export interface StoredCookie {
|
|
293
|
+
name: string;
|
|
294
|
+
value?: string;
|
|
295
|
+
/** Seconds since the epoch; Playwright reports a session cookie as `-1`. */
|
|
296
|
+
expires?: number;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* `true` when the jar holds a usable {@link LINKEDIN_AUTH_COOKIE} (0436 R4). A non-empty value that
|
|
301
|
+
* has not expired is the whole test: an expired or empty ticket cannot authenticate anything, so
|
|
302
|
+
* reporting a login from it would leave exactly the profile every later check calls "expired".
|
|
303
|
+
*/
|
|
304
|
+
export function hasLinkedinAuthCookie(cookies: readonly StoredCookie[], nowMs: number = Date.now()): boolean {
|
|
305
|
+
return cookies.some(
|
|
306
|
+
(cookie) =>
|
|
307
|
+
cookie.name === LINKEDIN_AUTH_COOKIE &&
|
|
308
|
+
(cookie.value ?? '') !== '' &&
|
|
309
|
+
(cookie.expires === undefined || cookie.expires <= 0 || cookie.expires * 1000 > nowMs),
|
|
310
|
+
);
|
|
311
|
+
}
|
|
312
|
+
|
|
232
313
|
/**
|
|
233
314
|
* Site-owned config for the shared session check and operator CLI (ADR-032). The publish preflight
|
|
234
315
|
* never forwards a headed fallback: it is the operator CLI's setting, and a refusal must never
|
|
@@ -239,6 +320,28 @@ export const LINKEDIN_CONFIG: ChannelBrowserConfig = {
|
|
|
239
320
|
homeUrl: LINKEDIN_HOME_URL,
|
|
240
321
|
isAuthenticated: isLinkedinAuthenticated,
|
|
241
322
|
loginTimeoutMs: LOGIN_TIMEOUT_MS,
|
|
323
|
+
// Headless with a SIGNED-IN profile lands on the login wall (measured 2026-11-24: `check`
|
|
324
|
+
// refused in 68 s while `check --headed` verified on the same profile, and the same pair of
|
|
325
|
+
// launches repeated after two operator sign-ins). A headless preflight pass is therefore a
|
|
326
|
+
// guaranteed burn, and the post flow is headed anyway — so the preflight probes headed, the
|
|
327
|
+
// same shape medium-pub carries for its Cloudflare interstitial.
|
|
328
|
+
checkHeadedOnly: true,
|
|
329
|
+
// This channel has no `storageState` artifact — the profile's own cookie store is the session —
|
|
330
|
+
// so the hook is used as the post-login ASSERTION instead of a capture: a sign-in the page
|
|
331
|
+
// predicate accepted but that stored no auth ticket fails here, at the login that produced it,
|
|
332
|
+
// rather than silently leaving a profile every later `check` refuses (0436 R4). A hook throw
|
|
333
|
+
// already fails the verb and suppresses the `verified` verdict, so the bot parent promotes
|
|
334
|
+
// nothing. No cookie name/value pair is ever logged: the message names the cookie only.
|
|
335
|
+
sessionState: {
|
|
336
|
+
onAuthenticated: async ({ context }) => {
|
|
337
|
+
const cookies = await context.cookies(LINKEDIN_HOME_URL).catch(() => [] as StoredCookie[]);
|
|
338
|
+
if (hasLinkedinAuthCookie(cookies)) return;
|
|
339
|
+
throw new Error(
|
|
340
|
+
`the sign-in stored no ${LINKEDIN_AUTH_COOKIE} session cookie in this profile, so no session was ` +
|
|
341
|
+
`saved — confirm the browser shows your own feed after signing in, then run ${LINKEDIN_LOGIN_INSTRUCTION} again`,
|
|
342
|
+
);
|
|
343
|
+
},
|
|
344
|
+
},
|
|
242
345
|
};
|
|
243
346
|
|
|
244
347
|
/**
|
|
@@ -294,6 +397,7 @@ export class LinkedinBrowserTransport implements PublishTransport {
|
|
|
294
397
|
private readonly operation: LinkedinOperation;
|
|
295
398
|
private readonly launcher: BrowserLauncher;
|
|
296
399
|
private readonly stepTimeoutMs: number;
|
|
400
|
+
private readonly preflightTimeoutMs: number;
|
|
297
401
|
constructor(
|
|
298
402
|
operation: LinkedinOperation = 'post',
|
|
299
403
|
driver: BrowserDriver = 'script',
|
|
@@ -303,6 +407,7 @@ export class LinkedinBrowserTransport implements PublishTransport {
|
|
|
303
407
|
this.driver = driver;
|
|
304
408
|
this.launcher = deps.launcher ?? kkBrowserLauncher;
|
|
305
409
|
this.stepTimeoutMs = deps.stepTimeoutMs ?? STEP_TIMEOUT_MS;
|
|
410
|
+
this.preflightTimeoutMs = deps.stepTimeoutMs ?? PREFLIGHT_TIMEOUT_MS;
|
|
306
411
|
}
|
|
307
412
|
|
|
308
413
|
/**
|
|
@@ -347,8 +452,9 @@ export class LinkedinBrowserTransport implements PublishTransport {
|
|
|
347
452
|
const session = await checkChannelSession(LINKEDIN_CONFIG, {
|
|
348
453
|
profileDir,
|
|
349
454
|
launcher: this.launcher,
|
|
350
|
-
|
|
351
|
-
|
|
455
|
+
// Headed, not headless: see LINKEDIN_CONFIG.checkHeadedOnly (measured 2026-11-24).
|
|
456
|
+
headedOnly: LINKEDIN_CONFIG.checkHeadedOnly === true,
|
|
457
|
+
timeoutMs: this.preflightTimeoutMs,
|
|
352
458
|
});
|
|
353
459
|
if (session.status !== 'verified') {
|
|
354
460
|
// The recovery command leads the message: `fail()` bounds the line, and the operator's
|
|
@@ -409,13 +515,15 @@ export class LinkedinBrowserTransport implements PublishTransport {
|
|
|
409
515
|
label: 'linkedin share box',
|
|
410
516
|
});
|
|
411
517
|
} catch {
|
|
412
|
-
return
|
|
518
|
+
return preSubmitFail(
|
|
413
519
|
`linkedin share box not found on ${LINKEDIN_HOME_URL} (session may be logged out, or the selector drifted) — run: ${LINKEDIN_LOGIN_INSTRUCTION}`,
|
|
414
520
|
'share-trigger',
|
|
415
521
|
metadata,
|
|
416
522
|
);
|
|
417
523
|
}
|
|
418
|
-
|
|
524
|
+
// Visible match only (0437 R1): `resolveSelector` resolves attached nodes, so a hidden duplicate
|
|
525
|
+
// can resolve first and swallow the click while the composer never opens.
|
|
526
|
+
await page.locator(triggerSelector).filter({ visible: true }).first().click();
|
|
419
527
|
|
|
420
528
|
// Modal editor. A missing editor after the click is the same loud typed refusal family.
|
|
421
529
|
// The share box is a React target that can be clicked before the feed finishes hydrating
|
|
@@ -435,6 +543,7 @@ export class LinkedinBrowserTransport implements PublishTransport {
|
|
|
435
543
|
if (retryTrigger !== null)
|
|
436
544
|
await page
|
|
437
545
|
.locator(retryTrigger)
|
|
546
|
+
.filter({ visible: true })
|
|
438
547
|
.first()
|
|
439
548
|
.click()
|
|
440
549
|
.catch(() => {});
|
|
@@ -444,10 +553,18 @@ export class LinkedinBrowserTransport implements PublishTransport {
|
|
|
444
553
|
}).catch(() => '');
|
|
445
554
|
}
|
|
446
555
|
if (composerSelector === '') {
|
|
556
|
+
const probe = await probeComposer(page, triggerSelector);
|
|
557
|
+
const counts = Object.values(probe.candidates);
|
|
558
|
+
const found = counts.every((n) => n === 0) ? 'all 0' : counts.map((n, i) => `#${i}=${n}`).join(',');
|
|
559
|
+
// Counts lead and the login hint trails inside the 300-char bound; the full selector→count
|
|
560
|
+
// map rides in `metadata.composerProbe`. The screenshot is the visual twin of the send stage's.
|
|
561
|
+
await Promise.resolve()
|
|
562
|
+
.then(() => page.screenshot({ path: '/tmp/kk-linkedin-composer-latest.png' }))
|
|
563
|
+
.catch(() => null);
|
|
447
564
|
return stageFail(
|
|
448
|
-
`linkedin composer did not open after the share box, twice (
|
|
565
|
+
`linkedin composer did not open after the share box, twice — trigger ${probe.trigger} (matches ${probe.triggerMatches}, visible ${probe.triggerVisible}); composer candidates ${found}; url ${probe.url}; frames ${probe.frames} — run: ${LINKEDIN_LOGIN_INSTRUCTION}`,
|
|
449
566
|
'composer',
|
|
450
|
-
metadata,
|
|
567
|
+
{ ...metadata, composerProbe: probe, itcDelivery: { schemaVersion: 1, effect: 'none' } },
|
|
451
568
|
);
|
|
452
569
|
}
|
|
453
570
|
const composer = page.locator(composerSelector).first();
|
|
@@ -463,7 +580,7 @@ export class LinkedinBrowserTransport implements PublishTransport {
|
|
|
463
580
|
|
|
464
581
|
// Readback before anything else: a field the editor dropped must never be submitted.
|
|
465
582
|
const readback = await this.requireReadback(page, composerSelector, text);
|
|
466
|
-
if (!readback.ok) return
|
|
583
|
+
if (!readback.ok) return preSubmitFail(readback.error, 'text-readback', metadata);
|
|
467
584
|
|
|
468
585
|
// Image upload: confirmed landed; an unconfirmed upload refuses before submit — never a
|
|
469
586
|
// silent text-only post while an image was requested. When posting a URL with no image,
|
|
@@ -471,7 +588,7 @@ export class LinkedinBrowserTransport implements PublishTransport {
|
|
|
471
588
|
const [image] = images;
|
|
472
589
|
if (image !== undefined) {
|
|
473
590
|
const uploaded = await this.uploadImage(page, image);
|
|
474
|
-
if (!uploaded.ok) return
|
|
591
|
+
if (!uploaded.ok) return preSubmitFail(uploaded.error, 'image-upload', metadata);
|
|
475
592
|
} else {
|
|
476
593
|
await this.waitForLinkPreview(page, composerSelector, text);
|
|
477
594
|
}
|
|
@@ -20557,7 +20557,12 @@ async function acquireProfileLease(profileDir, options = {}) {
|
|
|
20557
20557
|
const leaseDir = join3(leaseRoot, id);
|
|
20558
20558
|
await fileSystem.ensureDir(leaseRoot);
|
|
20559
20559
|
if (!mkdirExclusive(leaseDir, 448)) {
|
|
20560
|
-
|
|
20560
|
+
if (!await reclaimDeadOwnerLease(fileSystem, leaseDir)) {
|
|
20561
|
+
throw new BotError("busy", await busyGuidance(fileSystem, leaseDir));
|
|
20562
|
+
}
|
|
20563
|
+
if (!mkdirExclusive(leaseDir, 448)) {
|
|
20564
|
+
throw new BotError("busy", await busyGuidance(fileSystem, leaseDir));
|
|
20565
|
+
}
|
|
20561
20566
|
}
|
|
20562
20567
|
const token = randomBytes(16).toString("hex");
|
|
20563
20568
|
const owner = {
|
|
@@ -20673,9 +20678,35 @@ async function busyGuidance(fileSystem, leaseDir) {
|
|
|
20673
20678
|
}
|
|
20674
20679
|
return `browser lease ${leaseDir} already exists with no owner record \u2014 a previous run may have crashed mid-acquire; confirm no kk browser still uses this profile, then remove ${leaseDir} manually`;
|
|
20675
20680
|
}
|
|
20676
|
-
const
|
|
20681
|
+
const live = isProcessAlive(owner.pid) ? [] : await liveChildHolders(fileSystem, leaseDir);
|
|
20682
|
+
const suffix = live.length > 0 ? `pid ${owner.pid} is gone but child holders ${live.join(", ")} are still running \u2014 stop those processes before retrying` : isProcessAlive(owner.pid) ? "confirm that process and any browser for this profile have stopped; stale ownership is never auto-removed" : `pid ${owner.pid} is no longer running and the lease could not be reclassified \u2014 confirm no browser for this profile is open, then remove the stale lease with: rm -rf ${leaseDir}`;
|
|
20677
20683
|
return `browser lease ${leaseDir} is held by pid ${owner.pid} (logical ${owner.logicalPath}) \u2014 ${suffix}`;
|
|
20678
20684
|
}
|
|
20685
|
+
async function reclaimDeadOwnerLease(fileSystem, leaseDir) {
|
|
20686
|
+
const owner = await readOwner(fileSystem, leaseDir);
|
|
20687
|
+
if (owner === null || isProcessAlive(owner.pid))
|
|
20688
|
+
return false;
|
|
20689
|
+
if ((await liveChildHolders(fileSystem, leaseDir)).length > 0)
|
|
20690
|
+
return false;
|
|
20691
|
+
const target = staleLeaseDir(leaseDir);
|
|
20692
|
+
try {
|
|
20693
|
+
rename(leaseDir, target);
|
|
20694
|
+
} catch {
|
|
20695
|
+
return false;
|
|
20696
|
+
}
|
|
20697
|
+
const moved = await readOwner(fileSystem, target);
|
|
20698
|
+
if (moved !== null && moved.token !== owner.token) {
|
|
20699
|
+
try {
|
|
20700
|
+
rename(target, leaseDir);
|
|
20701
|
+
} catch {}
|
|
20702
|
+
return false;
|
|
20703
|
+
}
|
|
20704
|
+
return true;
|
|
20705
|
+
}
|
|
20706
|
+
function staleLeaseDir(leaseDir) {
|
|
20707
|
+
const stamp = new Date().toISOString().replace(/[:.]/g, "").slice(0, 15);
|
|
20708
|
+
return `${leaseDir}.stale-${stamp}-${process.pid}-${randomBytes(3).toString("hex")}`;
|
|
20709
|
+
}
|
|
20679
20710
|
async function holderResidue(fileSystem, leaseDir) {
|
|
20680
20711
|
try {
|
|
20681
20712
|
const entries = await fileSystem.readDir(leaseDir);
|
|
@@ -20219,7 +20219,12 @@ async function acquireProfileLease(profileDir, options = {}) {
|
|
|
20219
20219
|
const leaseDir = join2(leaseRoot, id);
|
|
20220
20220
|
await fileSystem.ensureDir(leaseRoot);
|
|
20221
20221
|
if (!mkdirExclusive(leaseDir, 448)) {
|
|
20222
|
-
|
|
20222
|
+
if (!await reclaimDeadOwnerLease(fileSystem, leaseDir)) {
|
|
20223
|
+
throw new BotError("busy", await busyGuidance(fileSystem, leaseDir));
|
|
20224
|
+
}
|
|
20225
|
+
if (!mkdirExclusive(leaseDir, 448)) {
|
|
20226
|
+
throw new BotError("busy", await busyGuidance(fileSystem, leaseDir));
|
|
20227
|
+
}
|
|
20223
20228
|
}
|
|
20224
20229
|
const token = randomBytes(16).toString("hex");
|
|
20225
20230
|
const owner = {
|
|
@@ -20335,9 +20340,35 @@ async function busyGuidance(fileSystem, leaseDir) {
|
|
|
20335
20340
|
}
|
|
20336
20341
|
return `browser lease ${leaseDir} already exists with no owner record \u2014 a previous run may have crashed mid-acquire; confirm no kk browser still uses this profile, then remove ${leaseDir} manually`;
|
|
20337
20342
|
}
|
|
20338
|
-
const
|
|
20343
|
+
const live = isProcessAlive(owner.pid) ? [] : await liveChildHolders(fileSystem, leaseDir);
|
|
20344
|
+
const suffix = live.length > 0 ? `pid ${owner.pid} is gone but child holders ${live.join(", ")} are still running \u2014 stop those processes before retrying` : isProcessAlive(owner.pid) ? "confirm that process and any browser for this profile have stopped; stale ownership is never auto-removed" : `pid ${owner.pid} is no longer running and the lease could not be reclassified \u2014 confirm no browser for this profile is open, then remove the stale lease with: rm -rf ${leaseDir}`;
|
|
20339
20345
|
return `browser lease ${leaseDir} is held by pid ${owner.pid} (logical ${owner.logicalPath}) \u2014 ${suffix}`;
|
|
20340
20346
|
}
|
|
20347
|
+
async function reclaimDeadOwnerLease(fileSystem, leaseDir) {
|
|
20348
|
+
const owner = await readOwner(fileSystem, leaseDir);
|
|
20349
|
+
if (owner === null || isProcessAlive(owner.pid))
|
|
20350
|
+
return false;
|
|
20351
|
+
if ((await liveChildHolders(fileSystem, leaseDir)).length > 0)
|
|
20352
|
+
return false;
|
|
20353
|
+
const target = staleLeaseDir(leaseDir);
|
|
20354
|
+
try {
|
|
20355
|
+
rename(leaseDir, target);
|
|
20356
|
+
} catch {
|
|
20357
|
+
return false;
|
|
20358
|
+
}
|
|
20359
|
+
const moved = await readOwner(fileSystem, target);
|
|
20360
|
+
if (moved !== null && moved.token !== owner.token) {
|
|
20361
|
+
try {
|
|
20362
|
+
rename(target, leaseDir);
|
|
20363
|
+
} catch {}
|
|
20364
|
+
return false;
|
|
20365
|
+
}
|
|
20366
|
+
return true;
|
|
20367
|
+
}
|
|
20368
|
+
function staleLeaseDir(leaseDir) {
|
|
20369
|
+
const stamp = new Date().toISOString().replace(/[:.]/g, "").slice(0, 15);
|
|
20370
|
+
return `${leaseDir}.stale-${stamp}-${process.pid}-${randomBytes(3).toString("hex")}`;
|
|
20371
|
+
}
|
|
20341
20372
|
async function holderResidue(fileSystem, leaseDir) {
|
|
20342
20373
|
try {
|
|
20343
20374
|
const entries = await fileSystem.readDir(leaseDir);
|
|
@@ -20540,7 +20540,12 @@ async function acquireProfileLease(profileDir, options = {}) {
|
|
|
20540
20540
|
const leaseDir = join3(leaseRoot, id);
|
|
20541
20541
|
await fileSystem.ensureDir(leaseRoot);
|
|
20542
20542
|
if (!mkdirExclusive(leaseDir, 448)) {
|
|
20543
|
-
|
|
20543
|
+
if (!await reclaimDeadOwnerLease(fileSystem, leaseDir)) {
|
|
20544
|
+
throw new BotError("busy", await busyGuidance(fileSystem, leaseDir));
|
|
20545
|
+
}
|
|
20546
|
+
if (!mkdirExclusive(leaseDir, 448)) {
|
|
20547
|
+
throw new BotError("busy", await busyGuidance(fileSystem, leaseDir));
|
|
20548
|
+
}
|
|
20544
20549
|
}
|
|
20545
20550
|
const token = randomBytes(16).toString("hex");
|
|
20546
20551
|
const owner = {
|
|
@@ -20656,9 +20661,35 @@ async function busyGuidance(fileSystem, leaseDir) {
|
|
|
20656
20661
|
}
|
|
20657
20662
|
return `browser lease ${leaseDir} already exists with no owner record \u2014 a previous run may have crashed mid-acquire; confirm no kk browser still uses this profile, then remove ${leaseDir} manually`;
|
|
20658
20663
|
}
|
|
20659
|
-
const
|
|
20664
|
+
const live = isProcessAlive(owner.pid) ? [] : await liveChildHolders(fileSystem, leaseDir);
|
|
20665
|
+
const suffix = live.length > 0 ? `pid ${owner.pid} is gone but child holders ${live.join(", ")} are still running \u2014 stop those processes before retrying` : isProcessAlive(owner.pid) ? "confirm that process and any browser for this profile have stopped; stale ownership is never auto-removed" : `pid ${owner.pid} is no longer running and the lease could not be reclassified \u2014 confirm no browser for this profile is open, then remove the stale lease with: rm -rf ${leaseDir}`;
|
|
20660
20666
|
return `browser lease ${leaseDir} is held by pid ${owner.pid} (logical ${owner.logicalPath}) \u2014 ${suffix}`;
|
|
20661
20667
|
}
|
|
20668
|
+
async function reclaimDeadOwnerLease(fileSystem, leaseDir) {
|
|
20669
|
+
const owner = await readOwner(fileSystem, leaseDir);
|
|
20670
|
+
if (owner === null || isProcessAlive(owner.pid))
|
|
20671
|
+
return false;
|
|
20672
|
+
if ((await liveChildHolders(fileSystem, leaseDir)).length > 0)
|
|
20673
|
+
return false;
|
|
20674
|
+
const target = staleLeaseDir(leaseDir);
|
|
20675
|
+
try {
|
|
20676
|
+
rename(leaseDir, target);
|
|
20677
|
+
} catch {
|
|
20678
|
+
return false;
|
|
20679
|
+
}
|
|
20680
|
+
const moved = await readOwner(fileSystem, target);
|
|
20681
|
+
if (moved !== null && moved.token !== owner.token) {
|
|
20682
|
+
try {
|
|
20683
|
+
rename(target, leaseDir);
|
|
20684
|
+
} catch {}
|
|
20685
|
+
return false;
|
|
20686
|
+
}
|
|
20687
|
+
return true;
|
|
20688
|
+
}
|
|
20689
|
+
function staleLeaseDir(leaseDir) {
|
|
20690
|
+
const stamp = new Date().toISOString().replace(/[:.]/g, "").slice(0, 15);
|
|
20691
|
+
return `${leaseDir}.stale-${stamp}-${process.pid}-${randomBytes(3).toString("hex")}`;
|
|
20692
|
+
}
|
|
20662
20693
|
async function holderResidue(fileSystem, leaseDir) {
|
|
20663
20694
|
try {
|
|
20664
20695
|
const entries = await fileSystem.readDir(leaseDir);
|
|
@@ -19947,7 +19947,12 @@ async function acquireProfileLease(profileDir, options = {}) {
|
|
|
19947
19947
|
const leaseDir = join2(leaseRoot, id);
|
|
19948
19948
|
await fileSystem.ensureDir(leaseRoot);
|
|
19949
19949
|
if (!mkdirExclusive(leaseDir, 448)) {
|
|
19950
|
-
|
|
19950
|
+
if (!await reclaimDeadOwnerLease(fileSystem, leaseDir)) {
|
|
19951
|
+
throw new BotError("busy", await busyGuidance(fileSystem, leaseDir));
|
|
19952
|
+
}
|
|
19953
|
+
if (!mkdirExclusive(leaseDir, 448)) {
|
|
19954
|
+
throw new BotError("busy", await busyGuidance(fileSystem, leaseDir));
|
|
19955
|
+
}
|
|
19951
19956
|
}
|
|
19952
19957
|
const token = randomBytes(16).toString("hex");
|
|
19953
19958
|
const owner = {
|
|
@@ -20063,9 +20068,35 @@ async function busyGuidance(fileSystem, leaseDir) {
|
|
|
20063
20068
|
}
|
|
20064
20069
|
return `browser lease ${leaseDir} already exists with no owner record \u2014 a previous run may have crashed mid-acquire; confirm no kk browser still uses this profile, then remove ${leaseDir} manually`;
|
|
20065
20070
|
}
|
|
20066
|
-
const
|
|
20071
|
+
const live = isProcessAlive(owner.pid) ? [] : await liveChildHolders(fileSystem, leaseDir);
|
|
20072
|
+
const suffix = live.length > 0 ? `pid ${owner.pid} is gone but child holders ${live.join(", ")} are still running \u2014 stop those processes before retrying` : isProcessAlive(owner.pid) ? "confirm that process and any browser for this profile have stopped; stale ownership is never auto-removed" : `pid ${owner.pid} is no longer running and the lease could not be reclassified \u2014 confirm no browser for this profile is open, then remove the stale lease with: rm -rf ${leaseDir}`;
|
|
20067
20073
|
return `browser lease ${leaseDir} is held by pid ${owner.pid} (logical ${owner.logicalPath}) \u2014 ${suffix}`;
|
|
20068
20074
|
}
|
|
20075
|
+
async function reclaimDeadOwnerLease(fileSystem, leaseDir) {
|
|
20076
|
+
const owner = await readOwner(fileSystem, leaseDir);
|
|
20077
|
+
if (owner === null || isProcessAlive(owner.pid))
|
|
20078
|
+
return false;
|
|
20079
|
+
if ((await liveChildHolders(fileSystem, leaseDir)).length > 0)
|
|
20080
|
+
return false;
|
|
20081
|
+
const target = staleLeaseDir(leaseDir);
|
|
20082
|
+
try {
|
|
20083
|
+
rename(leaseDir, target);
|
|
20084
|
+
} catch {
|
|
20085
|
+
return false;
|
|
20086
|
+
}
|
|
20087
|
+
const moved = await readOwner(fileSystem, target);
|
|
20088
|
+
if (moved !== null && moved.token !== owner.token) {
|
|
20089
|
+
try {
|
|
20090
|
+
rename(target, leaseDir);
|
|
20091
|
+
} catch {}
|
|
20092
|
+
return false;
|
|
20093
|
+
}
|
|
20094
|
+
return true;
|
|
20095
|
+
}
|
|
20096
|
+
function staleLeaseDir(leaseDir) {
|
|
20097
|
+
const stamp = new Date().toISOString().replace(/[:.]/g, "").slice(0, 15);
|
|
20098
|
+
return `${leaseDir}.stale-${stamp}-${process.pid}-${randomBytes(3).toString("hex")}`;
|
|
20099
|
+
}
|
|
20069
20100
|
async function holderResidue(fileSystem, leaseDir) {
|
|
20070
20101
|
try {
|
|
20071
20102
|
const entries = await fileSystem.readDir(leaseDir);
|
|
@@ -20564,7 +20564,12 @@ async function acquireProfileLease(profileDir, options = {}) {
|
|
|
20564
20564
|
const leaseDir = join3(leaseRoot, id);
|
|
20565
20565
|
await fileSystem.ensureDir(leaseRoot);
|
|
20566
20566
|
if (!mkdirExclusive(leaseDir, 448)) {
|
|
20567
|
-
|
|
20567
|
+
if (!await reclaimDeadOwnerLease(fileSystem, leaseDir)) {
|
|
20568
|
+
throw new BotError("busy", await busyGuidance(fileSystem, leaseDir));
|
|
20569
|
+
}
|
|
20570
|
+
if (!mkdirExclusive(leaseDir, 448)) {
|
|
20571
|
+
throw new BotError("busy", await busyGuidance(fileSystem, leaseDir));
|
|
20572
|
+
}
|
|
20568
20573
|
}
|
|
20569
20574
|
const token = randomBytes(16).toString("hex");
|
|
20570
20575
|
const owner = {
|
|
@@ -20680,9 +20685,35 @@ async function busyGuidance(fileSystem, leaseDir) {
|
|
|
20680
20685
|
}
|
|
20681
20686
|
return `browser lease ${leaseDir} already exists with no owner record \u2014 a previous run may have crashed mid-acquire; confirm no kk browser still uses this profile, then remove ${leaseDir} manually`;
|
|
20682
20687
|
}
|
|
20683
|
-
const
|
|
20688
|
+
const live = isProcessAlive(owner.pid) ? [] : await liveChildHolders(fileSystem, leaseDir);
|
|
20689
|
+
const suffix = live.length > 0 ? `pid ${owner.pid} is gone but child holders ${live.join(", ")} are still running \u2014 stop those processes before retrying` : isProcessAlive(owner.pid) ? "confirm that process and any browser for this profile have stopped; stale ownership is never auto-removed" : `pid ${owner.pid} is no longer running and the lease could not be reclassified \u2014 confirm no browser for this profile is open, then remove the stale lease with: rm -rf ${leaseDir}`;
|
|
20684
20690
|
return `browser lease ${leaseDir} is held by pid ${owner.pid} (logical ${owner.logicalPath}) \u2014 ${suffix}`;
|
|
20685
20691
|
}
|
|
20692
|
+
async function reclaimDeadOwnerLease(fileSystem, leaseDir) {
|
|
20693
|
+
const owner = await readOwner(fileSystem, leaseDir);
|
|
20694
|
+
if (owner === null || isProcessAlive(owner.pid))
|
|
20695
|
+
return false;
|
|
20696
|
+
if ((await liveChildHolders(fileSystem, leaseDir)).length > 0)
|
|
20697
|
+
return false;
|
|
20698
|
+
const target = staleLeaseDir(leaseDir);
|
|
20699
|
+
try {
|
|
20700
|
+
rename(leaseDir, target);
|
|
20701
|
+
} catch {
|
|
20702
|
+
return false;
|
|
20703
|
+
}
|
|
20704
|
+
const moved = await readOwner(fileSystem, target);
|
|
20705
|
+
if (moved !== null && moved.token !== owner.token) {
|
|
20706
|
+
try {
|
|
20707
|
+
rename(target, leaseDir);
|
|
20708
|
+
} catch {}
|
|
20709
|
+
return false;
|
|
20710
|
+
}
|
|
20711
|
+
return true;
|
|
20712
|
+
}
|
|
20713
|
+
function staleLeaseDir(leaseDir) {
|
|
20714
|
+
const stamp = new Date().toISOString().replace(/[:.]/g, "").slice(0, 15);
|
|
20715
|
+
return `${leaseDir}.stale-${stamp}-${process.pid}-${randomBytes(3).toString("hex")}`;
|
|
20716
|
+
}
|
|
20686
20717
|
async function holderResidue(fileSystem, leaseDir) {
|
|
20687
20718
|
try {
|
|
20688
20719
|
const entries = await fileSystem.readDir(leaseDir);
|
|
@@ -19947,7 +19947,12 @@ async function acquireProfileLease(profileDir, options = {}) {
|
|
|
19947
19947
|
const leaseDir = join2(leaseRoot, id);
|
|
19948
19948
|
await fileSystem.ensureDir(leaseRoot);
|
|
19949
19949
|
if (!mkdirExclusive(leaseDir, 448)) {
|
|
19950
|
-
|
|
19950
|
+
if (!await reclaimDeadOwnerLease(fileSystem, leaseDir)) {
|
|
19951
|
+
throw new BotError("busy", await busyGuidance(fileSystem, leaseDir));
|
|
19952
|
+
}
|
|
19953
|
+
if (!mkdirExclusive(leaseDir, 448)) {
|
|
19954
|
+
throw new BotError("busy", await busyGuidance(fileSystem, leaseDir));
|
|
19955
|
+
}
|
|
19951
19956
|
}
|
|
19952
19957
|
const token = randomBytes(16).toString("hex");
|
|
19953
19958
|
const owner = {
|
|
@@ -20063,9 +20068,35 @@ async function busyGuidance(fileSystem, leaseDir) {
|
|
|
20063
20068
|
}
|
|
20064
20069
|
return `browser lease ${leaseDir} already exists with no owner record \u2014 a previous run may have crashed mid-acquire; confirm no kk browser still uses this profile, then remove ${leaseDir} manually`;
|
|
20065
20070
|
}
|
|
20066
|
-
const
|
|
20071
|
+
const live = isProcessAlive(owner.pid) ? [] : await liveChildHolders(fileSystem, leaseDir);
|
|
20072
|
+
const suffix = live.length > 0 ? `pid ${owner.pid} is gone but child holders ${live.join(", ")} are still running \u2014 stop those processes before retrying` : isProcessAlive(owner.pid) ? "confirm that process and any browser for this profile have stopped; stale ownership is never auto-removed" : `pid ${owner.pid} is no longer running and the lease could not be reclassified \u2014 confirm no browser for this profile is open, then remove the stale lease with: rm -rf ${leaseDir}`;
|
|
20067
20073
|
return `browser lease ${leaseDir} is held by pid ${owner.pid} (logical ${owner.logicalPath}) \u2014 ${suffix}`;
|
|
20068
20074
|
}
|
|
20075
|
+
async function reclaimDeadOwnerLease(fileSystem, leaseDir) {
|
|
20076
|
+
const owner = await readOwner(fileSystem, leaseDir);
|
|
20077
|
+
if (owner === null || isProcessAlive(owner.pid))
|
|
20078
|
+
return false;
|
|
20079
|
+
if ((await liveChildHolders(fileSystem, leaseDir)).length > 0)
|
|
20080
|
+
return false;
|
|
20081
|
+
const target = staleLeaseDir(leaseDir);
|
|
20082
|
+
try {
|
|
20083
|
+
rename(leaseDir, target);
|
|
20084
|
+
} catch {
|
|
20085
|
+
return false;
|
|
20086
|
+
}
|
|
20087
|
+
const moved = await readOwner(fileSystem, target);
|
|
20088
|
+
if (moved !== null && moved.token !== owner.token) {
|
|
20089
|
+
try {
|
|
20090
|
+
rename(target, leaseDir);
|
|
20091
|
+
} catch {}
|
|
20092
|
+
return false;
|
|
20093
|
+
}
|
|
20094
|
+
return true;
|
|
20095
|
+
}
|
|
20096
|
+
function staleLeaseDir(leaseDir) {
|
|
20097
|
+
const stamp = new Date().toISOString().replace(/[:.]/g, "").slice(0, 15);
|
|
20098
|
+
return `${leaseDir}.stale-${stamp}-${process.pid}-${randomBytes(3).toString("hex")}`;
|
|
20099
|
+
}
|
|
20069
20100
|
async function holderResidue(fileSystem, leaseDir) {
|
|
20070
20101
|
try {
|
|
20071
20102
|
const entries = await fileSystem.readDir(leaseDir);
|
|
@@ -20558,7 +20558,12 @@ async function acquireProfileLease(profileDir, options = {}) {
|
|
|
20558
20558
|
const leaseDir = join3(leaseRoot, id);
|
|
20559
20559
|
await fileSystem.ensureDir(leaseRoot);
|
|
20560
20560
|
if (!mkdirExclusive(leaseDir, 448)) {
|
|
20561
|
-
|
|
20561
|
+
if (!await reclaimDeadOwnerLease(fileSystem, leaseDir)) {
|
|
20562
|
+
throw new BotError("busy", await busyGuidance(fileSystem, leaseDir));
|
|
20563
|
+
}
|
|
20564
|
+
if (!mkdirExclusive(leaseDir, 448)) {
|
|
20565
|
+
throw new BotError("busy", await busyGuidance(fileSystem, leaseDir));
|
|
20566
|
+
}
|
|
20562
20567
|
}
|
|
20563
20568
|
const token = randomBytes(16).toString("hex");
|
|
20564
20569
|
const owner = {
|
|
@@ -20674,9 +20679,35 @@ async function busyGuidance(fileSystem, leaseDir) {
|
|
|
20674
20679
|
}
|
|
20675
20680
|
return `browser lease ${leaseDir} already exists with no owner record \u2014 a previous run may have crashed mid-acquire; confirm no kk browser still uses this profile, then remove ${leaseDir} manually`;
|
|
20676
20681
|
}
|
|
20677
|
-
const
|
|
20682
|
+
const live = isProcessAlive(owner.pid) ? [] : await liveChildHolders(fileSystem, leaseDir);
|
|
20683
|
+
const suffix = live.length > 0 ? `pid ${owner.pid} is gone but child holders ${live.join(", ")} are still running \u2014 stop those processes before retrying` : isProcessAlive(owner.pid) ? "confirm that process and any browser for this profile have stopped; stale ownership is never auto-removed" : `pid ${owner.pid} is no longer running and the lease could not be reclassified \u2014 confirm no browser for this profile is open, then remove the stale lease with: rm -rf ${leaseDir}`;
|
|
20678
20684
|
return `browser lease ${leaseDir} is held by pid ${owner.pid} (logical ${owner.logicalPath}) \u2014 ${suffix}`;
|
|
20679
20685
|
}
|
|
20686
|
+
async function reclaimDeadOwnerLease(fileSystem, leaseDir) {
|
|
20687
|
+
const owner = await readOwner(fileSystem, leaseDir);
|
|
20688
|
+
if (owner === null || isProcessAlive(owner.pid))
|
|
20689
|
+
return false;
|
|
20690
|
+
if ((await liveChildHolders(fileSystem, leaseDir)).length > 0)
|
|
20691
|
+
return false;
|
|
20692
|
+
const target = staleLeaseDir(leaseDir);
|
|
20693
|
+
try {
|
|
20694
|
+
rename(leaseDir, target);
|
|
20695
|
+
} catch {
|
|
20696
|
+
return false;
|
|
20697
|
+
}
|
|
20698
|
+
const moved = await readOwner(fileSystem, target);
|
|
20699
|
+
if (moved !== null && moved.token !== owner.token) {
|
|
20700
|
+
try {
|
|
20701
|
+
rename(target, leaseDir);
|
|
20702
|
+
} catch {}
|
|
20703
|
+
return false;
|
|
20704
|
+
}
|
|
20705
|
+
return true;
|
|
20706
|
+
}
|
|
20707
|
+
function staleLeaseDir(leaseDir) {
|
|
20708
|
+
const stamp = new Date().toISOString().replace(/[:.]/g, "").slice(0, 15);
|
|
20709
|
+
return `${leaseDir}.stale-${stamp}-${process.pid}-${randomBytes(3).toString("hex")}`;
|
|
20710
|
+
}
|
|
20680
20711
|
async function holderResidue(fileSystem, leaseDir) {
|
|
20681
20712
|
try {
|
|
20682
20713
|
const entries = await fileSystem.readDir(leaseDir);
|
|
@@ -20219,7 +20219,12 @@ async function acquireProfileLease(profileDir, options = {}) {
|
|
|
20219
20219
|
const leaseDir = join2(leaseRoot, id);
|
|
20220
20220
|
await fileSystem.ensureDir(leaseRoot);
|
|
20221
20221
|
if (!mkdirExclusive(leaseDir, 448)) {
|
|
20222
|
-
|
|
20222
|
+
if (!await reclaimDeadOwnerLease(fileSystem, leaseDir)) {
|
|
20223
|
+
throw new BotError("busy", await busyGuidance(fileSystem, leaseDir));
|
|
20224
|
+
}
|
|
20225
|
+
if (!mkdirExclusive(leaseDir, 448)) {
|
|
20226
|
+
throw new BotError("busy", await busyGuidance(fileSystem, leaseDir));
|
|
20227
|
+
}
|
|
20223
20228
|
}
|
|
20224
20229
|
const token = randomBytes(16).toString("hex");
|
|
20225
20230
|
const owner = {
|
|
@@ -20335,9 +20340,35 @@ async function busyGuidance(fileSystem, leaseDir) {
|
|
|
20335
20340
|
}
|
|
20336
20341
|
return `browser lease ${leaseDir} already exists with no owner record \u2014 a previous run may have crashed mid-acquire; confirm no kk browser still uses this profile, then remove ${leaseDir} manually`;
|
|
20337
20342
|
}
|
|
20338
|
-
const
|
|
20343
|
+
const live = isProcessAlive(owner.pid) ? [] : await liveChildHolders(fileSystem, leaseDir);
|
|
20344
|
+
const suffix = live.length > 0 ? `pid ${owner.pid} is gone but child holders ${live.join(", ")} are still running \u2014 stop those processes before retrying` : isProcessAlive(owner.pid) ? "confirm that process and any browser for this profile have stopped; stale ownership is never auto-removed" : `pid ${owner.pid} is no longer running and the lease could not be reclassified \u2014 confirm no browser for this profile is open, then remove the stale lease with: rm -rf ${leaseDir}`;
|
|
20339
20345
|
return `browser lease ${leaseDir} is held by pid ${owner.pid} (logical ${owner.logicalPath}) \u2014 ${suffix}`;
|
|
20340
20346
|
}
|
|
20347
|
+
async function reclaimDeadOwnerLease(fileSystem, leaseDir) {
|
|
20348
|
+
const owner = await readOwner(fileSystem, leaseDir);
|
|
20349
|
+
if (owner === null || isProcessAlive(owner.pid))
|
|
20350
|
+
return false;
|
|
20351
|
+
if ((await liveChildHolders(fileSystem, leaseDir)).length > 0)
|
|
20352
|
+
return false;
|
|
20353
|
+
const target = staleLeaseDir(leaseDir);
|
|
20354
|
+
try {
|
|
20355
|
+
rename(leaseDir, target);
|
|
20356
|
+
} catch {
|
|
20357
|
+
return false;
|
|
20358
|
+
}
|
|
20359
|
+
const moved = await readOwner(fileSystem, target);
|
|
20360
|
+
if (moved !== null && moved.token !== owner.token) {
|
|
20361
|
+
try {
|
|
20362
|
+
rename(target, leaseDir);
|
|
20363
|
+
} catch {}
|
|
20364
|
+
return false;
|
|
20365
|
+
}
|
|
20366
|
+
return true;
|
|
20367
|
+
}
|
|
20368
|
+
function staleLeaseDir(leaseDir) {
|
|
20369
|
+
const stamp = new Date().toISOString().replace(/[:.]/g, "").slice(0, 15);
|
|
20370
|
+
return `${leaseDir}.stale-${stamp}-${process.pid}-${randomBytes(3).toString("hex")}`;
|
|
20371
|
+
}
|
|
20341
20372
|
async function holderResidue(fileSystem, leaseDir) {
|
|
20342
20373
|
try {
|
|
20343
20374
|
const entries = await fileSystem.readDir(leaseDir);
|