Skip to content

fix(cli): retain session data when removing profiles - #639

Open
christso wants to merge 2 commits into
mainfrom
fix/637-retain-profile-sessions
Open

christso wants to merge 2 commits into
mainfrom
fix/637-retain-profile-sessions

Conversation

@christso

@christso christso commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Closes #637

profile remove now uninstalls corroborated launchers, plugins, and configuration while retaining client runtime directories and profile OAuth state. --yes accepts the selected plan. --purge-session-data opts into recursive cleanup of eligible owned client roots and deletion of profile OAuth state.

The removal plan shows retained and purged roots in the terminal and JSON. It preserves unknown runtime files and empty directories by default. Explicit purge continues to protect pre-existing client roots and roots with referenced or modified resources. OpenCode keeps its configuration root while removing the exact runtime-generated .gitignore and other verified resources. The command leaves the workspace declaration intact.

Built CLI evidence

Built with bun run build. Each run used a fresh mktemp -d with separate HOME and project directories under /tmp, and XDG directories inside the fixture home. The user workspace declared a Pi profile named work, launcher pi-work, and a local file-mode plugin with skills/demo/SKILL.md. The built CLI installed the profile before the session fixture was created.

"$cli" --json profile install work --yes --offline
client="$HOME/.allagents/profiles/work/clients/pi/agent"
oauth="$HOME/.allagents/profiles/work/oauth-proxy"
mkdir -p "$client/sessions/empty" "$oauth/server"
printf '{"type":"session","id":"fixture"}\n' > "$client/sessions/example.jsonl"
printf '{}\n' > "$oauth/server/tokens.json"
Build and command Observed plan and result
Base 05e349c with "$cli" --json profile remove work --dry-run, then "$cli" --json profile remove work --yes The root was reported as removed. The filesystem check failed with FAIL: session history deleted.
Branch with "$cli" profile remove work, then Left and Enter at the confirmation prompt using agent-tui The plan and result showed retained pi root and retained profile root. The session bytes, empty directory, and OAuth file survived.
Branch with "$cli" --json profile remove work --dry-run, then "$cli" --json profile remove work --yes Plan and result both reported the Pi and OAuth roots as retained. The session bytes, empty directory, and OAuth file survived.
Branch with "$cli" --json profile remove work --dry-run --purge-session-data, then "$cli" --json profile remove work --yes --purge-session-data The dry run left the history in place. Plan and result both reported the Pi and OAuth roots as removed. Both runtime roots were absent after apply.

In every apply case, the launcher and installed skill were absent and cmp confirmed byte-for-byte identical workspace.yaml contents.

A second isolated fixture installed an OpenCode review profile with launcher opencode-review and setting model: demo/model. It contained the generated .gitignore, an empty runtime directory, and a symlink from oauth-proxy to an external fixture directory. "$cli" --json profile remove review --purge-session-data required confirmation and preserved the launcher and configuration. Adding --yes removed the launcher, opencode.json, and exact .gitignore, retained the runtime directory, and returned partial with a failed OAuth root. The external token file and retry state survived. After replacing the symlink with an owned directory and dummy token file, rerunning the same explicit purge removed the OAuth root and state. The external token file and OpenCode runtime directory remained. Temporary fixture homes were removed.

Verification

  • Focused Bun profile command, manager, and OpenCode adapter suites passed with 63 tests and one Windows-only skip. Lifecycle regression coverage, OpenCode regression coverage.
  • bun run typecheck, bun run lint, bun run build, bun run schema:check, and bun run package:smoke passed. The changed TypeScript lines matched Biome formatting, and git diff --check passed. Repository lint reported five existing warnings. Full-file Biome formatting still reports pre-existing formatting differences.
  • bun run docs:build passed under Node 24.22.3.
  • bun test --timeout 30000 tests/unit passed with 2,307 tests and four Windows-only skips. The first local bun test run started before the review edits and overlapped builds. It finished with 2,767 passed, eight skipped, and 18 failures. The 15 E2E failures passed on isolated reruns across legacy-vscode-cli, workspace-update-scope, plugin-git-remotes credential rejection, and the project-scope plugin-update case. The three OpenCode cases passed in the focused and complete unit runs on the final sources. GitHub's full Test job passed on the final head.

Independent review

Codex Engineer (codex-engineer) used Compound Engineering's ce-code-review skill to review e601f0a46b93cf72db4e21ec3b7bc79b72c929af against 05e349cf25316389fd698521291c85919a72e8bf. The read-only solo review omitted the skill's external peer and nested reviewer or validation stages. Both P2 findings were addressed in 226e926. OpenCode's fingerprint-checked cleanup is visible and executable in both removal modes, and client docs now describe default retention and explicit purge. The focused tests and built CLI fixtures above were rerun after those changes.

@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • New Features
    • Profile removal now retains client runtime data and OAuth credentials by default, including when using --yes.
    • Added --purge-session-data to remove eligible profile-owned runtime data and OAuth state. Dry-run previews show planned cleanup; data with modified or referenced resources is retained.
    • OpenCode cleanup removes its unchanged generated .gitignore while retaining modified files and other runtime data.
  • Documentation
    • Updated profile, client, and configuration guides with removal and cleanup behavior.

Profile removal now retains client runtime data and profile OAuth state by default. The --purge-session-data option requests cleanup of eligible owned roots. Planning and execution report retained or removed resources, and cleanup checks preserve modified, referenced, or unowned data.

Changes: Profile Removal

Layer / File(s) Summary
Purge option and removal planning
src/cli/commands/profile.ts, src/cli/metadata/profile.ts, src/core/profile/index.ts, src/core/profile/plan.ts, docs/src/content/docs/docs/reference/cli.mdx, tests/unit/cli/profile-command.test.ts
profile remove accepts --purge-session-data. Runtime options default to retaining session data. The CLI reference describes the option, default retention, and removal planning behavior.
Owned client-root cleanup
src/core/profile/plan.ts, src/core/profile/types.ts, src/core/profile/adapters/opencode.ts, src/core/profile/manager.ts, tests/unit/core/profile/manager.test.ts, tests/unit/core/profile/opencode.test.ts, docs/src/content/docs/docs/reference/clients.mdx
Recursive cleanup requires purge selection, an owned root, adapter support, and no retained resources. OpenCode cleanup returns the generated .gitignore path and fingerprint for verification. Tests cover retained and purged roots, unowned roots, and modified generated files.
OAuth state and removal results
src/core/profile/index.ts, src/core/profile/plan.ts, src/core/profile/manager.ts, tests/unit/core/profile/manager.test.ts, docs/src/content/docs/docs/guides/mcp-proxy.mdx, docs/src/content/docs/docs/reference/configuration.mdx
Planning adds a profile-level OAuth cleanup step. Removal retains OAuth state unless purge is enabled, then reports cleanup results. Profile-root pruning removes only the root directory. Tests cover default retention, explicit purge, and symlink failure and retry behavior.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: Minimal · up to 226e9

Profile removal now keeps client runtime data and OAuth state unless --purge-session-data is passed, and the docs describe this. The reviewed code and tests show purge is opt-in and limited to eligible owned roots. No merge-blocking issues were found. Check the remaining E2E reruns before merging.

Security architecture risk: Low · up to 226e9

Keeping sessions by default reduces accidental data loss. The tradeoff is that existing uninstall scripts no longer clear local OAuth credentials, and a later purge can be unavailable once both the profile declaration and installation record are gone. The impact is limited to the selected local profile.

Retained concerns

  • Low · security · observed: Default removal can leave OAuth credentials behind while deleting the last installation record. If the declaration is already absent or later removed, a follow-up purge is rejected before it checks the cache. The base removed the cache on the corresponding successful uninstall path. A still-declared profile remains eligible for follow-up OAuth purge.
  • Low · security · inferred: If the OAuth cache is absent at preview but created before cleanup, explicit purge can return success without clearing or reporting it. The base checked for the cache during apply. Avoiding deletion of an unpreviewed root is reasonable; silently completing the purge leaves its credential-cleanup outcome ambiguous.
Security review details

Security Blast Radius

  • observed — The deletion scope is local: the selected profile's OAuth subtree and eligible managed client roots. Recursive purge can delete untracked data inside eligible roots, but pre-existing roots without managed ownership records are treated as referenced.

Trust Boundaries and Controls

  • observed — The planner validates the profile name before deriving its storage path. Recursive deletion requires the expected root path and refuses symlinks and non-directories; managed-file deletion checks containment and the expected SHA-256 before unlinking.

Resilience and Maintainability Implications

  • observed — Client cleanup checkpoints mutations. A failed OAuth deletion returns partial before removing the installation record, preserving the state needed to retry the failed purge.

Hardening Proposals

  • proposed — Preserve a narrowly scoped cleanup record for retained OAuth state, and report a newly appeared cache as requiring a fresh purge plan rather than deleting it without preview or silently reporting success.
Pre-merge checks: Passed 3 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Linked Issues check Inconclusive Issue #637 (direct, open) has coding requirements, all mapped to the current PR:

1. Default removal uninstalls owned launchers, plugins, and generated configuration, and retains session data and cont…
Add an automated built-CLI test, or confirm that the manual runs satisfy the issue's verification requirement. Such a test should cover default profile remove, profile remove --yes alone, and profile remove --yes --purge-session-data …
Passed Passed checks: 3 passed

Check name Status Explanation
Title check Passed The title "fix(cli): retain session data when removing profiles" matches the main change: profile removal now retains client runtime directories and OAuth state by default, with an opt-in --purge-sess…
Out of Scope Changes check Passed All changed areas connect to #637 objectives:
- CLI flag and metadata (src/cli/commands/profile.ts, src/cli/metadata/profile.ts) implement --purge-session-data. The CLI help test in tests/unit/cli/p…
Description check Passed The description is specific to the changeset. It explains that profile remove now uninstalls verified launchers, plugins, and configuration while retaining client runtime directories and OAuth state b…
Full details: Title check

Explanation

The title "fix(cli): retain session data when removing profiles" matches the main change: profile removal now retains client runtime directories and OAuth state by default, with an opt-in --purge-session-data flag. It is concise, specific, and conventional.

Full details: Out of Scope Changes check

Explanation

All changed areas connect to #637 objectives:

  • CLI flag and metadata (src/cli/commands/profile.ts, src/cli/metadata/profile.ts) implement --purge-session-data. The CLI help test in tests/unit/cli/profile-command.test.ts covers it.
  • Core option and plan types (src/core/profile/index.ts, plan.ts, types.ts) carry purgeSessionData and the OAuth cleanup step. These support the purge and retention semantics.
  • Replacement of prepareRootCleanup with rootCleanupFile (opencode.ts, types.ts, manager.ts) supports fingerprint-checked OpenCode cleanup in both removal modes. This matches the issue's safeguard requirement.
  • Documentation updates (cli.mdx, clients.mdx, configuration.mdx, mcp-proxy.mdx) describe the new default retention and purge behavior. The issue does not require docs, but they describe the changed behavior and are not unrelated.
  • Test updates in manager.test.ts and opencode.test.ts exercise the new behavior.

No change was found that is unrelated to profile removal.

Full details: Description check

Explanation

The description is specific to the changeset. It explains that profile remove now uninstalls verified launchers, plugins, and configuration while retaining client runtime directories and OAuth state by default, and that --purge-session-data opts into recursive cleanup. It also covers OpenCode's exact .gitignore handling, the built-CLI verification, and the test results, all of which match the summarized file changes (profile command, manager, plan, OpenCode adapter, and docs).

Full details: Linked Issues check

Explanation

Issue #637 (direct, open) has coding requirements, all mapped to the current PR:

  1. Default removal uninstalls owned launchers, plugins, and generated configuration, and retains session data and containing directories. Summary of src/core/profile/plan.ts and manager.ts supports this. Unit tests in tests/unit/core/profile/manager.test.ts (default removal) and opencode.test.ts (default removal) cover it. Author-reported built-CLI runs show retained Pi and OAuth roots, and launcher and skill removal. Addressed on the summary and test evidence. I did not read the planning or manager code directly.
  2. --purge-session-data opts into recursive cleanup of eligible owned roots and OAuth state. Added in src/cli/commands/profile.ts and metadata. Manager tests cover explicit purge. Addressed on summary evidence.
  3. --yes does not select purge. Built-CLI runs report --yes alone retains roots. Addressed on author-reported evidence.
  4. Dry-run and JSON preview of retained and purged roots. Author-reported runs show plan and result output. Addressed on author-reported evidence.
  5. Safeguards for modified and referenced resources. Covered by the purge-protection and OpenCode modified-.gitignore tests. Addressed on summary evidence.
  6. Declaration editing is separate from removal. Author reports workspace.yaml byte-identical after apply. Addressed on author-reported evidence.
  7. Verification through the built CLI against isolated fixtures. The built-CLI runs are manual shell and TUI sessions reported in the PR description. The repository has no automated built-CLI test for profile remove. tests/e2e contains no profile-remove suite. The unit-test files cover manager and adapter behavior, not the built binary.

Unresolved: the built-CLI requirement is evidenced only by author-reported manual runs. I did not inspect the planning and manager code directly. Coding behavior is consistent with the summaries and the tests, but this assessment does not confirm it from source.

Resolution

Add an automated built-CLI test, or confirm that the manual runs satisfy the issue's verification requirement. Such a test should cover default profile remove, profile remove --yes alone, and profile remove --yes --purge-session-data against an isolated fixture home. Optionally, confirm the removal logic in src/core/profile/plan.ts and src/core/profile/manager.ts against the cited test cases.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 05e349c and 226e926.

Files selected for processing: 14

  • docs/src/content/docs/docs/guides/mcp-proxy.mdx
  • docs/src/content/docs/docs/reference/cli.mdx
  • docs/src/content/docs/docs/reference/clients.mdx
  • docs/src/content/docs/docs/reference/configuration.mdx
  • src/cli/commands/profile.ts
  • src/cli/metadata/profile.ts
  • src/core/profile/adapters/opencode.ts
  • src/core/profile/index.ts
  • src/core/profile/manager.ts
  • src/core/profile/plan.ts
  • src/core/profile/types.ts
  • tests/unit/cli/profile-command.test.ts
  • tests/unit/core/profile/manager.test.ts
  • tests/unit/core/profile/opencode.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying allagents with  Cloudflare Pages  Cloudflare Pages

Latest commit: 226e926
Status: ✅  Deploy successful!
Preview URL: https://44e77ec9.allagents.pages.dev
Branch Preview URL: https://fix-637-retain-profile-sessi.allagents.pages.dev

View logs

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Preserve session data by default when removing a profile

1 participant