Delete replaced profile generations and retry failed deletes (CLS-1267) #318

Merged
stephen merged 8 commits from stephen/cls-1267-retired-generations into main 2026-11-12 00:06:09 +00:00
Owner

CLS-1267 item 2, the cleanup half (the lock and refresh fence are #316). Replacing a profile (PAT login, auth refresh --token, Fjord login) published a new generation under a new random key and never deleted the previous generation's secret. A later logout only knows the current generation, so the old PAT, bearer or refresh token stayed in storage with no way to find it again.

Schema (additive). HostProfiles gains retired: Vec<Profile> (#[serde(default, skip_serializing_if = "Vec::is_empty")]). Old hosts.toml files load unchanged and an empty list is never written; tests cover both.

Behaviour

  • The replaced descriptor moves to retired in the same publication as the new generation, so its identity is durable before any delete is attempted.
  • Right after publishing, still under the account lock, fj deletes the secrets of every retired generation on the host (PAT key, or Fjord bearer and refresh). Every secret of a generation is attempted even if one fails. A generation leaves the list only when all its deletes succeeded; otherwise the command fails with "N previous credential(s) could not be removed yet; running this command again retries", and the new profile is already active.
  • Retried by the next auth login, Fjord login, auth refresh (both kinds) and logout on that host. Logout drains before unpublishing, so a failure leaves the profile selectable and logging out again retries.
  • A generation staged but never published (write or read-back failed, publication refused) is deleted, and if that delete fails it is listed the same way.
  • The named Fjord login error mapping now lets this one outcome through instead of printing "sign-in failed" for a saved profile.
  • profile_session::logout shares the new secret_keys helper.

Known limits (self-review rounds, left as is)

  • delete_token cannot confirm deletion from a keychain that is unreachable on Linux (PlatformFailure warns and succeeds, as in #314) or disabled with FJ_NO_KEYCHAIN=1, so those are dropped from the list as deleted.
  • A first named login to a host with no profiles yet whose staged cleanup also fails cannot be listed (an account entry without a host breaks every later save, and one on a legacy-only host would make it look profiled); only hosts that already have profiles keep the identity.
  • Failure of the delete itself is injected at the drain_with seam and by an unreadable token store, not by a failing keychain; the refresh and Fjord-login call sites are covered by existing integration tests but not by a new failing-delete test.

Tests: old file round-trip, list round-trip, replacement deletes the old secret, failed delete stays listed and is retried, retry on the next store and on logout, abandoned PAT and Fjord generations kept when the store is unreadable then drained, one failed delete does not stop the generation's other secrets. Touches profiles.rs, fjord_profiles.rs, profile_session.rs (logout only), a new profile_retired.rs, profile_maintenance.rs and invocation_profiles.rs; fj-cl confirmed it is not editing these.

CI note: the first push failed clippy (an unused import and a fold) because this host's newer toolchain stops at an unrelated lint; fixed, and clippy is clean here with that lint allowed. A fourth self-review round (past the 3-round budget, needed for the CI fix) added only the hosts-with-profiles restriction above and repeated the keychain limits.

CLS-1267 item 2, the cleanup half (the lock and refresh fence are #316). Replacing a profile (PAT login, `auth refresh --token`, Fjord login) published a new generation under a new random key and never deleted the previous generation's secret. A later logout only knows the current generation, so the old PAT, bearer or refresh token stayed in storage with no way to find it again. **Schema (additive).** `HostProfiles` gains `retired: Vec<Profile>` (`#[serde(default, skip_serializing_if = "Vec::is_empty")]`). Old `hosts.toml` files load unchanged and an empty list is never written; tests cover both. **Behaviour** - The replaced descriptor moves to `retired` in the same publication as the new generation, so its identity is durable before any delete is attempted. - Right after publishing, still under the account lock, fj deletes the secrets of every retired generation on the host (PAT key, or Fjord bearer and refresh). Every secret of a generation is attempted even if one fails. A generation leaves the list only when all its deletes succeeded; otherwise the command fails with "N previous credential(s) could not be removed yet; running this command again retries", and the new profile is already active. - Retried by the next `auth login`, Fjord login, `auth refresh` (both kinds) and logout on that host. Logout drains before unpublishing, so a failure leaves the profile selectable and logging out again retries. - A generation staged but never published (write or read-back failed, publication refused) is deleted, and if that delete fails it is listed the same way. - The named Fjord login error mapping now lets this one outcome through instead of printing "sign-in failed" for a saved profile. - `profile_session::logout` shares the new `secret_keys` helper. **Known limits (self-review rounds, left as is)** - `delete_token` cannot confirm deletion from a keychain that is unreachable on Linux (PlatformFailure warns and succeeds, as in #314) or disabled with `FJ_NO_KEYCHAIN=1`, so those are dropped from the list as deleted. - A first named login to a host with no profiles yet whose staged cleanup also fails cannot be listed (an account entry without a host breaks every later save, and one on a legacy-only host would make it look profiled); only hosts that already have profiles keep the identity. - Failure of the delete itself is injected at the `drain_with` seam and by an unreadable token store, not by a failing keychain; the refresh and Fjord-login call sites are covered by existing integration tests but not by a new failing-delete test. Tests: old file round-trip, list round-trip, replacement deletes the old secret, failed delete stays listed and is retried, retry on the next store and on logout, abandoned PAT and Fjord generations kept when the store is unreadable then drained, one failed delete does not stop the generation's other secrets. Touches `profiles.rs`, `fjord_profiles.rs`, `profile_session.rs` (logout only), a new `profile_retired.rs`, `profile_maintenance.rs` and `invocation_profiles.rs`; fj-cl confirmed it is not editing these. CI note: the first push failed clippy (an unused import and a fold) because this host's newer toolchain stops at an unrelated lint; fixed, and clippy is clean here with that lint allowed. A fourth self-review round (past the 3-round budget, needed for the CI fix) added only the hosts-with-profiles restriction above and repeated the keychain limits.
Replacing a profile left the previous generation's secret in storage with no
way to find it again. The replaced descriptor now moves to an optional
per-account retired list in the same publication, its secrets are deleted under
the account lock, and a failed delete stays listed and is retried by the next
store, Fjord login or logout on the host. A staged generation whose cleanup
fails is listed too. Older hosts.toml files load unchanged.
Let a pending-cleanup outcome through the named Fjord login error (CLS-1267)
Some checks failed
ci / check (pull_request) Failing after 3m47s
ci / coverage (pull_request) Has been skipped
ci / live-e2e (pull_request) Has been skipped
510fdd76bb
gerri approved these changes 2026-11-11 17:40:09 +00:00
Dismissed
gerri left a comment

Automated Codex review (read-only) of head 510fdd76bb.

No new correctness or security findings. Required formatting checks passed; builds and tests were not run.

  • Low (edge case), src/config/profile_retired.rs:37,85: The confirmed-deletion and durable-retry invariants retain the accepted limitations documented under “Known limits” in the PR body, including unconfirmed keychain deletes, unrecorded cleanup on failed first login, and failure-test coverage gaps. No new evidence makes these blocking. Address them in follow-up work.

BLOCKING: 0

Reviewed head 510fdd76bb at 2026-11-11T17:40:07Z by codex exec (read-only sandbox).

Automated Codex review (read-only) of head 510fdd76bbe9d4431c98f7ffb964d3f79c783ddc. No new correctness or security findings. Required formatting checks passed; builds and tests were not run. - **Low** (edge case), `src/config/profile_retired.rs:37,85`: The confirmed-deletion and durable-retry invariants retain the accepted limitations documented under “Known limits” in the PR body, including unconfirmed keychain deletes, unrecorded cleanup on failed first login, and failure-test coverage gaps. No new evidence makes these blocking. Address them in follow-up work. BLOCKING: 0 --- Reviewed head 510fdd76bbe9d4431c98f7ffb964d3f79c783ddc at 2026-11-11T17:40:07Z by codex exec (read-only sandbox).
gerri approved these changes 2026-11-11 17:46:39 +00:00
Dismissed
gerri left a comment

Automated Codex review (read-only) of head 59e25105e7.

No new blocking correctness or security findings found.

  • Low (edge case), src/config/profile_retired.rs:88: The invariant is that unfinished credential deletion retains a durable identity. The PR body already defers unconfirmed keychain deletion and failed staged cleanup on a host without profiles. Those paths can leave secrets without a retry descriptor. No new evidence makes these blocking here. Follow-up: preserve cleanup identities independently of selectable profiles and retain entries when deletion cannot be confirmed.

BLOCKING: 0

Reviewed head 59e25105e7 at 2026-11-11T17:46:38Z by codex exec (read-only sandbox).

Automated Codex review (read-only) of head 59e25105e761bc8b946e40361a3c8e768639bab5. No new blocking correctness or security findings found. - **Low** (edge case), `src/config/profile_retired.rs:88`: The invariant is that unfinished credential deletion retains a durable identity. The PR body already defers unconfirmed keychain deletion and failed staged cleanup on a host without profiles. Those paths can leave secrets without a retry descriptor. No new evidence makes these blocking here. Follow-up: preserve cleanup identities independently of selectable profiles and retain entries when deletion cannot be confirmed. BLOCKING: 0 --- Reviewed head 59e25105e761bc8b946e40361a3c8e768639bab5 at 2026-11-11T17:46:38Z by codex exec (read-only sandbox).
Expect the replaced PAT generation to be deleted in the profile test (CLS-1267)
All checks were successful
ci / check (pull_request) Successful in 12m52s
ci / live-e2e (pull_request) Successful in 2m57s
ci / coverage (pull_request) Successful in 2m57s
60b6771f52
gerri approved these changes 2026-11-12 00:04:38 +00:00
gerri left a comment

Automated Codex review (read-only) of head 60b6771f52.

No new correctness or security problems found in the changed paths.

  • Low (edge case), src/config/profile_retired.rs:85: Invariant: retain credential identities until deletion is confirmed. The PR body’s accepted “Known limits” remain: unavailable or disabled keychains can leave deletion unconfirmed, and failed staged cleanup during a first named login can leave an untracked secret. These are disclosed deferrals, with no new evidence here of normal-operation impact. Follow-up: preserve unresolved cleanup identities independently of active profiles and distinguish confirmed deletion from unavailable storage.

BLOCKING: 0

Reviewed head 60b6771f52 at 2026-11-12T00:04:38Z by codex exec (read-only sandbox).

Automated Codex review (read-only) of head 60b6771f52151be02a4939632149798268f391dc. No new correctness or security problems found in the changed paths. - **Low** (edge case), `src/config/profile_retired.rs:85`: Invariant: retain credential identities until deletion is confirmed. The PR body’s accepted “Known limits” remain: unavailable or disabled keychains can leave deletion unconfirmed, and failed staged cleanup during a first named login can leave an untracked secret. These are disclosed deferrals, with no new evidence here of normal-operation impact. Follow-up: preserve unresolved cleanup identities independently of active profiles and distinguish confirmed deletion from unavailable storage. BLOCKING: 0 --- Reviewed head 60b6771f52151be02a4939632149798268f391dc at 2026-11-12T00:04:38Z by codex exec (read-only sandbox).
Sign in to join this conversation.
No description provided.