Skip to content

emrg: llm.jsonl rotation keeps three backup generations where its constant, docstring and prompt all say two #2697

Closed

Description

@argszero

What is observed

emrg/session.py rotates llm.jsonl when it passes _LLM_LOG_MAX_BYTES, and three separate carriers state that it keeps two backup generations:

  • emrg/session.py:38 — _LLM_LOG_BACKUP_COUNT = 2
  • emrg/session.py:899 — the docstring: "keeping up to 2 backup files (llm.jsonl.1, llm.jsonl.2)"
  • emrg/server/prompts/system.j2:77 — "llm.jsonl is the raw log, rotated with two backups."

The code keeps three. Driving the real _rotate_llm_log() over six successive appends in a temporary directory, with the size bound forced low:

rotation 1: ['llm.jsonl.1']
rotation 2: ['llm.jsonl.1', 'llm.jsonl.2']
rotation 3: ['llm.jsonl.1', 'llm.jsonl.2', 'llm.jsonl.3']
rotation 4: ['llm.jsonl.1', 'llm.jsonl.2', 'llm.jsonl.3']
rotation 5: ['llm.jsonl.1', 'llm.jsonl.2', 'llm.jsonl.3']
rotation 6: ['llm.jsonl.1', 'llm.jsonl.2', 'llm.jsonl.3']

A live session on this host holds exactly that: llm.jsonl 25 MB plus .1 53 MB, .2 52 MB, .3 52 MB.

Why the code disagrees with itself

The shift loop deletes .3 and then renames .2 into it, so the newest deletion frees nothing:

# Shift existing backups: .2 → .3 (delete), .1 → .2, main → .1
for i in range(_LLM_LOG_BACKUP_COUNT, 0, -1):
    ...
    if i == _LLM_LOG_BACKUP_COUNT and new.exists():
        new.unlink()
    if old.exists():
        old.rename(new)

The comment already describes the intent the loop fails to carry out: .2 is meant to be dropped, not promoted.

What the fix must satisfy

  • The rotation keeps exactly _LLM_LOG_BACKUP_COUNT backup generations, so the constant, the docstring and the system prompt describe the same file set.
  • The oldest generation is removed rather than shifted into a new name.
  • The size bound behaves as documented: one live file plus _LLM_LOG_BACKUP_COUNT backups, i.e. 150 MB at the 50 MB default instead of the 200 MB kept today.

Activity

  1. argszero commented on Nov 3, 2026

    @argszero
    OwnerAuthor

    Handled by #2699

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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