feat(shared): wire tolerantFsync to record skips with path classification
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import { fsyncSync } from "node:fs"
|
||||
import type { FileHandle } from "node:fs/promises"
|
||||
|
||||
import { classifyPathEnvironment } from "./classify-path-environment"
|
||||
import { recordFsyncSkip } from "./fsync-skip-tracker"
|
||||
import { log } from "./logger"
|
||||
|
||||
const TOLERATED_FSYNC_CODES: ReadonlySet<string> = new Set([
|
||||
@@ -16,6 +18,13 @@ export function isToleratedFsyncError(error: unknown): boolean {
|
||||
return code !== undefined && TOLERATED_FSYNC_CODES.has(code)
|
||||
}
|
||||
|
||||
function extractPathFromContextLabel(contextLabel: string): string {
|
||||
const separatorIndex = contextLabel.indexOf(":")
|
||||
if (separatorIndex < 0) return contextLabel
|
||||
|
||||
return contextLabel.slice(separatorIndex + 1)
|
||||
}
|
||||
|
||||
export async function tolerantFsync(
|
||||
fileHandle: FileHandle,
|
||||
contextLabel: string,
|
||||
@@ -24,11 +33,23 @@ export async function tolerantFsync(
|
||||
await fileHandle.sync()
|
||||
} catch (error) {
|
||||
if (!isToleratedFsyncError(error)) throw error
|
||||
const errorCode = (error as NodeJS.ErrnoException).code ?? "UNKNOWN"
|
||||
const message = error instanceof Error ? error.message : String(error)
|
||||
const filePath = extractPathFromContextLabel(contextLabel)
|
||||
|
||||
log("fsync skipped due to filesystem limitation", {
|
||||
event: "fsync-skipped",
|
||||
contextLabel,
|
||||
code: (error as NodeJS.ErrnoException).code,
|
||||
message: error instanceof Error ? error.message : String(error),
|
||||
code: errorCode,
|
||||
message,
|
||||
})
|
||||
|
||||
recordFsyncSkip({
|
||||
filePath,
|
||||
contextLabel,
|
||||
errorCode,
|
||||
message,
|
||||
pathClassification: classifyPathEnvironment(filePath),
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -42,11 +63,23 @@ export function tolerantFsyncSync(
|
||||
fsyncImpl(fileDescriptor)
|
||||
} catch (error) {
|
||||
if (!isToleratedFsyncError(error)) throw error
|
||||
const errorCode = (error as NodeJS.ErrnoException).code ?? "UNKNOWN"
|
||||
const message = error instanceof Error ? error.message : String(error)
|
||||
const filePath = extractPathFromContextLabel(contextLabel)
|
||||
|
||||
log("fsync skipped due to filesystem limitation", {
|
||||
event: "fsync-skipped",
|
||||
contextLabel,
|
||||
code: (error as NodeJS.ErrnoException).code,
|
||||
message: error instanceof Error ? error.message : String(error),
|
||||
code: errorCode,
|
||||
message,
|
||||
})
|
||||
|
||||
recordFsyncSkip({
|
||||
filePath,
|
||||
contextLabel,
|
||||
errorCode,
|
||||
message,
|
||||
pathClassification: classifyPathEnvironment(filePath),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user