Persistent cron rotation starts a new chat, preserving the old one#167
Merged
Conversation
Rotation used to reset the SDK context in place: every context epoch piled
into one endless cron:{job_id} chat, and since the chat view only loads the
most recent messages, pre-rotation history was effectively invisible.
Now each persistent job runs in a generation chat (cron:{job_id}:{ts})
tracked via channel_sessions. Rotation retires the current chat untouched
(history, usage, and run-log links preserved; browsable like any session),
cancels its pending wakeups, stamps/retitles it, and mints a fresh chat for
subsequent runs. Legacy stable-id sessions are adopted on first run so
existing installs keep their context.
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.
Investigation
The suspicion was that persistent-cron auto-rotation loses the previous chat history. Findings:
sdk_session_id/connected_aton the stablecron:{job_id}session and scheduled memU indexing. E.g. a long-livedinbox-processorsession holds ~10.7K messages spanning 4 months of daily rotations — all still in the DB.Change
Persistent jobs now run in generation chats:
cron:{job_id}:{timestamp}); the job's current generation is tracked inchannel_sessionsunder the keycron:{job_id}.rotated_atin metadata, and retitles the chat with its end date (Cron: {job_id} (until 2026-07-05)).context_rotate_hours,context_rotate_at, manual rotate).connected_atstill marks the SDK context epoch.POST /api/cron/jobs/{id}/rotate) now retires + mints eagerly, and returnsold_session_id/new_session_id.cron:{job_id}) are adopted as the current generation on the first run after upgrade — SDK context carries over seamlessly — and move to the generation scheme at their next rotation. A rotated-out legacy session is never re-adopted.run_persistent_cronaccepts the resolvedsession_idfrom the cron service (falls back to the legacy id when omitted).Reminder mode, run-log session linking, notification session-label suppression (prefix-matched), and the CronPage chat link (
get_latest_cron_session_id) all work unchanged with generation ids.Tests