Commit 6d3306b
fix: prevent phantom (previous) sessions from lazy-resume fallback (#584)
## What
When lazy-resume fails (CLI returns "Session not found" / corrupt /
shutdown) and creates a fresh session, the old persisted entry was not
being marked as superseded. On the next `SaveActiveSessionsToDisk`,
`MergeSessionEntries` found both old and new entries with the same
display name and renamed the old one to `"(previous)"`.
## Root cause
The lazy-resume fallback in `EnsureSessionConnectedAsync` creates a
fresh session but didn't:
1. Set `RecoveredFromSessionId` — so
`CanSafelyDropSupersededGroupMoveEntry` returned false
2. Add the old session ID to `_closedSessionIds` — so the merge didn't
filter it out
## Fix
Two lines after the fresh session is created:
- `state.Info.RecoveredFromSessionId ??= sessionId` — marks the new
session as the successor
- `_closedSessionIds.TryAdd(sessionId, 0)` — ensures the merge drops the
old entry
## Real-world trigger
Observed on session "34678": the CLI shut down the original session
(`session.shutdown` at 02:57 UTC). After app restart, lazy-resume got
"Session not found", created a fresh session, but left the old entry on
disk → "34678 (previous)" appeared.
## Testing
3335/3335 tests pass.
---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent fa06232 commit 6d3306b
3 files changed
Lines changed: 116 additions & 0 deletions
File tree
- PolyPilot.Tests
- PolyPilot/Services
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1790 | 1790 | | |
1791 | 1791 | | |
1792 | 1792 | | |
| 1793 | + | |
| 1794 | + | |
| 1795 | + | |
| 1796 | + | |
| 1797 | + | |
| 1798 | + | |
| 1799 | + | |
| 1800 | + | |
| 1801 | + | |
| 1802 | + | |
| 1803 | + | |
| 1804 | + | |
| 1805 | + | |
| 1806 | + | |
| 1807 | + | |
| 1808 | + | |
| 1809 | + | |
| 1810 | + | |
| 1811 | + | |
| 1812 | + | |
| 1813 | + | |
| 1814 | + | |
| 1815 | + | |
| 1816 | + | |
| 1817 | + | |
| 1818 | + | |
| 1819 | + | |
| 1820 | + | |
| 1821 | + | |
| 1822 | + | |
| 1823 | + | |
| 1824 | + | |
| 1825 | + | |
| 1826 | + | |
| 1827 | + | |
| 1828 | + | |
| 1829 | + | |
| 1830 | + | |
| 1831 | + | |
| 1832 | + | |
| 1833 | + | |
| 1834 | + | |
| 1835 | + | |
| 1836 | + | |
| 1837 | + | |
| 1838 | + | |
| 1839 | + | |
| 1840 | + | |
| 1841 | + | |
| 1842 | + | |
| 1843 | + | |
| 1844 | + | |
| 1845 | + | |
| 1846 | + | |
| 1847 | + | |
| 1848 | + | |
| 1849 | + | |
| 1850 | + | |
| 1851 | + | |
| 1852 | + | |
| 1853 | + | |
| 1854 | + | |
| 1855 | + | |
| 1856 | + | |
| 1857 | + | |
| 1858 | + | |
| 1859 | + | |
| 1860 | + | |
| 1861 | + | |
| 1862 | + | |
| 1863 | + | |
| 1864 | + | |
| 1865 | + | |
| 1866 | + | |
| 1867 | + | |
| 1868 | + | |
| 1869 | + | |
| 1870 | + | |
| 1871 | + | |
| 1872 | + | |
| 1873 | + | |
| 1874 | + | |
| 1875 | + | |
| 1876 | + | |
| 1877 | + | |
| 1878 | + | |
| 1879 | + | |
| 1880 | + | |
| 1881 | + | |
| 1882 | + | |
| 1883 | + | |
| 1884 | + | |
| 1885 | + | |
| 1886 | + | |
| 1887 | + | |
| 1888 | + | |
| 1889 | + | |
| 1890 | + | |
1793 | 1891 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
442 | 442 | | |
443 | 443 | | |
444 | 444 | | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
445 | 448 | | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
446 | 453 | | |
447 | 454 | | |
448 | 455 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3858 | 3858 | | |
3859 | 3859 | | |
3860 | 3860 | | |
| 3861 | + | |
3861 | 3862 | | |
3862 | 3863 | | |
3863 | 3864 | | |
| |||
3887 | 3888 | | |
3888 | 3889 | | |
3889 | 3890 | | |
| 3891 | + | |
| 3892 | + | |
| 3893 | + | |
3890 | 3894 | | |
| 3895 | + | |
| 3896 | + | |
3891 | 3897 | | |
3892 | 3898 | | |
3893 | 3899 | | |
| |||
3914 | 3920 | | |
3915 | 3921 | | |
3916 | 3922 | | |
| 3923 | + | |
| 3924 | + | |
| 3925 | + | |
3917 | 3926 | | |
| 3927 | + | |
| 3928 | + | |
3918 | 3929 | | |
3919 | 3930 | | |
3920 | 3931 | | |
| |||
0 commit comments