Skip to content

[CLI][v0.0.7] cortex delete removes session files but leaves stale entries in cortex lock list #53210

Description

@luis9a

Project

cortex-cli (lock_cmd, run_delete)

Description

General case: Deleting a resource should clear dependent bookkeeping (locks, indexes) or refuse with a clear path to unlock first.

Concrete case: cortex lock add <session-id> appends to ~/.cortex/session_locks.json. cortex delete <session-id> removes only the rollout file. cortex lock list can still show the id after deletion—orphaned lock rows. cortex sessions no longer lists the session, so state is inconsistent.

Root cause (this repo)

  • run_delete (src/cortex-cli/src/cli/handlers.rs ~687–725) resolves conversation_id, confirms, then remove_file on get_rollout_path (~716–720) only—no load_lock_file / save_lock_file, no call to is_session_locked.
  • is_session_locked (src/cortex-cli/src/lock_cmd.rs ~154–163) exists but is only defined there (grep shows no other callers)—delete path never consults it.
  • Lock persistence: get_lock_file_path, load_lock_file, save_lock_file (~117–152).

Fix direction (proposed)

  • On successful rollout delete, remove matching session_id entries from session_locks.json (full UUID match + prefix rules aligned with is_session_locked), or
  • bail! / prompt when locked unless --force, pointing to cortex lock remove.

Code snapshot

  • src/cortex-cli/src/cli/handlers.rsrun_delete (~687–725)
  • src/cortex-cli/src/lock_cmd.rsget_lock_file_path, load_lock_file, save_lock_file (~117–152); is_session_locked (~154–163); run_remove retain + save_lock_file (~256–291)

Error Message


(None — inconsistent on-disk state.)

Debug Logs

System Information

OS: typical reporter
CLI: cortex lock add … then cortex delete … (no manual lock remove)

Screenshots / Media

https://github.com/galuis116/plaftform_51/blob/main/2026-04-09_20h55_48.png

Steps to Reproduce

  1. cortex lock add <session-id>.
  2. cortex lock list — note entry.
  3. cortex delete <session-id> — confirm.
  4. cortex lock list — entry still there.
  5. cortex sessions --all — session gone.

Expected Behavior

Deletion clears the lock entry or blocks until unlocked / --force, with explicit copy.

Actual Behavior

Rollout removed; session_locks.json unchanged.

Duplicate check

Search terms: cortex delete, run_delete, session_locks.json, cortex lock, is_session_locked, get_rollout_path.

Additional Context

Reuse LockFile mutation logic from run_remove (lock_cmd.rs) to avoid duplicating JSON schema rules.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions