Scheduler run contexts accumulate forever: one persisted chat per run, no eviction (and state_snapshot disagrees with get_task_by_run_id on previous_run_id) #119
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
nsaspy/a0-symbolics#119
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Commit
0b62cccb("fix: isolate scheduler run contexts", PR #111, in main atbba5dcba) creates a freshAgentContextwithid=run_idfor every task occurrence and persists it withsave_tmp_chat(helpers/task_scheduler.py:998and:1056,:1152,:1207). These run contexts areAgentContextType.TASK(not BACKGROUND), sosave_tmp_chat(helpers/persist_chat.py:50-60) writes a chat file tousr/chats/<run_id>/on every run. No code path ever removes them:helpers/task_scheduler.pycontains noAgentContext.remove/remove_chatcall, and the scheduler's own delete path (api/scheduler_task_delete.py:31-42) only removes the legacytask.uuidcontext and resets the current run context — previous run contexts are never cleaned.Repro
task-steward-gate, cron*/20).ls usr/chats | wc -lgrows by one directory per run occurrence (72/day for a 20-minute cadence). On the live instance, 73 chat folders exist with only 8 referenced by task run/context IDs — the rest accumulate as orphans.Impact
usr/chats/proportional to schedule frequency.AgentContext._contextsin-memory until process restart (nothing evicts it), holding agent history/log references.helpers/state_snapshot.py:312-320only maps a run context to a task whenctx.idis the task'scurrent_run_idorlast_run_id. Contexts of previous runs fail that re-check (get_task_by_run_idathelpers/task_scheduler.py:739-752does matchprevious_run_id, butstate_snapshot.py:315-317then nulls it because the id isn't current/last), so old run contexts fall through tolegacy_tasklookup (:318-320, requireslast_run_id is None— false for any run task) and are emitted as plain chats inctxs.Location
helpers/task_scheduler.py:989-1012(_new_run_context),:1056and:1152/:1207(_persist_chatcalls),:947-982(_finish_run— no cleanup).helpers/state_snapshot.py:312-320(previous-run contexts leak into the chats list).bba5dcba; introduced in0b62cccb(2026-09-06).Suggested fix
_finish_run, after promoting the newlast_run_id, evict the previous run:AgentContext.remove(task.previous_run_id)+persist_chat.remove_chat(task.previous_run_id)when it differs fromcurrent_run_id/last_run_idand is not a legacytask.context_id.AgentContextType.BACKGROUNDsosave_tmp_chatskips them, and keep only the task-levelprevious_run_output(already bounded to 32 KiB) as the durable record; the WebUI task detail already rendersprevious_run_outputfrom task serialization, not from the chat.state_snapshot.pyconsistent withget_task_by_run_id(either includeprevious_run_idin the snapshot re-check or drop the redundant re-check entirely — today the two disagree aboutprevious_run_id).