fix: wake thinking scheduler immediately on user message #586

Closed
kimi wants to merge 0 commits from kimi/issue-582 into main
Collaborator

Summary

The thinking scheduler slept for a fixed 5-minute interval between cycles (asyncio.sleep(settings.thinking_interval_seconds)). When a user sent a message, record_user_input() only reset the idle timer but did NOT wake the scheduler. Worst case: a message arriving right after a cycle completed would wait ~11 minutes (5 min sleep + 2 min timeout + 5 min sleep) before being "registered" as a thought.

Fix

  • Added an asyncio.Event to ThinkingEngine that gets set when record_user_input() is called
  • Added wait_for_interval() method that replaces the fixed asyncio.sleep() with an interruptible wait
  • The scheduler now wakes immediately when a user message arrives, triggering a thought cycle without delay

Files changed

  • src/timmy/thinking.py — Added _wake_event, _get_wake_event(), updated record_user_input(), added wait_for_interval()
  • src/dashboard/app.py — Replaced asyncio.sleep() with thinking_engine.wait_for_interval()

Fixes #582

## Summary The thinking scheduler slept for a fixed 5-minute interval between cycles (`asyncio.sleep(settings.thinking_interval_seconds)`). When a user sent a message, `record_user_input()` only reset the idle timer but did NOT wake the scheduler. Worst case: a message arriving right after a cycle completed would wait ~11 minutes (5 min sleep + 2 min timeout + 5 min sleep) before being "registered" as a thought. ## Fix - Added an `asyncio.Event` to `ThinkingEngine` that gets set when `record_user_input()` is called - Added `wait_for_interval()` method that replaces the fixed `asyncio.sleep()` with an interruptible wait - The scheduler now wakes immediately when a user message arrives, triggering a thought cycle without delay ## Files changed - `src/timmy/thinking.py` — Added `_wake_event`, `_get_wake_event()`, updated `record_user_input()`, added `wait_for_interval()` - `src/dashboard/app.py` — Replaced `asyncio.sleep()` with `thinking_engine.wait_for_interval()` Fixes #582
kimi added 3 commits 2026-03-20 15:37:03 +00:00
The thinking engine was recording created_at after the LLM finished
generating a response, causing up to 11 minutes of timestamp drift
(interval wait + model latency + dedup retries). Now the timestamp
is captured at the beginning of think_once() and passed through to
_store_thought(), so thoughts reflect when the cycle started.

Fixes #582

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
fix: capture thought timestamp at cycle start, not after LLM call
All checks were successful
Tests / lint (pull_request) Successful in 5s
Tests / test (pull_request) Successful in 1m12s
1dd0f3ffe1
The thinking engine was recording created_at after the LLM generation
completed. With dedup retries and model latency this could accumulate
up to ~11 minutes of drift. Capture the timestamp before the LLM call
so the thought reflects when the cycle started.

Fixes #582

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Owner

@kimi This PR has merge conflicts with main. Please rebase your branch kimi/issue-582 onto latest main and force-push.

@kimi This PR has merge conflicts with main. Please rebase your branch `kimi/issue-582` onto latest main and force-push.
kimi added 1 commit 2026-03-20 15:44:30 +00:00
fix: wake thinking scheduler immediately on user message
All checks were successful
Tests / lint (pull_request) Successful in 2s
Tests / test (pull_request) Successful in 1m11s
53d85491bd
The thinking scheduler slept for a fixed 5-minute interval between
cycles, meaning user messages could wait up to ~11 minutes before
being "registered" as a thought. Replace the fixed asyncio.sleep()
with an interruptible wait using asyncio.Event that wakes immediately
when record_user_input() is called.

Fixes #582

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
kimi changed title from fix: capture thought timestamp at cycle start, not after LLM call to fix: wake thinking scheduler immediately on user message 2026-03-20 15:44:43 +00:00
Timmy closed this pull request 2026-03-20 15:52:08 +00:00
Owner

Closing PR — source branch was deleted. The fix described in this issue is still valid. Reopening the issue for re-implementation.

Closing PR — source branch was deleted. The fix described in this issue is still valid. Reopening the issue for re-implementation.

Pull request closed

Sign in to join this conversation.
No Reviewers
No Label
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Rockachopa/Timmy-time-dashboard#586