Skip to content

fix: clear scheduled job context before each invocation (#301) - #302

Merged
mattmezza merged 1 commit into
mainfrom
kindral/clear-job-context
Jul 19, 2026
Merged

fix: clear scheduled job context before each invocation (#301)#302
mattmezza merged 1 commit into
mainfrom
kindral/clear-job-context

Conversation

@kindralai

@kindralai kindralai Bot commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Problem

Recurring scheduled jobs (e.g. scheduler:proactive-mail-triage, which runs hourly between 8 AM and 7 PM) accumulate conversation history across invocations. Each run adds its input and output to the same history key. Over time this causes:

  • Growing token costs — each run starts with the full history of all previous runs loaded into context
  • Cache invalidation — the long context means the model's prompt cache rarely hits
  • Degraded relevance — the model sees old job outputs mixed with the current task
  • Eventual slowdown — as the history grows, the LLM call takes longer and costs more

Issue #235 / PR #236 gave each job its own context key, but a single recurring job's own context still grows unbounded.

Solution

Send a /new command via agent.process() to clear the job's history key before each invocation. Applied to both run_agent_task() and run_subagent_task().

Note on respond=: The issue suggested respond=False, but the _process_impl respond-gate (line 1348) returns early before reaching the /new handler when respond=False — it just records the command as an inbound message. Using respond=True processes the /new command and clears context. The "Conversation cleared." response is discarded by the caller (not assigned or delivered).

Changes

File Change
humux/core/scheduler.py Add /new context clearing in run_agent_task() and run_subagent_task() before the actual task runs

Acceptance criteria

Closes #301

Recurring jobs accumulate conversation history across invocations —
each run appends to the same context key, causing growing token costs,
cache misses, and degraded relevance.

Send a /new command to clear the job's context key before each
invocation, in both run_agent_task() and run_subagent_task(). The
respond=True parameter is required because respond=False would just
record the command as an inbound message without processing it; the
'Conversation cleared.' response is discarded since the caller doesn't
deliver it.

Note: the issue suggested respond=False, but the _process_impl
respond-gate returns early before reaching the /new handler when
respond is False.

Closes #301
@kindralai
kindralai Bot requested a review from mattmezza July 19, 2026 10:36

@mattmezza mattmezza left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

merge it @kindralai[bot]

@mattmezza
mattmezza merged commit 3736b88 into main Jul 19, 2026
3 checks passed
@mattmezza
mattmezza deleted the kindral/clear-job-context branch July 19, 2026 10:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Recurring scheduled jobs accumulate context across invocations — needs /new before each run

1 participant