Skip to content

[Perf] EventLog.append lists the entire event directory on every append #4676

Closed

Description

@VascoSch92

Part of #4671 (step 1).

What happens

EventLog.append (event_store.py:184) begins, inside the file lock:

with self._fs.lock(self._lock_path, timeout=LOCK_TIMEOUT_SECONDS):
    # Sync with disk in case another process wrote while we waited
    disk_length = self._count_events_on_disk()

and _count_events_on_disk (:235) does a full directory listing plus a scan of every path:

paths = self._fs.list(self._dir)
...
return sum(1 for p in paths
           if posix_path_name(p).startswith("event-") and p.endswith(".json"))

So appending event N costs O(N) directory work, under the lock, on the run loop's critical path. Append cost grows linearly with conversation length, and the cost is paid while holding the lock that intake also wants.

Why it matters

Long conversations get progressively slower to write, and the slowdown is invisible in profiles that look at "the agent" rather than at persistence. It also widens the FIFOLock contention window exactly when conversations are longest.

Desired Behavior

Cheaper multi-writer detection than a full listing — an mtime/size check on a marker, a monotonic counter file, or dropping the cross-process sync from the hot path and doing it on open plus on lock contention only. The multi-process case this guards should be stated explicitly first (which deployments actually have two writers on one event dir?), because the answer may be "none" for the default single-writer path.

Acceptance Criteria

  • Append cost is flat against conversation length. Measure before and after — this is one of the baselines in the step-0 issue.

Activity

  1. added
    enhancement
    on Aug 27, 2026
  2. github-actions commented on Aug 27, 2026

    @github-actions
    Contributor

    ✅ ready-for-dev label applied

    This issue meets the readiness criteria and is ready for contribution.
    A contributor can now open a PR that links this issue (Fixes #<number>).

    This is an automated check — no AI was used to generate this comment.

  3. self-assigned this
    on Aug 27, 2026
  4. added
    ready-for-dev
    on Aug 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementready-for-dev

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions