plandex-ai/plandex · error

failed to store assistant message: %v

Error message

failed to store assistant message: %v

What it means

Raised while persisting the assistant message after a successful stream: after storing the conversation via the auto-loaded context (activatePathsOrdered, removedSubtasks), the returned err indicates the assistant message could not be stored. The error is reported through state.onError with storeDesc:true and then returned, aborting the store phase of the stream finalization even though the model output itself was generated.

Source

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

		if hasNewSubtasks && (state.req.IsApplyDebug || state.req.IsUserDebug) {
			log.Println("storeOnFinished: hasNewSubtasks && (state.req.IsApplyDebug || state.req.IsUserDebug)")
			flags.DidMakeDebuggingPlan = true
		}

		log.Println("storeOnFinished: flags", flags)

		assistantMsg, convoCommitMsg, err := state.storeAssistantReply(repo, storeAssistantReplyParams{
			flags:                flags,
			subtask:              messageSubtask,
			addedSubtasks:        addedSubtasks,
			activatePaths:        autoLoadContextResult.activatePaths,
			activatePathsOrdered: autoLoadContextResult.activatePathsOrdered,
			removedSubtasks:      removedSubtasks,
		}) // updates state.convo

		if err != nil {
			state.onError(onErrorParams{
				streamErr: fmt.Errorf("failed to store assistant message: %v", err),
				storeDesc: true,
			})
			return err
		}

		log.Println("getting description for assistant message: ", assistantMsg.Id)

		var description *db.ConvoMessageDescription
		if len(replyOperations) == 0 {
			description = &db.ConvoMessageDescription{
				OrgId:                 currentOrgId,
				PlanId:                planId,
				ConvoMessageId:        assistantMsg.Id,
				SummarizedToMessageId: summarizedToMessageId,
				BuildPathsInvalidated: map[string]bool{},
				WroteFiles:            false,
			}
		} else {

View on GitHub (pinned to e2d772072e)

Solutions

  1. Check the wrapped %v cause: fix the underlying db error (unlock/close other processes, free disk space).
  2. Run any pending database migrations for the app version.
  3. Retry the session/tell request once the database is writable.
  4. Back up and repair/recreate a corrupt conversation database if corruption is reported.
  5. If caused by oversized payloads, trim conversation content before storage.

Example fix

// before
if err != nil {
    state.onError(onErrorParams{streamErr: fmt.Errorf("failed to store assistant message: %v", err), storeDesc: true})
    return err
}
// after: retry transient store failures before giving up
if err != nil {
    if retryErr := retryDbStore(func() error { return db.StoreConvoMessage(assistantMsg) }, 3); retryErr != nil {
        state.onError(onErrorParams{streamErr: fmt.Errorf("failed to store assistant message: %v", retryErr), storeDesc: true})
        return retryErr
    }
}
Defensive patterns

Strategy: try-catch

Validate before calling

// before storing: ensure the DB is writable
func ensureDbWritable(db *sql.DB) error {
    if err := db.Ping(); err != nil { return err }
    _, err := db.Exec("PRAGMA quick_check;")
    return err
}

Try / catch

if err := storeAssistantMessage(assistantMsg); err != nil {
    state.onError(onErrorParams{streamErr: fmt.Errorf("failed to store assistant message: %v", err), storeDesc: true})
    return fmt.Errorf("store assistant message %s: %w", assistantMsg.Id, err)
}

Prevention

When it happens

Trigger: db layer fails while writing the assistant message row: database file locked/corrupt, disk full, migration mismatch, or the store call after updating state.convo returns a non-nil error (constraint violation on message fields, oversized payload).

Common situations: SQLite database locked by another process (a second client/editor instance open on the same project); read-only or full disk; schema migration out of date after a version upgrade; very large assistant reply exceeding storage limits.

Related errors


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