Skip to content

Preserve history with logical model and agent deletion#770

Merged
1 commit merged into
dataelement:mainfrom
Y1fe1Zh0u:fix/model-agent-logical-deletion
Jul 23, 2026
Merged

Preserve history with logical model and agent deletion#770
1 commit merged into
dataelement:mainfrom
Y1fe1Zh0u:fix/model-agent-logical-deletion

Conversation

@Y1fe1Zh0u

Copy link
Copy Markdown
Collaborator

Summary

  • replace physical Agent and model deletion with deleted_at logical deletion
  • exclude deleted entities from active APIs, permissions, runtime entry points, schedulers, selectors, and background jobs
  • preserve Chat, Run, Task, Audit, Participant, history, and workspace data after deletion
  • cancel unfinished Agent runs, release workspace edit locks, and remove runtime containers on a best-effort basis
  • add centralized active-model resolution with primary, fallback, and tenant-default candidates
  • simplify model deletion in the frontend and expose deleted Group participants as historical records
  • add an Alembic migration for nullable deletion timestamps and active-row partial indexes

Why

Physical deletion currently conflicts with existing foreign-key references and relies on destructive cleanup across historical data. Logical deletion makes an Agent or model unavailable everywhere it can be actively used while retaining the records needed to preserve history and auditability.

User and developer impact

  • deleted Agents and models disappear from active selection and execution paths
  • historical Group messages and participant references remain readable
  • Agent workspace files remain in their original location
  • deleting an in-use model no longer clears historical configuration references; runtime resolution falls back to another active model
  • existing foreign keys are intentionally unchanged in this iteration

Validation

  • backend full test suite: 1997 passed
  • focused logical-deletion backend suite: 23 passed
  • frontend tests: 63 passed
  • frontend production build: passed
  • Alembic heads: add_agent_model_deleted_at (head)
  • staged diff check: passed

Migration note

Apply the new Alembic revision before deploying the application code. The migration adds nullable deleted_at columns and partial indexes; it does not remove or rewrite existing foreign keys.

Deleting an Agent or model now marks it deleted and removes it from active product and runtime paths while preserving chats, runs, tasks, audits, participants, and workspace files. Agent deletion also cancels unfinished runs, releases edit locks, and removes runtime containers on a best-effort basis; model resolution falls back to an active candidate.

Constraint: Existing foreign keys remain unchanged in this iteration
Rejected: Manual cleanup and hard deletion | destroys historical data and fails against existing references
Confidence: high
Scope-risk: broad
Directive: New active Agent and model query paths must exclude deleted_at rows
Tested: Backend full suite (1997 passed); focused backend suite (23 passed); frontend tests (63 passed); frontend production build; Alembic heads; staged diff check
Not-tested: Applying the migration against a production database
Y1fe1Zh0u added a commit that referenced this pull request Jul 22, 2026
The integration branch needs this pull request alongside the other v1.11.2 candidates without changing the original PR state.

Constraint: Preserve the source PR commit and merge in numeric order.
Confidence: high
Scope-risk: moderate
Related: #770
Tested: Git merge completed without unresolved conflicts
Not-tested: Combined backend and frontend suites pending

# Conflicts:
#	backend/app/services/group_chat_service.py
#	backend/app/services/llm/caller.py
@Y1fe1Zh0u Y1fe1Zh0u closed this pull request by merging all changes into dataelement:main in 40c1f6b Jul 23, 2026
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