temporalio/temporal · error

unable to insert chasm search attributes: %w

Error message

unable to insert chasm search attributes: %w

What it means

The third statement of the InsertIntoVisibility transaction — inserting into the CHASM search attributes table (templateInsertChasmSearchAttributes) — failed. The transaction is rolled back and the error wrapped as 'unable to insert chasm search attributes'. CHASM visibility is a newer feature, so this most commonly fires when the visibility store schema predates the CHASM table.

Source

Thrown at common/persistence/sql/sqlplugin/mysql/visibility.go:122

	defer func() {
		err := tx.Rollback()
		// If the error is sql.ErrTxDone, it means the transaction already closed, so ignore error.
		if err != nil && !errors.Is(err, sql.ErrTxDone) {
			// Transaction rollback error should never happen, unless db connection was lost.
			retError = fmt.Errorf("transaction rollback failed: %w", retError)
		}
	}()
	result, err = tx.NamedExecContext(ctx, templateInsertWorkflowExecution, finalRow)
	if err != nil {
		return nil, fmt.Errorf("unable to insert workflow execution: %w", err)
	}
	_, err = tx.NamedExecContext(ctx, templateInsertCustomSearchAttributes, finalRow)
	if err != nil {
		return nil, fmt.Errorf("unable to insert custom search attributes: %w", err)
	}
	_, err = tx.NamedExecContext(ctx, templateInsertChasmSearchAttributes, finalRow)
	if err != nil {
		return nil, fmt.Errorf("unable to insert chasm search attributes: %w", err)
	}
	err = tx.Commit()
	if err != nil {
		return nil, err
	}
	return result, nil
}

// ReplaceIntoVisibility replaces an existing row if it exist or creates a new row in visibility table
func (mdb *db) ReplaceIntoVisibility(
	ctx context.Context,
	row *sqlplugin.VisibilityRow,
) (result sql.Result, retError error) {
	defer func() {
		retError = mdb.handle.ConvertError(retError)
	}()
	finalRow := mdb.prepareRowForDB(row)
	db, err := mdb.handle.DB()

View on GitHub (pinned to bde624efd1)

Solutions

  1. Check the wrapped cause: 'Table ... doesn't exist' means apply the latest visibility schema migrations.
  2. Run temporal-sql-tool update-schema against the temporal_visibility database.
  3. Verify the visibility store type/version supports CHASM (MySQL >= supported version, schema >= required release).
  4. If the wrapped error is constraint/dup-key related, inspect the VisibilityRow chasm fields for consistency with the execution row.
  5. Confirm connectivity to the visibility DB if the cause is a driver/connection error.

Example fix

// before: visibility schema older than server binary
// after
temporal-sql-tool -plugin mysql -ep $DB_HOST -u $DB_USER -p $DB_PWD update-schema -d temporal_visibility
Defensive patterns

Strategy: validation

Validate before calling

// Go: verify CHASM table exists at startup
var cnt int
if err := visDB.GetContext(ctx, &cnt,
    "SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = DATABASE() AND table_name = 'visibility_chasm_search_attributes'"); err != nil || cnt == 0 {
    logger.Fatal("visibility schema missing CHASM tables; run update-schema")
}

Try / catch

if err := db.InsertIntoVisibility(ctx, row); err != nil {
    if strings.Contains(err.Error(), "unable to insert chasm search attributes") {
        logger.Error("chasm SA insert failed; likely visibility schema drift", tag.Error(err))
        return convertPersistenceErr(err)
    }
    return err
}

Prevention

When it happens

Trigger: InsertIntoVisibility: templateInsertChasmSearchAttributes NamedExecContext fails — visibility_chasm_search_attributes table missing (old schema), constraint violation on the row, or connection loss mid-transaction.

Common situations: Upgrading to a Temporal version with CHASM visibility support without updating the visibility schema; misconfigured visibility database pointing at a stale schema; duplicate/inconsistent chasm attributes in the row struct.

Related errors


AI-assisted analysis of temporalio/temporal@bde624efd1 (2026-09-01). Data as JSON: /api/errors/9ef7be7be430c349. Report an issue: GitHub.