Skip to content

Fix Destroy→Restore: KB name, duplicate agents, webloc, My Lists#6

Closed
agropper wants to merge 4 commits intoagropper:mainfrom
HIEofOne:claude/identity-cleanup
Closed

Fix Destroy→Restore: KB name, duplicate agents, webloc, My Lists#6
agropper wants to merge 4 commits intoagropper:mainfrom
HIEofOne:claude/identity-cleanup

Conversation

@agropper
Copy link
Copy Markdown
Owner

@agropper agropper commented Apr 3, 2026

Summary

  • KB name mismatch (NO_KB_FILES): /api/account/recreate now generates and stores kbName in the new user doc so RestoreWizard and update-knowledge-base use the same timestamped KB folder path
  • Orphaned agents: Destroy now scans for ALL agents matching {userId}-agent-* pattern, not just the stored assignedAgentId
  • Duplicate agent on restore: Suppress ChatInterface's agent-setup-status polling during restore to prevent racing with RestoreWizard's sync-agent call
  • Missing webloc after restore: Write personalized maia-for-{name}-as-{userId}.webloc and save local state snapshot on restore completion
  • My Lists reload loop: Clear stale autoProcessInitialFile and wizardMyListsAuto sessionStorage flags at restore start
  • Debug logging: Comprehensive logging for destroy verification, file registration, and KB indexing
  • Documentation: Added Documentation/Wizards.md describing the provisioning/destroy/restore architecture and known fragility points

Test plan

  • Create new user, complete wizard, verify KB indexes successfully
  • Destroy account → verify DO dashboard shows no agents/KBs for that user
  • Click GET STARTED on destroyed user card → verify restore creates exactly one agent
  • Verify KB indexes successfully after restore (no NO_KB_FILES error)
  • Verify personalized .webloc file appears in local folder after restore
  • Verify My Lists tab does not reload repeatedly after restore

🤖 Generated with Claude Code

agropper and others added 4 commits April 1, 2026 11:59
…h, FAQ accordion

- /api/local/delete: relax UUID-only regex to accept any valid userId format
- Restore flow: validate folder identity matches userId before restoring
- Folder picker: reject folders already assigned to a different known user
- Wizard: switch tabs in-place instead of close/reopen MyStuffDialog (fixes flash)
- FAQ dialog: render as expandable accordion instead of flat markdown

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- generate-patient-summary: retry once after recreating stale API key
- files/lists/current-medications: same 401 retry pattern
- extractMarkdownCategories: same 401 retry pattern
- Matches existing retry logic in chat.js

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ists loop

Root cause of NO_KB_FILES: RestoreWizard uploaded files to {userId}-kb/ (simple
fallback) but update-knowledge-base generated a new timestamped name and looked
for files under {userId}-kb-{timestamp}/. Fix: /api/account/recreate now
generates and stores kbName so both paths use the same name.

Other fixes:
- Destroy now scans for and deletes ALL agents matching {userId}-agent-* pattern,
  not just the stored assignedAgentId (prevents orphaned agents in DO)
- Suppress ChatInterface agent-setup-status polling during restore to prevent
  racing with RestoreWizard's sync-agent call (duplicate agent creation)
- Write personalized webloc and save local state snapshot after restore
- Clear stale sessionStorage wizard flags on restore to prevent My Lists reload
- Add comprehensive debug logging to destroy, restore, file registration, and
  KB indexing flows
- Add post-destroy verification (CouchDB, agent, KB, Spaces)
- Add POST /api/user-status endpoint for RestoreWizard completion
- Add Documentation/Wizards.md describing provisioning architecture and fragility

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…& coordinator

1. Idempotent KB name: getKBNameFromUserDoc() returns null instead of
   generating a new name. ensureKBNameOnUserDoc() is the only generator.
   kbName is set at user doc creation time in both /api/temporary/start
   and /api/account/recreate. Null guards added to unguarded callers.

2. Agent creation mutex: per-user lock prevents concurrent agent creation
   from ChatInterface polling and RestoreWizard both calling ensureUserAgent().

3. RestoreWizard waits for agent deployment: polls /api/agent-setup-status
   every 5s (up to 40 attempts) before proceeding to metadata restore.

4. Single provisioning coordinator: POST /api/restore batches metadata saves
   (medications, summary, chats, instructions) into one server-side call,
   replacing 4 separate client-side fetch calls.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@agropper agropper closed this Apr 5, 2026
@agropper agropper deleted the claude/identity-cleanup branch April 5, 2026 00:30
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.

1 participant