plandex-ai/plandex · critical

error storing model stream: %v

Error message

error storing model stream: %v

What it means

During activation, after creating the ActivePlan, the code stores the model stream via the db layer. If storage fails, it sends an ApiError on active.StreamDoneCh (to abort the just-created active plan) and returns "error storing model stream: %v". Activation cannot proceed without a persisted stream record.

Source

Thrown at app/server/model/plan/activate.go:74

		autoContext,
		sessionId,
	)

	modelStream = &db.ModelStream{
		OrgId:      auth.OrgId,
		PlanId:     plan.Id,
		InternalIp: host.Ip,
		Branch:     branch,
	}
	err = db.StoreModelStream(modelStream, active.Ctx, active.CancelFn)
	if err != nil {
		log.Printf("Tell: Error storing model stream for plan ID %s on branch %s: %v\n", plan.Id, branch, err) // Log error storing model stream
		log.Printf("Error storing model stream: %v\n", err)
		log.Printf("Tell: Error storing model stream: %v\n", err) // Log error storing model stream

		active.StreamDoneCh <- &shared.ApiError{Msg: fmt.Sprintf("Error storing model stream: %v", err)}

		return nil, fmt.Errorf("error storing model stream: %v", err)
	}

	active.ModelStreamId = modelStream.Id

	log.Printf("Tell: Model stream stored with ID %s for plan ID %s on branch %s\n", modelStream.Id, plan.Id, branch) // Log successful storage of model stream
	log.Println("Model stream id:", modelStream.Id)

	return active, nil
}

View on GitHub (pinned to e2d772072e)

Solutions

  1. Inspect the wrapped cause and restore DB connectivity/credentials.
  2. Clean up any partially created active-plan/stream rows from the failed attempt, then retry.
  3. Make activation idempotent: upsert the stream instead of blind insert to tolerate retries.
  4. Ensure the StreamDoneCh abort path also releases the ActivePlan so retries are not blocked by error 645.

Example fix

// before: insert fails on leftover row
err := db.CreateModelStream(modelStream)
// after: idempotent upsert
err := db.UpsertModelStream(modelStream)
Defensive patterns

Strategy: retry

Validate before calling

if err := db.Ping(); err != nil {
    return fmt.Errorf("skipping activation, database unavailable: %w", err)
}

Try / catch

_, err := Tell(ctx, req)
if err != nil && strings.Contains(err.Error(), "error storing model stream") {
    time.Sleep(2 * time.Second) // let ActivePlan abort propagate
    _, err = Tell(ctx, req)
}

Prevention

When it happens

Trigger: db stream-store call fails while activating: DB outage, connection loss between CreateActivePlan and the store call, unique-constraint violation on an existing stream id, or serialization error of the stream payload.

Common situations: Database restarts mid-deploy, disk-full on the DB host, credentials rotated between the two DB calls, or constraint conflicts from a half-cleaned previous activation.

Related errors


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