mirror of
https://github.com/Gitlawb/openclaude.git
synced 2026-08-24 02:34:15 -05:00
* diagnostics(issue-1830): trace interruption causality * test(issue-1830): lock interruption ownership matrix * fix(codex): preserve stream deadline contract * fix(diagnostics): harden interruption trace lifecycle Refs #1830 * fix(diagnostics): harden interruption trace settlement Refs #1830 * fix(diagnostics): preserve interruption causality * fix(diagnostics): address interruption trace review * fix(diagnostics): preserve tracing observer contracts * fix(diagnostics): preserve interruption trace contracts * test(permissions): cover interactive hook interrupts
62 lines
1.4 KiB
TypeScript
62 lines
1.4 KiB
TypeScript
import {
|
|
getInterruptionSignalAbortTrace,
|
|
tracePermissionAbortResolution,
|
|
} from '../interruptionTrace.js'
|
|
|
|
export type InProcessPermissionAbortCompleter = {
|
|
claim(): boolean
|
|
completeAbort(
|
|
source: string | undefined,
|
|
causalEventId: string | undefined,
|
|
): boolean
|
|
completeSignalAbort(): boolean
|
|
isSettled(): boolean
|
|
}
|
|
|
|
export function createInProcessPermissionAbortCompleter(
|
|
signal: AbortSignal,
|
|
onAbortSettled: () => void,
|
|
): InProcessPermissionAbortCompleter {
|
|
let settled = false
|
|
|
|
const claim = (): boolean => {
|
|
if (settled) return false
|
|
settled = true
|
|
signal.removeEventListener('abort', onSignalAbort)
|
|
return true
|
|
}
|
|
|
|
const completeAbort = (
|
|
source: string | undefined,
|
|
causalEventId: string | undefined,
|
|
): boolean => {
|
|
if (!claim()) return false
|
|
tracePermissionAbortResolution(
|
|
source,
|
|
causalEventId,
|
|
'in_process_permission_bridge',
|
|
)
|
|
onAbortSettled()
|
|
return true
|
|
}
|
|
|
|
const completeSignalAbort = (): boolean => {
|
|
const trace = getInterruptionSignalAbortTrace(signal)
|
|
return completeAbort(trace.source, trace.causalEventId)
|
|
}
|
|
|
|
const onSignalAbort = () => {
|
|
completeSignalAbort()
|
|
}
|
|
|
|
signal.addEventListener('abort', onSignalAbort, { once: true })
|
|
if (signal.aborted) onSignalAbort()
|
|
|
|
return {
|
|
claim,
|
|
completeAbort,
|
|
completeSignalAbort,
|
|
isSettled: () => settled,
|
|
}
|
|
}
|