fix(core): isolate scheduled prompt sessions by default - #1651
Open
AaronZ345 wants to merge 2 commits into
Open
Conversation
AaronZ345
force-pushed
the
fix/cron-busy-side-session-20260806
branch
3 times, most recently
from
August 13, 2026 14:44
bf770ec to
0ef2daa
Compare
AaronZ345
force-pushed
the
fix/cron-busy-side-session-20260806
branch
from
August 14, 2026 14:43
0ef2daa to
1093542
Compare
chenhg5
approved these changes
Aug 15, 2026
chenhg5
left a comment
Owner
There was a problem hiding this comment.
Conclusion: Approve
Overall assessment:
This PR flips the default session mode for cron/timer prompt jobs from reuse to new_per_run, fixing the long-standing busy-session conflict where scheduled jobs competed with active chat turns. Behavior change is intentional, fully documented, and gated behind a clean opt-out (session_mode = "reuse"). Local go test -race ./... -count=1 -timeout 60s passes for the in-scope packages (core, config, cmd/cc-connect with -tags no_web); the only failing targets are pre-existing env issues (missing web/dist, cursor login requirement) and are unrelated to this patch.
Review scope:
- Read
core/cron.go,core/timer.go,core/interfaces.go,cmd/cc-connect/{cron,timer}.go,config/config.go,config.example.toml, all updated tests, and the touched doc files. - Walked through
NormalizeCronSessionMode,UsesNewSession,validateCronJob,UpdateJob, and the two scheduler constructors to confirm the new default and the explicit-reuse path are wired end-to-end. - Ran
go test -race ./core ./config ./cmd/cc-connect(with-tags no_web); all pass. The two unrelated failures (cmd/cc-connectwithoutno_webneedsweb/dist;agent/acp.TestCursorCLI_ACPHandshakeneedsagent login) reproduce onmainand are not regressions.
✅ What looks good:
defaultScheduledSessionModeas a single named constant removes the previous "empty string means reuse" ambiguity.NormalizeCronSessionModenow distinguishes""(inherit default),"reuse", and"new_per_run"cleanly.validateCronJobandUpdateJobboth accept the explicitreusevalue with a clear error message — opt-out is well supported.- The CHANGELOG entry is concise and tells users exactly what to do if they need the old behavior.
- The CLI help text, the management API docs (both EN and ZH-CN), and
config.example.tomlwere all updated consistently. The--session-modeand[cron].session_modedefaults are flipped everywhere users could discover them. TestExecuteCronJob_ResolvesCronReplyTargetwas correctly retrofitted withSessionMode: "reuse". That single-character edit shows the author understood the default flip and audited the test corpus.
🟠 Should improve:
- Merge ordering: this PR is the prerequisite for #1650 (hide scheduler background sessions). On its own, #1650 is dormant because
defaultSessionMode == ""meansuseNewSession=falseandNewBackgroundSessionis never reached. The CHANGELOG doesn't mention this dependency; merging them out of order leaves #1650 silently invisible to default users. Worth a brief coordination note in the PR body or in the team handoff. - Migration audit: only one existing test (
TestExecuteCronJob_ResolvesCronReplyTarget) was updated for the new default. Any other test that exercisesExecuteCronJob/ExecuteTimerJobwith an emptySessionModewould have changed semantics silently. I ran the targeted test set (TestExecuteCronJob_*,TestExecuteTimerJob_*,TestSessionManager_*,TestValidateTimerJob,TestMgmt_CronExecByID) and all pass, but a CI run on the fullgo test ./...should confirm there are no other implicit-dependency tests in the suite that this author missed. - Implicit config-default flip:
[cron]section inconfig.example.tomlchanges the documented default fromreusetonew_per_run. Operators who copyconfig.example.tomlas a starting point will silently get the new behavior even if their previouscc-connect.tomlhad no[cron]block. This is fine but is the kind of thing that shows up as a "why did my cron behavior change?" support ticket later. Consider adding a one-line "since vX.Y, default is nownew_per_run" callout indocs/usage.md(currently the prose was rewritten but doesn't carry a "changed in this release" anchor).
🔵 Optional:
- The dead-code
"" / "reuse"collapse removed inNormalizeCronSessionModeis good — but the comment block abovedefaultScheduledSessionModecould mention the previous "empty == reuse" semantic so future readers understand why the constant exists. TestCronScheduler_AddJob_NormalizesSessionModenow also asserts that""round-trips as"". Adding at.Cleanup-style assertion that an invalid mode (e.g."foobar") is rejected at validation would lock the current behavior in case someone refactorsNormalizeCronSessionModelater.
❓ Questions:
- Did you audit the Web management API's cron-create/edit forms for any UI elements that hard-code
reuseas the default radio button / dropdown selection? If the UI sends back whatever it displays, that would mask the new backend default for users who touch cron jobs through the web console.
Testing / Risk:
- Verified:
go test -race ./core ./config ./cmd/cc-connectwith-tags no_webis green.TestCronScheduler_UsesNewSession_GlobalDefault,TestTimerScheduler_UsesNewSession_Defaults,TestValidateTimerJob, andTestExecuteCronJob_ResolvesCronReplyTargetall pass. - Unverified risk: any consumer of
NormalizeCronSessionModeoutsidecore/andcmd/cc-connect/(e.g.web/,tests/blackbox/) that relies on""collapsing to "reuse" would now see different behavior. Worth a quickgrep -rn "NormalizeCronSessionMode" --include="*.go"to confirm scope.
Next step:
- Land this PR first; then immediately follow with #1650 so the new default is paired with the hide-from-list behavior. Update the management API web form defaults in a follow-up if any UI elements still show
reuseas the default selection.
AaronZ345
force-pushed
the
fix/cron-busy-side-session-20260806
branch
from
August 15, 2026 14:44
1093542 to
a5842a8
Compare
AaronZ345
force-pushed
the
fix/cron-busy-side-session-20260806
branch
from
August 16, 2026 14:44
a5842a8 to
4b4221e
Compare
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
session_mode = "reuse"or--session-mode reuseis set explicitly.Root cause
Scheduled prompt jobs inherited the active chat session by default. When a cron fired while the user session was already busy, it could fail with a busy-session error or wait behind unrelated interactive work. The scheduled task should be isolated by default instead of competing with normal chat turns.
Test Plan
go test -count=1 ./core ./configGOOS=linux GOARCH=amd64 go test -c -tags no_web ./cmd/cc-connectgit diff --checkSupersedes #1349. This is the same rebased patch on a fresh PR branch.
Supersedes #1496. This fresh replacement carries the same patch rebased onto the latest
mainafter the original PR exceeded 30 days.