#16511: feat(cron): support custom session IDs and auto-bind to current session
docs
app: macos
app: web-ui
gateway
agents
size: M
Cluster:
Cron Job Enhancements
Implements ZachQin's proposal from issue #9765
## Summary
Currently, cron jobs only support two execution modes: main (runs in the main session) and isolated (creates ephemeral sessions). This limits the ability to have cron jobs contribute to persistent, named conversation contexts outside of the main session.
## Changes
This PR implements support for:
1. **"current" sessionTarget** - When creating a cron job from an active session (e.g., Telegram group/DM), using "current" will bind it to that session. The sessionKey is resolved at creation time and stored persistently as "session:<sessionKey>".
2. **Custom session IDs via "session:" prefix** - Users can now specify "session:project-alpha-daily" to have the cron job run in a persistent named session that maintains conversation context across runs.
## UX Improvements
As proposed by @ZachQin in #9765, this makes in-context cron creation much more intuitive. Users no longer need to look up and pass session keys - they can simply use "current" and the system binds to the current session context.
## Example Usage
```json
// Create a daily standup cron that persists context in the current channel
{
"name": "Daily Standup",
"schedule": { "kind": "cron", "expr": "0 9 * * *" },
"payload": { "kind": "agentTurn", "message": "Summarize yesterday's progress" },
"sessionTarget": "current"
}
// Or use a custom persistent session
{
"name": "Project Monitor",
"schedule": { "kind": "every", "everyMs": 300000 },
"payload": { "kind": "agentTurn", "message": "Check project status" },
"sessionTarget": "session:project-alpha-monitor"
}
```
## Default Behavior (Unchanged for Backward Compatibility)
- `payload.kind="systemEvent"` defaults to "main"
- `payload.kind="agentTurn"` defaults to "isolated"
To use current session binding, users must **explicitly** set `sessionTarget: "current"`.
## Backward Compatibility
- Existing jobs with "main" and "isolated" sessionTargets continue to work unchanged
- Default behavior remains the same - no automatic binding
- CLI/headless usage without session context maintains existing defaults
## Type System Updates
- Backend: `CronSessionTarget` now includes `"current"` and `session:${string}`
- UI: TypeScript types updated in `ui/src/ui/types.ts`
- macOS: Swift types updated with `CronCustomSessionTarget` enum to handle custom session IDs
Fixes #9765
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Adds support for custom session IDs and `"current"` sessionTarget binding for cron jobs, enabling persistent conversation contexts across cron runs.
**Key changes:**
- Extended `CronSessionTarget` type to support `"current"` and ``session:${string}`` formats
- `"current"` resolves to the session where the cron is created at creation time, stored as `session:<sessionKey>`
- Custom session IDs (e.g., `"session:project-alpha-daily"`) enable persistent named sessions
- Falls back gracefully to `"isolated"` when `"current"` is used without session context (CLI/headless)
- Comprehensive test coverage for edge cases (empty session keys, case normalization, fallback behavior)
- Documentation updated across English and Chinese versions
- Type system updated for UI (TypeScript) and macOS (Swift)
- Backward compatible: existing `"main"` and `"isolated"` jobs unchanged, defaults remain the same
**Implementation quality:**
- Proper normalization with whitespace trimming and case handling
- Validation ensures custom sessions require `payload.kind="agentTurn"`
- Delivery config correctly applied to all isolated-like targets (`"isolated"`, `"current"`, `session:xxx`)
- Swift types use enum for safe parsing of custom session IDs
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge with minimal risk
- The implementation is well-architected with comprehensive test coverage (13 new test cases covering edge cases), proper type safety across all platforms (TypeScript, Swift), thorough documentation updates, and backward compatibility preservation. The code correctly handles all edge cases including fallback behavior for unresolved "current" targets, empty session keys, and case normalization. The changes follow the repository's coding standards and patterns.
- No files require special attention
<sub>Last reviewed commit: 2db3e75</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#23562: feat: add sessionFreshness config for isolated cron jobs (#23539)
by MunemHashmi · 2026-02-22
81.0%
#23501: fix(cron): force new session ID for isolated cron jobs (#23470)
by stakeswky · 2026-02-22
79.5%
#16831: feat(status): group cron sessions for readability
by puritysb · 2026-02-15
77.5%
#6315: fix(cron): persist isolated sessions (fixes #6217) - attempt 2
by ChaitanyaSai-Meka · 2026-02-01
77.4%
#23431: feat(cron): add deferWhileActive to skip jobs during active sessions
by Dave-Pataky · 2026-02-22
76.9%
#23699: fix(cron): isolated sessions must generate fresh UUID on every run ...
by echoVic · 2026-02-22
76.8%
#15294: fix(cron): reset token counters when creating new isolated session
by Elarwei001 · 2026-02-13
75.7%
#20188: fix: Update sessionFile path when rolling to new session in cron jobs
by jriff · 2026-02-18
75.6%
#19998: macOS: harden cron editor updates and compatibility
by tobiasbischoff · 2026-02-18
74.2%
#8315: fix(cron): Add 'none' option to postToMainMode to prevent duplicate...
by vishaltandale00 · 2026-02-03
73.9%