plandex-ai/plandex · critical
Error getting active model stream
Error message
Error getting active model stream
What it means
proxyActivePlanMethod looks up the currently active model stream for a plan/branch via db.GetActiveModelStream before proxying a request (connect, stop, respond-missing-file, auto-load-context, build status) to the instance running the plan. A database error during that lookup triggers this HTTP 500. It is an infrastructure failure, not a business condition — the query itself could not be executed.
Source
Thrown at app/server/handlers/proxy_helper.go:21
import (
"fmt"
"io"
"log"
"net/http"
"os"
"plandex-server/db"
"plandex-server/host"
"time"
shared "plandex-shared"
)
func proxyActivePlanMethod(w http.ResponseWriter, r *http.Request, planId, branch, method string) {
modelStream, err := db.GetActiveModelStream(planId, branch)
if err != nil {
log.Printf("Error getting active model stream: %v\n", err)
http.Error(w, "Error getting active model stream", http.StatusInternalServerError)
return
}
if modelStream == nil {
log.Printf("No active model stream for plan %s\n", planId)
http.Error(w, "No active model stream for plan", http.StatusNotFound)
return
}
if modelStream.InternalIp == host.Ip {
// No active plan for this plan or else we wouldn't be calling proxyActivePlanMethod -- set the model stream to finished because something went wrong
err := db.SetModelStreamFinished(modelStream.Id)
if err != nil {
log.Printf("Error setting model stream %s to finished: %v\n", modelStream.Id, err)
}
err = db.SetPlanStatus(planId, branch, shared.PlanStatusError, "No active stream for plan")
if err != nil {View on GitHub (pinned to e2d772072e)
Solutions
- Read the server log for the underlying GetActiveModelStream error — the response deliberately hides details but the log has them.
- Verify DB connectivity (psql) and that the model_streams table/schema exists with the expected columns.
- Check connection pool configuration and whether limits were exhausted; raise pool size or fix connection leaks.
- Add retry with backoff around transient DB failures for read-only lookups.
- Set up DB health checks/alerts so outages are caught before user requests fail.
Example fix
// before
modelStream, err := db.GetActiveModelStream(planId, branch)
if err != nil {
http.Error(w, "Error getting active model stream", http.StatusInternalServerError)
return
}
// after
modelStream, err := db.GetActiveModelStream(planId, branch)
if err != nil {
if isTransientDbError(err) && retryGetActiveModelStream(&modelStream, planId, branch) == nil {
// recovered on retry
} else {
log.Printf("Error getting active model stream: %v", err)
http.Error(w, "Error getting active model stream", http.StatusInternalServerError)
return
}
} Defensive patterns
Strategy: retry
Validate before calling
// client-side: check plan status endpoint first
const status = await fetch(`/plans/${planId}/${branch}/status`).then(r => r.json());
if (!status || status.state !== 'running') throw new Error('Plan is not running'); Try / catch
// client with retry for 500s
async function callPlan(planId, branch, method, retries = 2) {
for (let i = 0; i <= retries; i++) {
const res = await fetch(`/plans/${planId}/${branch}/${method}`);
if (res.status === 500 && i < retries) { await sleep(2 ** i * 500); continue; }
return res;
}
} Prevention
- Monitor DB availability; alert on GetActiveModelStream failures.
- Keep schema migrations in sync with deployed code.
- Size the connection pool for peak concurrency and fix leaks.
- Add health checks so a down DB is caught before user traffic.
When it happens
Trigger: Postgres unreachable or the connection failed when any of the five handler endpoints call proxyActivePlanStream lookup; SQL error in GetActiveModelStream (missing table/column after migration drift); connection pool exhausted under load; transient network partition between server and DB.
Common situations: DB container restarted while plans were active; schema migration not applied so model_streams table is missing; too many concurrent plan connections exhausting the pool; DNS/network issues in Kubernetes between app and Postgres.
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
- Error getting contexts:
- Error creating project:
- Error listing projects:
- Error updating project:
- Error getting rows affected:
AI-assisted analysis of plandex-ai/plandex@e2d772072e (2026-09-05).
Data as JSON: /api/errors/06b425d99db92e6e.
Report an issue: GitHub.