You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Rule-check log rotation can lose or drop log lines when two processes rotate at once #705
Rotation of rule-checks.jsonl is a check-then-act sequence with no lock.
Where
src/core/lifecycle.ts:124-133 (appendRuleLog). The code stats the file, then unlinks .1, then renames the log to .1.
Failure scenario
Hooks run in parallel. Two processes both see size >= maxBytes. Process A unlinks the old .1 and renames the full log to .1. Process B, which already passed its size check, then unlinks A's fresh .1 (the full log, now lost) and tries to rename the new, nearly empty log. Or the rename throws ENOENT and B drops its entry through the outer catch. Result: up to one full 4 MiB of rule-check history is lost, or a line is skipped. This is a log only, and the function documents "never throws", so the impact is low.
Suggested fix
Rename over .1 directly. renameSync replaces the target, so the unlinkSync is unnecessary and the window shrinks.
Treat ENOENT on the rename as "someone else rotated" and carry on to the append.
Activity