MCPcopy Create free account
hub / github.com/anomalyco/opencode / stale

Function stale

packages/core/src/util/flock.ts:127–146  ·  view source on GitHub ↗
(lockDir: string, heartbeatPath: string, metaPath: string, staleMs: number)

Source from the content-addressed store, hash-verified

125 }
126
127 async function stale(lockDir: string, heartbeatPath: string, metaPath: string, staleMs: number) {
128 // Stale detection allows automatic recovery after crashed owners.
129 const now = wall()
130 const heartbeat = await stats(heartbeatPath)
131 if (heartbeat) {
132 return now - heartbeat.mtimeMs > staleMs
133 }
134
135 const meta = await stats(metaPath)
136 if (meta) {
137 return now - meta.mtimeMs > staleMs
138 }
139
140 const dir = await stats(lockDir)
141 if (!dir) {
142 return false
143 }
144
145 return now - dir.mtimeMs > staleMs
146 }
147
148 async function tryAcquireLockDir(lockDir: string, opts: Opts): Promise<Owned | { acquired: false }> {
149 const token = randomUUID?.() ?? randomBytes(16).toString("hex")

Callers 1

tryAcquireLockDirFunction · 0.85

Calls 2

wallFunction · 0.70
statsFunction · 0.70

Tested by

no test coverage detected