plandex-ai/plandex · error

Error error updating contexts:

Error message

Error error updating contexts: 

What it means

The repo operation wrapped in db.ExecRepoOperation inside UpdateContextHandler failed: either db.UpdateContexts errored (DB/storage) or repo.GitAddAndCommit errored (git commit). Because ClearRepoOnErr is true, the repo is cleared/reset on failure. The handler responds with HTTP 500 including the wrapped error text.

Source

Thrown at app/server/handlers/plans_context.go:289

			return err
		}

		if updateRes.MaxTokensExceeded {
			return nil
		}

		err = repo.GitAddAndCommit(branchName, updateRes.Msg)

		if err != nil {
			return fmt.Errorf("error committing changes: %v", err)
		}

		return nil
	})

	if err != nil {
		log.Printf("Error error updating contexts: %v\n", err)
		http.Error(w, "Error error updating contexts: "+err.Error(), http.StatusInternalServerError)
		return
	}

	if updateRes.MaxTokensExceeded {
		log.Printf("The total number of tokens (%d) exceeds the maximum allowed (%d)", updateRes.TotalTokens, updateRes.MaxTokens)
		bytes, err := json.Marshal(updateRes)

		if err != nil {
			log.Printf("Error marshalling response: %v\n", err)
			http.Error(w, "Error marshalling response: "+err.Error(), http.StatusInternalServerError)
			return
		}

		w.Write(bytes)
		return
	}

	bytes, err := json.Marshal(updateRes)

View on GitHub (pinned to e2d772072e)

Solutions

  1. Read the appended error text in the 500/log ('error committing changes: ...' vs UpdateContexts error) to locate the failing step
  2. Remove a stale .git/index.lock in the plan repo if a crashed writer left one
  3. Verify the context IDs in the request still exist on the target branch (refresh plan/branch state first)
  4. Retry the update after resolving concurrent-writer conflicts; the repo was already cleared on error
  5. Check disk space and DB connectivity for the plan storage backend

Example fix

// before
err = repo.GitAddAndCommit(branchName, updateRes.Msg)
if err != nil {
    return fmt.Errorf("error committing changes: %v", err)
}
// after
err = repo.GitAddAndCommit(branchName, updateRes.Msg)
if err != nil {
    if strings.Contains(err.Error(), "index.lock") {
        os.Remove(filepath.Join(repo.Path(), ".git", "index.lock"))
    }
    return fmt.Errorf("error committing changes: %w", err)
}
Defensive patterns

Strategy: fallback

Validate before calling

// before updating, confirm the contexts still exist on the branch
branch, err := getBranch(planId, branchName)
if err != nil { return err }
for id := range req.Ids {
    if !branchHasContext(branch, id) {
        return fmt.Errorf("context %s no longer exists on %s", id, branchName)
    }
}

Try / catch

resp, err := sendUpdate(req)
if err != nil && resp != nil && resp.StatusCode == 500 {
    // repo was cleared on error; re-fetch state, then retry once
    if err := refreshPlanState(planId, branchName); err != nil {
        return err
    }
    return retryOnce(req)
}

Prevention

When it happens

Trigger: db.UpdateContexts returns an error (context row not found, DB failure) or repo.GitAddAndCommit fails (stale .git/index.lock, merge conflict, disk full) inside the write-locked ExecRepoOperation callback; the returned error propagates to the handler's err check at line 287.

Common situations: Updating a context id that no longer exists on the branch; concurrent writers contending on the repo lock; index.lock left by a crashed process; branch deleted by another user mid-request; storage backend outages.

Related errors


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