plandex-ai/plandex · error
error removing contexts: %v
Error message
error removing contexts: %v
What it means
Returned by DeleteContextHandler when db.ContextRemove(auth.OrgId, planId, toRemove) fails after contexts were fetched and filtered. The DB deletion of the selected context rows failed (toRemove may be empty if no requested IDs matched, which some storage layers reject); the wrapped error is surfaced as HTTP 500 'Error deleting contexts'.
Source
Thrown at app/server/handlers/plans_context.go:398
ClearRepoOnErr: true,
}, func(repo *db.GitRepo) error {
var err error
dbContexts, err = db.GetPlanContexts(auth.OrgId, planId, false, false)
if err != nil {
return fmt.Errorf("error getting contexts: %v", err)
}
for _, dbContext := range dbContexts {
if _, ok := requestBody.Ids[dbContext.Id]; ok {
toRemove = append(toRemove, dbContext)
}
}
err = db.ContextRemove(auth.OrgId, planId, toRemove)
if err != nil {
return fmt.Errorf("error removing contexts: %v", err)
}
for _, dbContext := range toRemove {
toRemoveApiContexts = append(toRemoveApiContexts, dbContext.ToApi())
removeTokens += dbContext.NumTokens
}
commitMsg = shared.SummaryForRemoveContext(toRemoveApiContexts, branch.ContextTokens) + "\n\n" + shared.TableForRemoveContext(toRemoveApiContexts)
err = repo.GitAddAndCommit(branchName, commitMsg)
if err != nil {
return fmt.Errorf("error committing changes: %v", err)
}
return nil
})
View on GitHub (pinned to e2d772072e)
Solutions
- Log/inspect the wrapped DB error from ContextRemove
- Validate requestBody.Ids against existing contexts and return early when toRemove is empty
- Check for concurrent deletes and unique/foreign-key constraint violations
- Retry transient DB failures
Example fix
// before
err = db.ContextRemove(auth.OrgId, planId, toRemove)
if err != nil {
return fmt.Errorf("error removing contexts: %v", err)
}
// after
if len(toRemove) == 0 {
return nil // nothing matched requestBody.Ids; skip remove + commit
}
if err := db.ContextRemove(auth.OrgId, planId, toRemove); err != nil {
return fmt.Errorf("error removing contexts: %w", err)
} Defensive patterns
Strategy: validation
Validate before calling
toRemove := make([]*db.Context, 0)
for _, dbContext := range dbContexts {
if _, ok := requestBody.Ids[dbContext.Id]; ok {
toRemove = append(toRemove, dbContext)
}
}
if len(toRemove) == 0 {
return errors.New("no matching contexts found for requested ids")
} Try / catch
if err := db.ContextRemove(auth.OrgId, planId, toRemove); err != nil {
return fmt.Errorf("error removing contexts: %w", err)
}
// caller: inspect wrapped cause; on constraint errors refresh context list and retry once Prevention
- Validate requested IDs against existing contexts and no-op on empty match
- Handle concurrent deletions by refreshing the context list
- Check DB constraint errors explicitly for clearer client messages
When it happens
Trigger: Deleting contexts whose IDs were found via GetPlanContexts but whose DB removal then fails — storage-layer delete error, transaction failure, or calling ContextRemove with an empty toRemove slice because none of requestBody.Ids matched existing contexts.
Common situations: Client sending stale/unknown context IDs so toRemove is empty; concurrent deletion by another session; DB constraint or connection errors.
Related errors
- Error getting pending builds by path: %v
- error invalidating conflicted results: %v
- error adding plan context tokens: %v
- error adding org member: %v
- error listing org roles: %v
AI-assisted analysis of plandex-ai/plandex@e2d772072e (2026-09-05).
Data as JSON: /api/errors/429efa72b610a50c.
Report an issue: GitHub.