Skip to content

[codex] Fix scheduled state leaking into new chats#1018

Merged
tpae merged 4 commits into
osaurus-ai:mainfrom
mimeding:codex/fix-scheduled-chat-state
May 4, 2026
Merged

[codex] Fix scheduled state leaking into new chats#1018
tpae merged 4 commits into
osaurus-ai:mainfrom
mimeding:codex/fix-scheduled-chat-state

Conversation

@mimeding
Copy link
Copy Markdown
Contributor

@mimeding mimeding commented May 4, 2026

Business rationale

New chats created from the chat UI must be classified as manual chats. When schedule metadata leaks into those chats, users lose trust in sidebar filters and cannot reliably distinguish scheduled automation from manually started work.

Coding rationale

ChatWindowState.startNewChat() reuses the current ChatSession instance and calls reset(for:). ChatSession.reset() cleared content and identity but left source metadata intact, so the first save of the next manual chat reused .schedule, externalSessionKey, and dispatch metadata from the previously selected session. Resetting these fields beside sessionId keeps the session origin contract local to the session reset boundary.

What changed

  • Reset source, sourcePluginId, externalSessionKey, and dispatchTaskId to manual-chat defaults in ChatSession.reset().
  • Added regression tests covering reset from a scheduled session and the first saved manual turn after reset.

Validation

  • git fetch origin main && git rebase origin/main
  • swift build --package-path Packages/OsaurusCore
  • swift build -c release --package-path Packages/OsaurusCore
  • swift test --package-path Packages/OsaurusCore
  • xcrun swift-format lint --configuration .swift-format Packages/OsaurusCore/Views/Chat/ChatView.swift Packages/OsaurusCore/Tests/Chat/SessionSourcePersistenceTests.swift
  • swiftlint lint Packages/OsaurusCore/Views/Chat/ChatView.swift Packages/OsaurusCore/Tests/Chat/SessionSourcePersistenceTests.swift
  • git diff --check

Non-scope

  • Did not change schedule execution, dispatch reattachment, sidebar filtering, or persisted data migrations.
  • Did not address pre-existing SwiftLint warnings in ChatView.swift outside the touched hunk.

Residual risks

The fix relies on all UI-created manual chats flowing through ChatSession.reset(). Programmatic dispatch paths still explicitly set their own source metadata through ExecutionContext.

Manual chats should always start from chat defaults, even when the reused window session previously displayed a scheduled run. Resetting the origin metadata with the session identity prevents sidebar filtering and badges from inheriting schedule state.

Add regression coverage for resetting a scheduled session and saving the first manual turn afterward.
@mimeding
Copy link
Copy Markdown
Contributor Author

mimeding commented May 4, 2026

@tpae PR-specific CI note / next step:

This PR is currently failing test-core on the shared provider/model-picker race from main, not on the scheduled-chat state-leak fix. The red tests are the same RemoteProviderManagerRefreshTests / ModelPickerItemCacheTests cluster seen on main after #1020.

Required next step: merge the green base fix in #1025 first, then I will rebase/rerun this PR and update the status.

Why: this PR's diff is unrelated to provider refresh/model picker caching, so debugging it before #1025 lands would chase the wrong failure.

@tpae tpae merged commit 6a9689f into osaurus-ai:main May 4, 2026
5 checks passed
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.

3 participants