plandex-ai/plandex · error
error loading context: %v
Error message
error loading context: %v
What it means
This error wraps a failure from LoadContexts() while ApplyPlan loads newly-added plan files as file-type contexts on the plan's branch. ApplyPlan launches a goroutine that batches every path in pendingNewFilesSet into a LoadContextRequest; if LoadContexts returns an error (file missing on disk, invalid body, storage/DB failure), it is wrapped with "error loading context: %v" and sent over errCh, which ApplyPlan then surfaces wrapped again as "error applying plan". The plan apply is aborted, so no PlanApply record is stored.
Source
Thrown at app/server/db/result_helpers.go:657
})
}
if len(loadReq) > 0 {
res, _, err := LoadContexts(
ctx,
LoadContextsParams{
OrgId: orgId,
UserId: userId,
Plan: plan,
BranchName: branchName,
Req: &loadReq,
SkipConflictInvalidation: true, // no need to invalidate conflicts when applying plan--and fixes race condition since invalidation check loads description
AutoLoaded: true,
},
)
if err != nil {
errCh <- fmt.Errorf("error loading context: %v", err)
return
}
loadContextRes = res
}
errCh <- nil
}()
}
if len(pendingUpdatedFilesSet) > 0 {
go func() {
defer func() {
if r := recover(); r != nil {
log.Printf("panic in ApplyPlan: %v\n%s", r, debug.Stack())
errCh <- fmt.Errorf("panic in ApplyPlan: %v\n%s", r, debug.Stack())
runtime.Goexit() // don't allow outer function to continue and double-send to channel
}View on GitHub (pinned to e2d772072e)
Solutions
- Inspect the wrapped inner error in the message to identify the LoadContexts failure (missing file, bad body, storage error) and fix that root cause.
- Verify each file path in the plan's pendingNewFiles exists on disk and has a non-empty Body in CurrentPlanFiles.Files before calling ApplyPlan.
- Check permissions on the context/results storage directories and available disk space.
- Ensure no concurrent ApplyPlan or branch switch is running against the same plan; serialize applies per plan.
- Re-generate or re-fetch the plan state so file bodies are complete, then retry the apply.
Example fix
// before: applying a plan whose new-file bodies were lost
applyRes, err := db.ApplyPlan(ctx, params) // -> error loading context: open /path: no such file
// after: pre-validate new file bodies before applying
for path := range planState.CurrentPlanFiles.Files {
if planState.CurrentPlanFiles.Files[path] == "" {
return fmt.Errorf("plan file %s has empty body; re-generate plan before applying", path)
}
}
applyRes, err := db.ApplyPlan(ctx, params) Defensive patterns
Strategy: validation
Validate before calling
for path := range planState.CurrentPlanFiles.Files {
if planState.CurrentPlanFiles.Files[path] == "" {
return fmt.Errorf("plan file %s has empty body", path)
}
if _, err := os.Stat(path); err != nil {
return fmt.Errorf("plan file %s missing on disk: %w", path, err)
}
} Try / catch
res, err := db.ApplyPlan(ctx, params)
if err != nil {
var loadErr *fmt.WrapError
if strings.Contains(err.Error(), "error loading context:") {
// refresh plan state / re-load contexts and retry once
}
return err
} Prevention
- Validate all new-file bodies exist and are non-empty in plan state before ApplyPlan.
- Confirm workspace files referenced by the plan still exist at their paths.
- Check storage directory permissions and free disk space before large applies.
- Serialize ApplyPlan calls per plan to avoid concurrent state races.
When it happens
Trigger: Calling ApplyPlan with a plan state whose CurrentPlanFiles.Files contains paths in pendingNewFilesSet whose Body is missing/invalid, whose FilePath does not exist on disk, or when the underlying context store (DB/file storage) fails during LoadContexts; also triggered when loadContextRes assignment path errors before errCh <- nil, leaving numRoutines waiting on errCh satisfied only by this error.
Common situations: Plan applied after the workspace files were deleted or renamed outside the tool; partial plan state where file bodies were never persisted; storage directory permissions changed or disk full; concurrent apply of the same plan racing on the same context files; org/plan/branch identifiers stale after a branch switch or plan deletion.
Related errors
- error updating context: %v
- error applying plan: %v
- error marshalling plan apply: %v
- connection to plan stream timed out due to missing heartbeat
- error loading accounts: %v
AI-assisted analysis of plandex-ai/plandex@e2d772072e (2026-09-05).
Data as JSON: /api/errors/01cc0aabf59bd326.
Report an issue: GitHub.