plandex-ai/plandex · error

failed to store plan subtasks: %v

Error message

failed to store plan subtasks: %v

What it means

Thrown in storeOnFinished (tell_stream_store.go:190) when db.StorePlanSubtasks fails to persist the plan's subtask list to the database after an assistant streaming reply has already been stored and a description written. The library wraps the underlying db error so the caller knows persistence of subtasks (the plan/task breakdown) failed at the end of a streaming tell operation. The onError handler fires with the wrapped error and the store loop returns the error, surfacing a 500 'Error storing on finished' to the client.

Source

Thrown at app/server/model/plan/tell_stream_store.go:190

		err = db.StoreDescription(description)

		if err != nil {
			state.onError(onErrorParams{
				streamErr:      fmt.Errorf("failed to store description: %v", err),
				storeDesc:      false,
				convoMessageId: assistantMsg.Id,
				commitMsg:      convoCommitMsg,
			})
			return err
		}
		log.Println("[storeOnFinished] Description stored")

		// store subtasks
		err = db.StorePlanSubtasks(currentOrgId, planId, state.subtasks)
		if err != nil {
			log.Printf("Error storing plan subtasks: %v\n", err)
			state.onError(onErrorParams{
				streamErr:      fmt.Errorf("failed to store plan subtasks: %v", err),
				storeDesc:      false,
				convoMessageId: assistantMsg.Id,
				commitMsg:      convoCommitMsg,
			})
			return err
		}

		log.Println("Comitting after store on finished")

		err = repo.GitAddAndCommit(branch, convoCommitMsg)
		if err != nil {
			state.onError(onErrorParams{
				streamErr:      fmt.Errorf("failed to commit: %v", err),
				storeDesc:      false,
				convoMessageId: assistantMsg.Id,
				commitMsg:      convoCommitMsg,
			})
			return err

View on GitHub (pinned to e2d772072e)

Solutions

  1. Inspect the wrapped '%v' cause in server logs ('Error storing plan subtasks: ...') to identify the underlying db error (connection, lock, constraint).
  2. Verify database connectivity and run pending migrations; retry the tell operation once the DB is healthy.
  3. Check for concurrent writers on the same plan and reduce contention, or enable retry/backoff on StorePlanSubtasks.
  4. If a constraint is violated, validate state.subtasks before the call (non-nil ids, valid planId) and repair stale subtask data.

Example fix

// before
currentSubtasks := state.subtasks
err = db.StorePlanSubtasks(currentOrgId, planId, currentSubtasks)
// after
if err := retry(3, func() error {
    return db.StorePlanSubtasks(currentOrgId, planId, state.subtasks)
}); err != nil {
    return fmt.Errorf("failed to store plan subtasks: %w", err)
}
Defensive patterns

Strategy: retry

Validate before calling

if state.subtasks == nil || planId == "" || currentOrgId == "" {
    return fmt.Errorf("invalid subtask store inputs: planId=%q orgId=%q subtasks=%d", planId, currentOrgId, len(state.subtasks))
}
if err := db.Ping(); err != nil {
    return fmt.Errorf("database unavailable before storing subtasks: %w", err)
}

Try / catch

if err := db.StorePlanSubtasks(orgId, planId, subtasks); err != nil {
    var retryable bool = isTransientDbError(err) // e.g. net errors, lock timeouts
    if retryable {
        time.Sleep(backoff); return retryOnce()
    }
    return fmt.Errorf("failed to store plan subtasks: %w", err)
}

Prevention

When it happens

Trigger: db.StorePlanSubtasks(currentOrgId, planId, state.subtasks) returns a non-nil error — typically a database connection failure, lock timeout, constraint violation, or serialization failure while writing the subtasks rows for the current org/plan at the conclusion of a tell stream.

Common situations: Database restart or connection pool exhaustion mid-stream; concurrent writes to the same plan row from another session causing lock contention/serialization errors; schema mismatch after upgrading the server without running migrations; disk-full on the database host.

Related errors


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