Skip to content

Remote connection state: lossless lease scope identity and serialized legacy migration #4946

Open

Description

@thymikee

Follow-up to #4925 (review: #4925 (comment)). These items are out of scope for that PR.

Lease scope from a lossless session identity

The leased-profile scope hash in packages/remote/src/remote-connection-state.ts (around line 454) hashes the session as UTF-8. Lone surrogates such as U+D800 and U+D801 both encode as U+FFFD, so two sessions derive the same run and client IDs. The second open then gets the first session's lease ID back (src/cli/commands/connection-lease-transaction.ts, packages/daemon/src/resources/lease-registry.ts) and can release it on disconnect.

  • Derive new leased-profile scopes from a lossless session identity (for example UTF-16LE).
  • Keep the stored scope when the exact owning session loads its record.
  • Prevent new sessions from deriving an old lossy scope.

Cross-process serialization of legacy record migration

#4925 moves a legacy record to its owner's canonical path with a hard link and then an unlink. No lock covers this.

  • Serialize owner checks, retirement and claims of any legacy pathname while it can still alias the destination of another session.

Activity

  1. apex-sentinel-staging commented on Nov 22, 2026

    @apex-sentinel-staging

    Apex Sentinel · Issue review

    Suggested label: bug

    The report identifies concrete existing behavior where UTF-8 session hashing collides for lone surrogates, causing lease ID reuse/release, and notes a missing lock for legacy record migration. It includes file locations and actionable follow-up tasks.

    Required sections

    • Steps to reproduce (missing)
    • Expected and actual behavior (missing)
    • Version or environment (missing)
  2. thymikee commented on Nov 22, 2026

    @thymikee
    MemberAuthor
  3. thymikee commented on Nov 22, 2026

    @thymikee
    MemberAuthor

    More follow-ups from #4925 (comment):

    • Use the observation-only lookup on other read sites: resolveRemoteConnectionDefaults, the connect preflight, and the ended-lease rewrite.
    • Handle ENOTSUP from linkSync on volumes without hard links during legacy migration.
    • Report connection_record_owner_unknown instead of a raw errno when the directory is read-only and the session's own file is unreadable.
  4. thymikee commented on Nov 22, 2026

    @thymikee
    MemberAuthor
  5. thymikee commented on Nov 22, 2026

    @thymikee
    MemberAuthor

    Follow-ups from #4925 (a session literally named .active-session whose full record sits at the pointer path; the collision predates #4925):

    • Unnamed disconnect of a legacy .active-session record: after the checked hard link, atomically replace the full record at the pointer path with a pointer to the same owner, and let owner-checked pointer cleanup remove it after teardown (remote-connection-state.ts:794).
    • Failed save that retires a full record from the active path: replace it with a pointer to its verified owner, and overwrite that pointer with the new selection only after the new session record is committed (remote-connection-state.ts:384, 831, 392).
  6. thymikee commented on Nov 22, 2026

    @thymikee
    MemberAuthor

    ADR 0040 alignment (ADR)

    Decision: saved connections: Use #4973 for lossless scope derivation, exact-owner scope preservation and serialized legacy alias claims. Amend #4973 with the observation-only readers, legacy .active-session collision, typed unreadable and read-only failures, and platforms without hard links. Resolve the two optional recovery policies explicitly: force-disconnect of corrupt records and read-only default-to-pointer fallback. Keep this open until those residuals are assigned. #4947 already blocks labels-only refresh. Keep a client regression for lossless session identities and exact-owner release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions