Commit d88e5bb
Set limit size on file for tool history log (#441)
* fix: set limit size on file for tool history log
* fix(toolHistory): rolling trim instead of full wipe at size cap
Address review feedback on PR #441. The original size-cap implementation
had three issues:
1. flushToDisk wiped this.history = [] AFTER appendFileSync if the append
pushed the file over the cap, silently dropping the batch just written.
A user calling get_recent_tool_calls right after a tool ran would see
an empty history despite the call succeeding.
2. The pre-append branch reset the in-memory cache to the just-written
batch, discarding older entries that addCall already bounds via
MAX_ENTRIES. The size cap is a *disk* policy, not a memory policy.
3. clearHistoryFileIfTooLarge returned true on truncate failure, so
callers wiped in-memory state for an unchanged oversized file. On
subsequent flushes the file kept growing while memory kept resetting.
Beyond fixing those: switched from 'truncate to zero' to a rolling
byte-budget trim. When the file exceeds 5 MiB, drop oldest entries
until the kept tail fits within a 4 MiB target (with headroom so a
single overflow doesn't cause every subsequent flush to re-trim).
Always keeps at least the most recent entry.
Smoke-tested against a pre-filled 6.39 MiB file: trims to 4.00 MiB,
keeps the newest 688 records, every kept line is valid JSON, and
freshly appended records survive both on disk and in memory. A 4.36
MiB file (under cap) is left untouched.
---------
Co-authored-by: Eduard Ruzga <wonderwhy.er@gmail.com>1 parent fc6b143 commit d88e5bb
1 file changed
Lines changed: 71 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
35 | 40 | | |
36 | 41 | | |
37 | 42 | | |
| |||
65 | 70 | | |
66 | 71 | | |
67 | 72 | | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
68 | 77 | | |
69 | 78 | | |
70 | 79 | | |
| |||
90 | 99 | | |
91 | 100 | | |
92 | 101 | | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
93 | 156 | | |
94 | 157 | | |
95 | 158 | | |
| |||
125 | 188 | | |
126 | 189 | | |
127 | 190 | | |
128 | | - | |
| 191 | + | |
129 | 192 | | |
130 | 193 | | |
131 | 194 | | |
132 | | - | |
| 195 | + | |
133 | 196 | | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
134 | 203 | | |
135 | 204 | | |
136 | 205 | | |
| |||
0 commit comments