codex icon indicating copy to clipboard operation
codex copied to clipboard

Trim `history.jsonl` when `history.max_bytes` is set

Open terror opened this issue 1 month ago • 13 comments

This PR honors the history.max_bytes configuration parameter by trimming history.jsonl whenever it grows past the configured limit. While appending new entries we retain the newest record, drop the oldest lines to stay within the byte budget, and serialize the compacted file back to disk under the same lock to keep writers safe.

terror avatar Nov 05 '25 04:11 terror

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

github-actions[bot] avatar Nov 05 '25 04:11 github-actions[bot]

I have read the CLA Document and I hereby sign the CLA

terror avatar Nov 05 '25 04:11 terror

@codex review

etraut-openai avatar Nov 05 '25 08:11 etraut-openai

Codex Review: Didn't find any major issues. Bravo.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Thanks for the contributions. It looks like the newly-added tests are failing in CI. Could you take a look?

etraut-openai avatar Nov 05 '25 08:11 etraut-openai

Thanks for the contributions. It looks like the newly-added tests are failing in CI. Could you take a look?

I believe this was because we were missing a write(true) for truncation rights on Windows. My latest commit should fix this up.

terror avatar Nov 05 '25 16:11 terror

Thanks for the contributions. It looks like the newly-added tests are failing in CI. Could you take a look?

I believe this was because we were missing a write(true) for truncation rights on Windows. My latest commit should fix this up.

Alright, so apparently on Windows adding append(true) strips the handle of FILE_WRITE_DATA, leaving only FILE_APPEND_DATA. I've gated the append(true) for unix only.

terror avatar Nov 05 '25 23:11 terror

@terror thanks for taking this on!

One concern I have is that perhaps we need two limits: a soft cap and a hard cap?

Specifically, it seems like once we hit the limit, if we only delete the minimum number of lines to get under the limit, we will probably hit the limit again after another command or two, right?

Whereas if we had a "soft cap" and a "hard cap," I would say when we hit the hard cap, we reduce the file to the soft cap so we do less I/O overall, though admittedly at the cost of evicting old entries sooner than in your proposed implementation.

What do you think?

bolinfest avatar Nov 17 '25 23:11 bolinfest

@terror, I wanted to make sure you saw the response above. Interested in your thoughts.

etraut-openai avatar Nov 23 '25 20:11 etraut-openai

@terror thanks for taking this on!

One concern I have is that perhaps we need two limits: a soft cap and a hard cap?

Specifically, it seems like once we hit the limit, if we only delete the minimum number of lines to get under the limit, we will probably hit the limit again after another command or two, right?

Whereas if we had a "soft cap" and a "hard cap," I would say when we hit the hard cap, we reduce the file to the soft cap so we do less I/O overall, though admittedly at the cost of evicting old entries sooner than in your proposed implementation.

What do you think?

Yeah this makes sense, what do we think is a reasonable soft cap? 80% of max bytes?

terror avatar Nov 25 '25 07:11 terror

@terror, that sounds reasonable, but please make it configurable with a constant that can be adjusted if necessary. This PR has been open for a long time, so I'd like to get it over the finish line in the next few days if possible.

etraut-openai avatar Dec 02 '25 00:12 etraut-openai

@terror, that sounds reasonable, but please make it configurable with a constant that can be adjusted if necessary. This PR has been open for a long time, so I'd like to get it over the finish line in the next few days if possible.

Just pushed up some changes for this!

terror avatar Dec 02 '25 00:12 terror

@terror, CI is failing due to lint (cargo clippy) issues.

etraut-openai avatar Dec 02 '25 05:12 etraut-openai