fix: advance dream cursor when Dream is disabled to prevent prompt bloat (#4242)
When dream.enabled is false, the Dream cron job never runs, so the dream cursor (.dream_cursor) stays at its initial value (0). This causes read_recent_history_for_prompt() to treat every history entry as unprocessed, injecting the full chat history into every system prompt and growing without bound. Fix: fast-forward the dream cursor to the latest history entry at gateway startup when Dream is disabled.
This commit is contained in:
@@ -330,6 +330,27 @@ class TestDreamCursor:
|
||||
def test_initial_cursor_is_zero(self, store):
|
||||
assert store.get_last_dream_cursor() == 0
|
||||
|
||||
def test_returns_zero_when_empty(self, store):
|
||||
assert store.get_latest_cursor() == 0
|
||||
|
||||
def test_returns_cursor_of_last_entry(self, store):
|
||||
store.append_history("event 1")
|
||||
store.append_history("event 2")
|
||||
store.append_history("event 3")
|
||||
|
||||
assert store.get_latest_cursor() == 3
|
||||
|
||||
def test_returns_zero_when_no_entries(self, store):
|
||||
store.history_file.write_text("", encoding="utf-8")
|
||||
|
||||
assert store.get_latest_cursor() == 0
|
||||
|
||||
def test_matches_next_cursor_minus_one(self, store):
|
||||
store.append_history("event 1")
|
||||
store.append_history("event 2")
|
||||
|
||||
assert store.get_latest_cursor() == max(store._next_cursor() - 1, 0)
|
||||
|
||||
def test_set_and_get_cursor(self, store):
|
||||
store.set_last_dream_cursor(5)
|
||||
assert store.get_last_dream_cursor() == 5
|
||||
|
||||
Reference in New Issue
Block a user