mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-11-16 11:19:33 +01:00
fix: refuse a case folder move while a session is still being created in it (release review)
The rename lock is checked once, in the Session constructor, but a session
reaches the server's map (where the rename route builds its list of open
sessions) only later, after the create awaits the owner's layout lock and a
fresh settings read (and, for POST /api/sessions, inferLocalCaseName). A
rename in that gap neither listed nor stopped the session, moved the folder,
and the create then registered a session whose pane starts with
`cd "<old path>"`, skipping the 409 requiresStop / stopSessions guarantee.
- case-rename.ts keeps a record of sessions constructed but not yet
registered (`noteCaseSessionStarting` / `caseSessionSettled` /
`isCaseSessionStarting`), with a 30 s TTL for one that never registers
(a failed create, a one-shot prompt), swept on every note and check.
- The Session constructor records itself (local sessions only, as the
route ignores remote ones); registerSessionWithLayout()'s register
callback, the boot-restore registration and stop() settle it.
- The rename route answers 409 CONFLICT with renameCode BUSY ("A session is
starting in this case") for a folder move while one is recorded at or
under the folder. The check runs in the same tick that takes the lock, so
every interleaving is either refused here or by the constructor. An
alias-only rename is not refused.
A create whose path was validated before the move but whose Session is
constructed after it is still the ordinary check-then-use race of any
create path; CLAUDE.md now says so instead of "nothing starts mid-move".
Tests: unit (record, settle, stop, TTL), route (BUSY, then requiresStop once
registered; alias-only unaffected) and an end-to-end WebServer test that
holds the create between constructor and registration (it fails without
the route check: the folder moves under the session).
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
40158ce1ef
commit
f8029c2a9e
10 files changed
+238
-7
No files matched your search
+7
-1
@@ -151,7 +151,7 @@ import {
|
||||
} from './session-attachment-history.js';
|
||||
import type { SessionAttachmentHistoryItem, DisplayModel } from './types/session.js';
|
||||
import { resolveConfigModel } from './model-config-resolvers.js';
|
||||
import { isCasePathLocked } from './case-rename.js';
|
||||
import { caseSessionSettled, isCasePathLocked, noteCaseSessionStarting } from './case-rename.js';
|
||||
import { legacyConfigForMode } from './session-cli-registry-bridge.js';
|
||||
import {
|
||||
launchModelFor,
|
||||
@@ -954,6 +954,10 @@ export class Session extends EventEmitter {
|
||||
if (config.workingDir && isCasePathLocked(config.workingDir)) {
|
||||
throw new Error(`The case folder ${config.workingDir} is being renamed. Try again in a moment.`);
|
||||
}
|
||||
// And a rename must not start until this session is in the server's map, where it can be listed and
|
||||
// stopped: until registerSessionWithLayout() (or stop()) settles it, the rename route refuses the move.
|
||||
// A remote session's workingDir is the remote path, which the route never counts as the folder's.
|
||||
if (config.workingDir && !config.remote) noteCaseSessionStarting(this, config.workingDir);
|
||||
this.setMaxListeners(25);
|
||||
|
||||
// Default error handler prevents unhandled 'error' events from crashing the process.
|
||||
@@ -5181,6 +5185,8 @@ export class Session extends EventEmitter {
|
||||
async stop(killMux: boolean = true): Promise<void> {
|
||||
// Set stopped flag first to prevent new timers from being created
|
||||
this._isStopped = true;
|
||||
// A session stopped before it was registered (a create that failed) no longer holds up a case rename.
|
||||
caseSessionSettled(this);
|
||||
// A pane that is gone is watching nothing. Nothing probes a stopped session, so
|
||||
// without this the last chip it drew would ride along on its row forever.
|
||||
this._watching = null;
|
||||
|
||||
Reference in new issue
Block a user