plandex-ai/plandex · error

error updating context: %v

Error message

error updating context: %v

What it means

This error wraps a failure from UpdateContexts() while ApplyPlan applies new bodies to modified files on the plan's branch. The goroutine builds an UpdateContextRequest keyed by existing context IDs from contextsByPath, calls UpdateContexts with SkipConflictInvalidation=true, and on error sends "error updating context: %v" on errCh. ApplyPlan aborts before writing the PlanApply record, so partial updates may already be persisted but the apply is not recorded.

Source

Thrown at app/server/db/result_helpers.go:697

				context := contextsByPath[path]
				updateReq[context.Id] = &shared.UpdateContextParams{
					Body: currentPlanState.CurrentPlanFiles.Files[path],
				}
			}

			if len(updateReq) > 0 {
				res, err := UpdateContexts(
					UpdateContextsParams{
						OrgId:                    orgId,
						Plan:                     plan,
						BranchName:               branchName,
						Req:                      &updateReq,
						SkipConflictInvalidation: true, // no need to invalidate conflicts when applying plan--and fixes race condition since invalidation check loads description
					},
				)

				if err != nil {
					errCh <- fmt.Errorf("error updating context: %v", err)
					return
				}

				updateContextRes = res
			}
			errCh <- nil

		}()

	}

	for i := 0; i < numRoutines; i++ {
		err := <-errCh
		if err != nil {
			return fmt.Errorf("error applying plan: %v", err)
		}
	}

View on GitHub (pinned to e2d772072e)

Solutions

  1. Read the wrapped inner error to find the specific UpdateContexts failure (stale ID, storage error, conflict).
  2. Re-load the plan's contexts (LoadContexts) to get fresh context IDs and re-run ApplyPlan with current state.
  3. Verify the target context still exists for every path in pendingUpdatedFilesSet; re-add missing ones as new files instead of updates.
  4. Check storage directory permissions/disk space for the org/plan data directories.
  5. Avoid running branch switches or plan deletions concurrently with ApplyPlan.

Example fix

// before: stale context IDs cause UpdateContexts to fail
updateReq[context.Id] = &shared.UpdateContextParams{Body: body}
res, err := UpdateContexts(params) // error updating context: context not found

// after: refresh contexts and fall back to load when the ID is gone
context, ok := contextsByPath[path]
if !ok || context.Id == "" {
    return fmt.Errorf("context for %s missing; re-load contexts and retry apply", path)
}
res, err := UpdateContexts(params)
Defensive patterns

Strategy: retry

Validate before calling

for path := range planState.CurrentPlanFiles.Files {
    ctxRec, ok := contextsByPath[path]
    if !ok || ctxRec.Id == "" {
        return fmt.Errorf("context for %s missing/stale; re-load before applying", path)
    }
}

Try / catch

err := db.ApplyPlan(ctx, params)
if err != nil && strings.Contains(err.Error(), "error updating context:") {
    // re-load contexts to refresh IDs, then retry once
    fresh, _, lerr := db.LoadContexts(ctx, loadParams)
    if lerr == nil {
        err = db.ApplyPlan(ctx, refreshedParams)
    }
}

Prevention

When it happens

Trigger: Calling ApplyPlan with pendingUpdatedFilesSet non-empty and UpdateContexts failing: context ID no longer exists (deleted/renamed), DB/storage write error, conflict check inside UpdateContexts fails, or the supplied Body is invalid for the context type.

Common situations: File contexts deleted or re-created between loading and applying, so stored context IDs are stale; storage backend unavailable (disk full, permissions); concurrent branch operations invalidating contexts; plan state regenerated between load and apply producing mismatched context IDs.

Related errors


AI-assisted analysis of plandex-ai/plandex@e2d772072e (2026-09-05). Data as JSON: /api/errors/e86ed09f615cfd74. Report an issue: GitHub.