fix(rpc): refuse move_session copy ids the parser let through (#5930)

SU
15d ago
+122-5

Follow-up to #5920 (part 2 of #5889, move_session op copy). Fixes #5930 — both review LOWs recorded there instead of folded after the CLEAR.

What changed

  • session-move-request.ts (parseCopy): the copy sessionId now passes the same rule forkFrom applies (assertValidSessionId), in addition to isPlainId. An id ending in ., _ or - (e.g. copy-, a.) is refused with invalid_move_request before anything is written, instead of passing the parser and failing as move_failed after the target folder was created.
  • session-manager.ts (forkFrom): the id is validated before the target folder is created, so a rejected fork no longer leaves an empty folder behind.
  • session-move/copy.ts + new ownershipSessionIds helper in ownership.ts: copying a copy back under an id named by a session_id of an ownership entry the source inherited is refused with invalid_move_request. Previously only the source's own header id was refused, so the copy answered success: true but refused every write.
  • docs/rpc.md copy paragraph updated in the same increment.

Tests (RED → GREEN)

New regression tests, all failing on the pre-fix code for the intended reason and passing after:

  • test/suite/rpc-move-session-copy.test.ts: trailing-separator ids copy- / a. added to the refusal table (pre-fix: move_failed); new copy-back test — copy a revoked import under copy-5889, then copy that copy under the older inherited id (pre-fix: success: true).
  • test/session-manager/custom-session-id.test.ts: forkFrom with id copy- into a not-yet-created folder throws and the folder stays uncreated (pre-fix: folder created).

bun run --cwd packages/coding-agent test test/suite/rpc-move-session-copy.test.ts test/session-manager/custom-session-id.test.ts: 21/21 passed (pre-fix: 17 passed, 4 failed). bun run check: exit 0 (lint, fmt, tsc, install-lock).

Fixes #5930


Summary by cubic

Fixes three gaps in the move_session copy operation (#5930): invalid IDs ending in ., _, or - are now refused before anything is written, a rejected fork no longer leaves an empty folder behind, and copying a copy back under an older inherited ownership ID is refused instead of answering success: true for a copy that would refuse every write.

Bug Fixes

  • parseCopy now applies the same ID rule as forkFrom, refusing trailing-separator IDs with invalid_move_request instead of failing as move_failed after the target folder was created.
  • forkFrom validates the ID before creating the target folder.
  • copySessionAs refuses a copy ID named by an ownership entry the source inherited.
  • Adds a changelog fragment for the fix.