fix: filter automated turns from cache warming gap histograms#270
Merged
Conversation
Subagent turns and tool-use auto-continuations were recording sub-second gaps into the survival model, causing it to overestimate P(return) at short windows. Two fixes: 1. Guard gap recording with !isSubagentTurn && prevStopReason !== 'tool_use'. Add lastUserTurnTime field to SessionState so gaps measure real human think time, not time-since-last-automated-activity. 2. Replace hardcoded work/evening/night time slots with a single unsegmented histogram. The old slots assumed Western 9-5 hours and split observations 3x, hurting convergence. A single histogram adapts to actual user patterns. Old slot-segmented DB rows are merged on load for backward compatibility.
36187c3 to
f90c486
Compare
This was referenced May 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
!isSubagentTurn && prevStopReason !== "tool_use", and a newlastUserTurnTimefield tracks only genuine human-initiated turns.work/evening/nighttime-slot segmentation (hardcoded Mon-Fri 8-18 Western office hours) with a single unsegmented histogram per session/project. This adapts to any user's actual schedule, gives 3x more observations per histogram for faster convergence, and avoids the stale assumption of a 9-to-5 work pattern. Old slot-segmented DB rows are merged on load for backward compatibility.Changes
packages/gateway/src/translate/types.tslastUserTurnTime, removedTimeSlot/SurvivalModel, simplified toInterTurnHistogrampackages/gateway/src/pipeline.tsprevStopReasonbefore overwrite, initializeslastUserTurnTimepackages/gateway/src/cache-warmer.tsresolveTimeSlot(), single histogram model, backward-compat DB merge on loadpackages/gateway/src/idle.tspackages/gateway/src/ui.tspackages/gateway/test/cache-warmer.test.tspackages/gateway/test/helpers/idle-worker.tsTest results