慣性聚合 高效追讀感興趣之博客、新聞、科技資訊
閱原文 以慣性聚合開啟

推薦訂閱源

博客园 - 司徒正美
V
V2EX
T
Tailwind CSS Blog
有赞技术团队
有赞技术团队
aimingoo的专栏
aimingoo的专栏
Apple Machine Learning Research
Apple Machine Learning Research
IT之家
IT之家
Blog — PlanetScale
Blog — PlanetScale
A
About on SuperTechFans
月光博客
月光博客
T
The Blog of Author Tim Ferriss
宝玉的分享
宝玉的分享
Martin Fowler
Martin Fowler
博客园 - 聂微东
The GitHub Blog
The GitHub Blog
V
Visual Studio Blog
WordPress大学
WordPress大学
酷 壳 – CoolShell
酷 壳 – CoolShell
Engineering at Meta
Engineering at Meta
GbyAI
GbyAI

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4 test: trim doctor command hotspots · openclaw/openclaw@c66f16a test: isolate agent auth and spawn hotspots · openclaw/openclaw@9285935 test: stabilize MCP startup disposal race · openclaw/openclaw@dd9d2eb test: merge browser contract server suites · openclaw/openclaw@5817a76 test: narrow ollama provider discovery setup · openclaw/openclaw@a0d9598 build: declare qa-lab aimock runtime dependency · openclaw/openclaw@24431e5 test: speed up safe-bins exec harness · openclaw/openclaw@ee856ab test: preserve tool helpers in embedded runner mocks · openclaw/openclaw@acd86a0 refactor: move memory embeddings into provider plugins · openclaw/openclaw@77e6e4c test: reuse system-run temp fixtures · openclaw/openclaw@7e9ff0f test: trim hotspot wait overhead · openclaw/openclaw@12a59b0 Check: avoid duplicate boundary prep · openclaw/openclaw@baf11b8 test: reduce hotspot fixture overhead · openclaw/openclaw@3a59edd feat(ui): overhaul settings and slash command UX (#67819) thanks @Bun… · openclaw/openclaw@2cfb660 QA Matrix: exit cleanly on failure · openclaw/openclaw@42805d2 QA Matrix: isolate scenario coverage · openclaw/openclaw@7e659e1 Matrix: refresh crypto bootstrap state · openclaw/openclaw@94081d8 QA Lab: add provider registry · openclaw/openclaw@bb7e982 Matrix: add plugin changelog · openclaw/openclaw@4acab55 test: trim more hotspot overhead · openclaw/openclaw@f485311
修会话锁:于锁取时于shouldReclaim中严持maxHoldMs… · openclaw/openclaw@a1eb765
njuboy11 · 2026-05-24 · via Recent Commits to openclaw:main

@@ -12,6 +12,7 @@ type LockFilePayload = {

1212

createdAt?: string;

1313

/** Process start time in clock ticks (from /proc/pid/stat field 22). */

1414

starttime?: number;

15+

maxHoldMs?: number;

1516

};

16171718

function isValidLockNumber(value: unknown): value is number {

@@ -378,6 +379,9 @@ async function readLockPayload(lockPath: string): Promise<LockFilePayload | null

378379

if (isValidLockNumber(parsed.starttime)) {

379380

payload.starttime = parsed.starttime;

380381

}

382+

if (isValidLockNumber(parsed.maxHoldMs) && parsed.maxHoldMs > 0) {

383+

payload.maxHoldMs = parsed.maxHoldMs;

384+

}

381385

return payload;

382386

} catch {

383387

return null;

@@ -449,6 +453,7 @@ function inspectLockPayload(

449453

payload: LockFilePayload | null,

450454

staleMs: number,

451455

nowMs: number,

456+

opts: { respectMaxHold?: boolean } = {},

452457

): LockInspectionDetails {

453458

const pid = isValidLockNumber(payload?.pid) && payload.pid > 0 ? payload.pid : null;

454459

const pidAlive = pid !== null ? isPidAlive(pid) : false;

@@ -481,6 +486,16 @@ function inspectLockPayload(

481486

} else if (ageMs > staleMs) {

482487

staleReasons.push("too-old");

483488

}

489+

const holderMaxHoldMs =

490+

isValidLockNumber(payload?.maxHoldMs) && payload.maxHoldMs > 0 ? payload.maxHoldMs : undefined;

491+

if (

492+

opts.respectMaxHold === true &&

493+

typeof holderMaxHoldMs === "number" &&

494+

ageMs !== null &&

495+

ageMs > holderMaxHoldMs

496+

) {

497+

staleReasons.push("hold-exceeded");

498+

}

484499485500

return {

486501

pid,

@@ -552,39 +567,6 @@ function sessionLockHeldByThisProcess(normalizedSessionFile: string): boolean {

552567

);

553568

}

554569555-

async function removeReportedStaleLockIfStillStale(params: {

556-

lockPath: string;

557-

normalizedSessionFile: string;

558-

staleMs: number;

559-

readOwnerProcessArgs?: SessionLockOwnerProcessArgsReader;

560-

}): Promise<boolean> {

561-

const nowMs = Date.now();

562-

const payload = await readLockPayload(params.lockPath);

563-

if (payload === null) {

564-

try {

565-

await fs.access(params.lockPath);

566-

} catch (error) {

567-

if ((error as NodeJS.ErrnoException).code === "ENOENT") {

568-

return true;

569-

}

570-

throw error;

571-

}

572-

}

573-

const inspected = inspectLockPayloadForSession({

574-

payload,

575-

staleMs: params.staleMs,

576-

nowMs,

577-

heldByThisProcess: sessionLockHeldByThisProcess(params.normalizedSessionFile),

578-

reclaimLockWithoutStarttime: true,

579-

readOwnerProcessArgs: params.readOwnerProcessArgs ?? readProcessArgsSync,

580-

});

581-

if (!(await shouldReclaimContendedLockFile(params.lockPath, inspected, params.staleMs, nowMs))) {

582-

return false;

583-

}

584-

await fs.rm(params.lockPath, { force: true });

585-

return true;

586-

}

587-588570

function shouldTreatAsOrphanSelfLock(params: {

589571

payload: LockFilePayload | null;

590572

heldByThisProcess: boolean;

@@ -616,8 +598,11 @@ function inspectLockPayloadForSession(params: {

616598

heldByThisProcess: boolean;

617599

reclaimLockWithoutStarttime: boolean;

618600

readOwnerProcessArgs: SessionLockOwnerProcessArgsReader;

601+

respectMaxHold?: boolean;

619602

}): LockInspectionDetails {

620-

const inspected = inspectLockPayload(params.payload, params.staleMs, params.nowMs);

603+

const inspected = inspectLockPayload(params.payload, params.staleMs, params.nowMs, {

604+

respectMaxHold: params.respectMaxHold,

605+

});

621606

if (

622607

shouldTreatAsOrphanSelfLock({

623608

payload: params.payload,

@@ -745,18 +730,20 @@ export async function acquireSessionWriteLock(params: {

745730

const normalizedSessionFile = await resolveNormalizedSessionFile(sessionFile);

746731

const lockPath = `${normalizedSessionFile}.lock`;

747732

await fs.mkdir(sessionDir, { recursive: true });

733+748734

while (true) {

749735

try {

750736

const lock = await SESSION_LOCKS.acquire(sessionFile, {

751737

staleMs,

752738

timeoutMs,

753739

retry: { minTimeout: 50, maxTimeout: 1000, factor: 1 },

740+

staleRecovery: "remove-if-unchanged",

754741

allowReentrant,

755742

metadata: { maxHoldMs },

756743

payload: () => {

757744

const createdAt = new Date().toISOString();

758745

const starttime = resolveProcessStartTimeForLock(process.pid);

759-

const lockPayload: LockFilePayload = { pid: process.pid, createdAt };

746+

const lockPayload: LockFilePayload = { pid: process.pid, createdAt, maxHoldMs };

760747

if (starttime !== null) {

761748

lockPayload.starttime = starttime;

762749

}

@@ -770,24 +757,27 @@ export async function acquireSessionWriteLock(params: {

770757

heldByThisProcess,

771758

reclaimLockWithoutStarttime: true,

772759

readOwnerProcessArgs: readProcessArgsSync,

760+

respectMaxHold: !heldByThisProcess,

761+

});

762+

return await shouldReclaimContendedLockFile(lockPath, inspected, staleMs, nowMs);

763+

},

764+

shouldRemoveStaleLock: async ({ lockPath, normalizedTargetPath, payload }) => {

765+

const nowMs = Date.now();

766+

const heldByThisProcess = sessionLockHeldByThisProcess(normalizedTargetPath);

767+

const inspected = inspectLockPayloadForSession({

768+

payload: payload as LockFilePayload | null,

769+

staleMs,

770+

nowMs,

771+

heldByThisProcess,

772+

reclaimLockWithoutStarttime: true,

773+

readOwnerProcessArgs: readProcessArgsSync,

774+

respectMaxHold: !heldByThisProcess,

773775

});

774776

return await shouldReclaimContendedLockFile(lockPath, inspected, staleMs, nowMs);

775777

},

776778

});

777779

return { release: lock.release };

778780

} catch (err) {

779-

if (isFileLockError(err, "file_lock_stale")) {

780-

const staleLockPath = (err as { lockPath?: string }).lockPath ?? lockPath;

781-

if (

782-

await removeReportedStaleLockIfStillStale({

783-

lockPath: staleLockPath,

784-

normalizedSessionFile,

785-

staleMs,

786-

})

787-

) {

788-

continue;

789-

}

790-

}

791781

if (!isFileLockError(err, "file_lock_timeout")) {

792782

throw err;

793783

}

@@ -802,6 +792,7 @@ export async function acquireSessionWriteLock(params: {

802792

export const testing = {

803793

cleanupSignals: [...CLEANUP_SIGNALS],

804794

handleTerminationSignal,

795+

inspectLockPayloadForTest: inspectLockPayload,

805796

releaseAllLocksSync,

806797

runLockWatchdogCheck,

807798

setProcessStartTimeResolverForTest(resolver: ((pid: number) => number | null) | null): void {