plandex-ai/plandex · error

error getting recent model streams: %v

Error message

error getting recent model streams: %v

What it means

In ListPlansRunningHandler, a goroutine fetches active or recent model streams for the requested plan IDs via db.GetActiveOrRecentModelStreams / db.GetActiveModelStreams. When the database query fails, the underlying error is wrapped with this message and sent to errCh; the handler collects it and returns HTTP 500.

Source

Thrown at app/server/handlers/plans_crud.go:460

	var branches []*db.Branch

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

		var err error
		if includeRecent {
			streams, err = db.GetActiveOrRecentModelStreams(planIds)
		} else {
			streams, err = db.GetActiveModelStreams(planIds)
		}
		if err != nil {
			errCh <- fmt.Errorf("error getting recent model streams: %v", err)
			return
		}
		errCh <- nil
	}()

	go func() {
		defer func() {
			if r := recover(); r != nil {
				log.Printf("panic in ListPlansRunningHandler: %v\n%s", r, debug.Stack())
				errCh <- fmt.Errorf("panic in ListPlansRunningHandler: %v\n%s", r, debug.Stack())
				runtime.Goexit() // don't allow outer function to continue and double-send to channel
			}
		}()
		var err error
		branches, err = db.ListBranchesForPlans(auth.OrgId, planIds)
		if err != nil {
			errCh <- fmt.Errorf("error getting branches: %v", err)
			return

View on GitHub (pinned to e2d772072e)

Solutions

  1. Check the wrapped %v cause and verify the database is reachable (connection string, network, pool limits).
  2. Run schema migrations and confirm the model streams tables exist.
  3. Verify planIds is populated and correctly formed before querying.
  4. Check Postgres logs at the time of failure for the exact SQL error.

Example fix

// before
streams, err = db.GetActiveOrRecentModelStreams(planIds)
// after
if len(planIds) == 0 { planIds = []string{""} }
streams, err = db.GetActiveOrRecentModelStreams(planIds)
if err != nil {
    log.Printf("stream query failed: %v", err)
}
Defensive patterns

Strategy: try-catch

Validate before calling

// Go
if len(planIds) == 0 {
    return nil // nothing to query; skip DB round-trip
}
if err := db.PingContext(ctx); err != nil {
    return fmt.Errorf("db unavailable: %w", err)
}

Type guard

func planIdsValid(ids []string) bool { return len(ids) > 0 }

Try / catch

streams, err := db.GetActiveOrRecentModelStreams(planIds)
if err != nil {
    log.Printf("model streams query failed: %v", err)
    http.Error(w, "failed to load model streams", http.StatusBadGateway)
    return
}

Prevention

When it happens

Trigger: The Postgres query for model streams fails: DB unreachable, connection pool exhausted, SQL error, table/schema drift (e.g. model_streams table missing or migration not applied), or empty/invalid planIds causing a malformed IN clause.

Common situations: Database outage or restart during deployment; connection-pool saturation under load; running the server against a schema that predates the model streams migration; read-replica failover.

Understand the failure class

Background: Database query failed: Internal Server Error 500s wrapping SQL, Prisma, and connection failures — what to check first — this error's family across 16 libraries.

Related errors


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