Skip to content

fix: filter automated turns from cache warming gap histograms#270

Merged
BYK merged 1 commit into
mainfrom
fix/cache-warming-gap-pollution
May 12, 2026
Merged

fix: filter automated turns from cache warming gap histograms#270
BYK merged 1 commit into
mainfrom
fix/cache-warming-gap-pollution

Conversation

@BYK
Copy link
Copy Markdown
Owner

@BYK BYK commented May 12, 2026

Summary

  • Fix gap histogram pollution: Subagent turns and tool-use auto-continuations were recording sub-second inter-turn gaps into the survival model, skewing it toward predicting very short return times. Gap recording is now guarded with !isSubagentTurn && prevStopReason !== "tool_use", and a new lastUserTurnTime field tracks only genuine human-initiated turns.
  • Remove hardcoded time slots: Replaced the work/evening/night time-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

File Change
packages/gateway/src/translate/types.ts Added lastUserTurnTime, removed TimeSlot/SurvivalModel, simplified to InterTurnHistogram
packages/gateway/src/pipeline.ts Guarded gap recording, captures prevStopReason before overwrite, initializes lastUserTurnTime
packages/gateway/src/cache-warmer.ts Removed resolveTimeSlot(), single histogram model, backward-compat DB merge on load
packages/gateway/src/idle.ts Removed slot resolution
packages/gateway/src/ui.ts Single histogram per project in dashboard
packages/gateway/test/cache-warmer.test.ts 10 new gap filtering tests, removed time-slot tests
packages/gateway/test/helpers/idle-worker.ts Updated mock and session state

Test results

  • All 1301 tests pass across 55 files
  • All 4 packages typecheck cleanly

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.
@BYK BYK force-pushed the fix/cache-warming-gap-pollution branch from 36187c3 to f90c486 Compare May 12, 2026 21:12
@BYK BYK merged commit 2877998 into main May 12, 2026
7 checks passed
@BYK BYK deleted the fix/cache-warming-gap-pollution branch May 12, 2026 21:15
This was referenced May 13, 2026
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.

1 participant