Fix new sessions to inherit last used variant from previous session (Vibe Kanban) (#1870)
* The implementation is complete. Here's a summary of the changes:
## Summary
Fixed the issue where new sessions were inheriting the last used executor but not the last used variant.
### Changes Made to `vibe-kanban/frontend/src/components/ui-new/containers/SessionChatBoxContainer.tsx`:
1. **Added import** for `useExecutionProcesses` hook
2. **Added `lastSessionId`** - gets the most recent session's ID only when in new session mode:
```tsx
const lastSessionId = isNewSessionMode ? sessions?.[0]?.id : undefined;
```
3. **Added `useExecutionProcesses` call** - fetches processes from the last session to get the full executor profile:
```tsx
const { executionProcesses: lastSessionProcesses } =
useExecutionProcesses(lastSessionId);
```
4. **Added `lastSessionProfile` memo** - extracts the full profile (executor + variant) from the last session's processes:
```tsx
const lastSessionProfile = useMemo(() => {
if (!lastSessionProcesses?.length) return null;
return getLatestProfileFromProcesses(lastSessionProcesses);
}, [lastSessionProcesses]);
```
5. **Updated `latestProfileId` computation** - now uses `lastSessionProfile` (which includes the variant) before falling back to just the executor with `variant: null`
The type check passes successfully. When a user creates a new session, it will now correctly inherit both the executor AND variant from the most recently used session in that workspace.
* Done! The refactoring is complete. Here's a summary of the changes:
## Summary
Refactored the `latestProfileId` logic in `SessionChatBoxContainer.tsx` to be cleaner:
**Before:** 4 separate declarations
- `lastSessionExecutor` memo
- `lastSessionId`
- `lastSessionProcesses` hook
- `lastSessionProfile` memo
- `latestProfileId` memo (referencing all the above)
**After:** 3 declarations, consolidated
- `lastSessionId`
- `lastSessionProcesses` hook
- `latestProfileId` memo (all logic inlined)
**Changes:**
- Removed 2 intermediate `useMemo` hooks
- Inlined `lastSessionExecutor` and `lastSessionProfile` directly into `latestProfileId`
- Same 3-tier fallback behavior preserved: current processes → last session processes → session metadata
- Type check passes
This commit is contained in:
committed by
GitHub
parent
7d75a73fc8
commit
6a07e5cc16
@@ -6,6 +6,7 @@ import {
|
||||
type BaseCodingAgent,
|
||||
} from 'shared/types';
|
||||
import { useAttemptExecution } from '@/hooks/useAttemptExecution';
|
||||
import { useExecutionProcesses } from '@/hooks/useExecutionProcesses';
|
||||
import { useUserSystem } from '@/components/ConfigProvider';
|
||||
import { useApprovalFeedbackOptional } from '@/contexts/ApprovalFeedbackContext';
|
||||
import { useMessageEditContext } from '@/contexts/MessageEditContext';
|
||||
@@ -176,21 +177,23 @@ export function SessionChatBoxContainer({
|
||||
// User profiles, config preference, and latest executor from processes
|
||||
const { profiles, config } = useUserSystem();
|
||||
|
||||
// Get last used executor from the most recently used session in this workspace
|
||||
const lastSessionExecutor = useMemo(() => {
|
||||
if (!sessions?.length) return null;
|
||||
// Sessions are sorted by most recently used (first is most recent)
|
||||
const mostRecentSession = sessions[0];
|
||||
return mostRecentSession?.executor ?? null;
|
||||
}, [sessions]);
|
||||
// Fetch processes from last session to get full profile (only in new session mode)
|
||||
const lastSessionId = isNewSessionMode ? sessions?.[0]?.id : undefined;
|
||||
const { executionProcesses: lastSessionProcesses } =
|
||||
useExecutionProcesses(lastSessionId);
|
||||
|
||||
// Compute latestProfileId: from processes, or fall back to last session's executor
|
||||
// Compute latestProfileId: current processes > last session processes > session metadata
|
||||
const latestProfileId = useMemo(() => {
|
||||
// If we have processes (existing session), use them
|
||||
// Current session's processes take priority
|
||||
const fromProcesses = getLatestProfileFromProcesses(processes);
|
||||
if (fromProcesses) return fromProcesses;
|
||||
|
||||
// Fall back to last session's executor (useful for new session mode)
|
||||
// Try full profile from last session's processes (includes variant)
|
||||
const fromLastSession = getLatestProfileFromProcesses(lastSessionProcesses);
|
||||
if (fromLastSession) return fromLastSession;
|
||||
|
||||
// Fallback: just executor from session metadata, no variant
|
||||
const lastSessionExecutor = sessions?.[0]?.executor;
|
||||
if (lastSessionExecutor) {
|
||||
return {
|
||||
executor: lastSessionExecutor as BaseCodingAgent,
|
||||
@@ -199,7 +202,7 @@ export function SessionChatBoxContainer({
|
||||
}
|
||||
|
||||
return null;
|
||||
}, [processes, lastSessionExecutor]);
|
||||
}, [processes, lastSessionProcesses, sessions]);
|
||||
|
||||
// Message editor state
|
||||
const {
|
||||
|
||||
Reference in New Issue
Block a user