plandex-ai/plandex · error

error updating plan tokens: %v

Error message

error updating plan tokens: %v

What it means

AddPlanContextTokens: the UPDATE branches SET context_tokens = ... query fails for the given plan/branch, so context token accounting cannot be recorded. DB error — connection, constraint, or the row is locked/unavailable.

Source

Thrown at app/server/db/plan_helpers.go:137

func GetPlanNamesById(planIds []string) (map[string]string, error) {
	var plans []*Plan
	err := Conn.Select(&plans, "SELECT id, name FROM plans WHERE id = ANY($1)", pq.Array(planIds))
	if err != nil {
		return nil, fmt.Errorf("error getting plan names: %v", err)
	}

	namesMap := make(map[string]string)
	for _, plan := range plans {
		namesMap[plan.Id] = plan.Name
	}

	return namesMap, nil
}

func AddPlanContextTokens(planId, branch string, addTokens int) error {
	_, err := Conn.Exec("UPDATE branches SET context_tokens = context_tokens + $1 WHERE plan_id = $2 AND name = $3", addTokens, planId, branch)
	if err != nil {
		return fmt.Errorf("error updating plan tokens: %v", err)
	}
	return nil
}

func AddPlanConvoMessage(msg *ConvoMessage, branch string) error {
	errCh := make(chan error, 2)

	go func() {
		defer func() {
			if r := recover(); r != nil {
				log.Printf("panic in AddPlanConvoMessage: %v\n%s", r, debug.Stack())
				errCh <- fmt.Errorf("panic in AddPlanConvoMessage: %v\n%s", r, debug.Stack())
				runtime.Goexit() // don't allow outer function to continue and double-send to channel
			}
		}()

		_, err := Conn.Exec("UPDATE branches SET convo_tokens = convo_tokens + $1 WHERE plan_id = $2 AND name = $3", msg.Tokens, msg.PlanId, branch)

View on GitHub (pinned to e2d772072e)

Solutions

  1. Inspect the wrapped DB error
  2. Verify the branch row exists for plan_id + branch name
  3. Retry; token accounting is idempotent-adjacent (increment) so a retry is safe after confirming state
Defensive patterns

Strategy: retry

When it happens

Trigger: Thrown at app/server/db/plan_helpers.go:137 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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