Skip to content

Hooks: markers/ leaks hook-dedup-* files (134k+) — dedup markers never pruned #963

@magicpro97

Description

@magicpro97

Summary

hooks/hook_runner.py _check_and_set_dedup() writes one marker file hook-dedup-{event}-{payload_hash} per invocation to suppress double-fired hooks within a 500 ms window. The payload hash is a per-call MD5, so every unique tool call creates a new file that is never deleted.

Impact (Facts)

  • Observed ~/.copilot/markers/ containing 134,426 hook-dedup-* files (ls | grep -c hook-dedup).
  • Every hook invocation does mkdir + write_text into that directory; a directory with 130k+ entries slows all hook events (sessionStart/preToolUse/postToolUse/...).

Root cause

The 500 ms dedup window only needs a marker for a fraction of a second, but nothing ever removes stale markers.

Fix

Add a time-gated _prune_stale_dedup_markers() that removes hook-dedup-* files older than a 5 s TTL, at most once per 60 s (stamp file dedup-sweep.stamp), fully fail-open.

Acceptance criteria

  • Stale hook-dedup-* markers are pruned automatically.
  • Fresh marker for the current call survives (dedup still works within 500 ms).
  • Regression test added.
  • tests/test_hook_runner_entrypoints.py passes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions