vxcontrol/pentagi · error
failed to restore assistant msg chain: %w
Error message
failed to restore assistant msg chain: %w
What it means
PrepareAgentChain failed while restoring the assistant message chain via ap.fp.restoreChain, which loads (or creates) the persisted Msgchain row for the assistant agent. Without a restored chain ID the assistant cannot continue its conversation history, so the flow preparation aborts with this wrapped error.
Source
Thrown at backend/pkg/providers/assistant.go:127
"provider": ap.fp.Type(),
"assistant_id": ap.id,
"flow_id": ap.fp.ID(),
})
systemPrompt, err := ap.getAssistantSystemPrompt(ctx)
if err != nil {
logger.WithError(err).Error("failed to get assistant system prompt")
return 0, fmt.Errorf("failed to get assistant system prompt: %w", err)
}
optAgentType := pconfig.OptionsTypeAssistant
msgChainType := database.MsgchainTypeAssistant
ap.msgChainID, _, err = ap.fp.restoreChain(
ctx, nil, nil, optAgentType, msgChainType, systemPrompt, "",
)
if err != nil {
logger.WithError(err).Error("failed to restore assistant msg chain")
return 0, fmt.Errorf("failed to restore assistant msg chain: %w", err)
}
return ap.msgChainID, nil
}
func (ap *assistantProvider) PerformAgentChain(ctx context.Context) error {
ctx, span := obs.Observer.NewSpan(ctx, obs.SpanKindInternal, "providers.assistantProvider.PerformAgentChain")
defer span.End()
logger := logrus.WithContext(ctx).WithFields(logrus.Fields{
"provider": ap.fp.Type(),
"assistant_id": ap.id,
"flow_id": ap.fp.ID(),
"msg_chain_id": ap.msgChainID,
})
useAgents, err := ap.getAssistantUseAgents(ctx)
if err != nil {View on GitHub (pinned to ea665308ba)
Solutions
- Inspect the wrapped DB error from restoreChain
- Verify Postgres connectivity and that migrations in backend/migrations/sql are applied
- Check the msgchain/flow rows for the given flow_id (orphans or duplicates)
- Retry the flow creation; if persistent, check backend logs just before this error for the underlying sql error
Defensive patterns
Strategy: retry
Validate before calling
// ensure flow row exists before restoring the chain // SELECT id FROM flows WHERE id = ?
Try / catch
id, err := ap.PrepareAgentChain(ctx)
if err != nil {
if isTransientDBError(err) {
time.Sleep(backoff)
id, err = ap.PrepareAgentChain(ctx) // bounded retry
}
if err != nil { return err }
} Prevention
- Keep Postgres reachable with sane pool sizes and health checks
- Apply all goose migrations before starting workers
- Avoid concurrent flow deletion while agents restore chains
- Wrap restoreChain retries with bounded backoff and context timeout
When it happens
Trigger: restoreChain(ctx, nil, nil, OptionsTypeAssistant, MsgchainTypeAssistant, systemPrompt, "") fails: msgchain row lookup/insert fails, foreign-key issues on flow_id, DB unavailable, or context cancelled mid-query.
Common situations: Postgres outage or connection pool exhaustion; corrupted/partial flow data (flow deleted concurrently); migration drift leaving msgchain schema stale; restoring a chain for a flow whose ID no longer exists.
Related errors
- failed to get assistant system prompt: %w
- failed to put input for task %d: %w
- failed to get assistant use agents: %w
- token not found in database
- failed to create flow in DB: %w
AI-assisted analysis of vxcontrol/pentagi@ea665308ba (2026-09-01).
Data as JSON: /api/errors/dd835638597b08ab.
Report an issue: GitHub.