Skip to content

Release 6.10.2025 - #573

Merged
maxtechera merged 16 commits into
productionfrom
staging
Oct 6, 2025
Merged

Release 6.10.2025#573
maxtechera merged 16 commits into
productionfrom
staging

Conversation

@maxtechera

Copy link
Copy Markdown
Collaborator

No description provided.

bradtaylorsf and others added 16 commits September 26, 2025 09:25
Adds an index to the executive dashboard to manage document stores
Summary
This PR introduces several key upgrades and new features across core
generative AI model integrations, along with enhancements for image
generation, user context handling, and prompt-level caching.

Key Changes
1. Model Registry Updates
- Added gemini-2.5-flash-image-preview model for image generation and
understanding.
- Added support for gpt-5, gpt-5-mini, and gpt-5-nano models with
explicit cost metadata.
- Default models for Google Gemini and Anthropic Claude updated:
- Gemini default: gemini-2.5-flash
- Anthropic default: claude-sonnet-4-0

2. Google Generative AI – Image Generation Integration
- Response Modalities: Added responseModalities input and UI option.
Supports TEXT and IMAGE outputs.
- User Context: Model initialization now propagates user organization,
ID, and email (for image upload/auth).
- Image Handling:
- Auto-uploads generated images to storage, organized by user/org.
- Injects image Markdown into final output (supports streaming and
non-streaming).
- Safely builds public URLs for generated images.

3. Chat Model Inputs & User Experience
- OpenAI Node: Added promptCacheKey input for prompt-level cache
control, improving cache efficiency and cost management.
- Various code and interface refinements to surface new modalities,
credential usage, and context passing

4. File Upload & Image Upload Permission
Simplified isImageUploadAllowed logic: chat models with
allowImageUploads: true will correctly enable image upload in the UI,
regardless of specific node names.

Motivation & Context

- Adds early support for the latest Google Gemini and GPT-5 models.
- Enables direct image generation and output via Gemini, including
correct inline preview for users.
- Improves auditability and compliance of generated assets by tying
uploads to user/org context.
- Provides finer control over OpenAI prompt-caching to optimize costs.

Testing

- Validated image generation and upload using
gemini-2.5-flash-image-preview, confirming correct Markdown injection
and download links.
- Verified prompt cache hits with OpenAI using custom promptCacheKey.
- Confirmed new models selectable and default as expected for
Gemini/Anthropic.
- Image upload UI toggle respects new chat model configuration.
This commit introduces significant enhancements to the AAIToolAgent,
including the addition of an output parser for structured output. The
agent now supports parsing its output into a structured format,
improving the usability and flexibility of the tool. Key changes
include:

- Updated constructor to include an optional output parser input.
- Enhanced the run method to initialize and utilize the output parser.
- Added methods for injecting format instructions into the system
message and parsing the output.

These improvements aim to provide a more robust and user-friendly
experience for users leveraging the Tool Agent in the Answer tab.
## 🐛 Problem
Users were experiencing duplicate default chatflows being created when
logging in concurrently. This race condition occurred primarily in
production environments where multiple authentication requests for the
same user could execute simultaneously.

### Root Cause
The race condition had several contributing factors:
1. **Stale In-Memory Data**: The `findOrCreateDefaultChatflowsForUser`
function relied on in-memory user objects that could be outdated
2. **Missing Database Persistence**: The authentication middleware
updated `user.defaultChatflowId` in memory but didn't persist it to the
database immediately
3. **No Database-Level Protection**: Multiple processes could create
duplicate chatflows simultaneously without constraint enforcement

## ✅ Solution
This PR implements a multi-layered fix:

### 1. **Application-Level Fixes**
- **Enhanced Database Checks**: `findOrCreateDefaultChatflowsForUser`
now always queries the database for the latest `defaultChatflowId`
instead of trusting stale in-memory data
- **Immediate Persistence**: Authentication middleware now persists
`defaultChatflowId` updates to the database immediately
- **Transaction-Level Safety**: Added additional database checks within
transactions to prevent race conditions
- **Graceful Conflict Resolution**: Added cleanup logic for redundant
chatflows created during race conditions

### 2. **Database-Level Protection**
- **Unique Constraint**: Added a partial unique index to prevent
multiple default chatflows per user per template
- **Safe Migration**: Migration includes duplicate cleanup and
constraint enforcement
- **Constraint Violation Handling**: Application code gracefully handles
unique constraint violations

## 🔧 Changes Made

### Code Changes
- `packages/server/src/middlewares/authentication/index.ts`: Added
immediate database persistence
-
`packages/server/src/middlewares/authentication/findOrCreateDefaultChatflowsForUser.ts`:
Enhanced with database-first checks and conflict resolution
-
`packages/server/src/database/migrations/postgres/1753000000001-AddUniqueConstraintDefaultChatflows.ts`:
New migration for unique constraint

### Database Schema
- Added unique partial index: `idx_unique_user_parent_chatflow` on
`("userId", "parentChatflowId")` where `"parentChatflowId" IS NOT NULL
AND "deletedDate" IS NULL`

## 🚨 Pre-Migration Steps Required

**⚠️ IMPORTANT**: Before running the migration, you must manually clean
up existing duplicate chatflows:

1. **Analyze Duplicates**:
   ```sql
   -- Run this to see all duplicate chatflows
   -- (Use scripts/dbeaver-detailed-analysis.sql)
   ```

2. **Generate DELETE Statements**:
   ```sql
   -- Run this to generate safe DELETE statements
   -- (Use scripts/dbeaver-improved-deletes.sql)
   ```

3. **Manual Cleanup**:
   - Review each generated DELETE statement
   - Execute them individually in DBeaver
   - Verify user `defaultChatflowId` references remain valid

4. **Run Migration**:
   - Migration will fail safely if duplicates remain
   - Only proceeds when database is clean

## 🧪 Testing

### Reproduction Test
Created test scripts to simulate concurrent authentication requests:
- Multiple simultaneous `/api/v1/auth/me` calls
- Database verification queries
- Race condition detection logic

### Local Testing Results
- ✅ No race condition detected in local environment (expected due to low
latency)
- ✅ Code changes prevent race condition through multiple safety layers
- ✅ Unique constraint provides database-level enforcement

## 📊 Impact Analysis

### Production Data (Example)
- **Users with duplicates**: 57
- **Total duplicate chatflows**: 121  
- **Chatflows to be cleaned up**: ~64
- **Safe DELETE generation**: Prioritizes user's current
`defaultChatflowId`

### User Experience
- ✅ **No Functionality Loss**: Users retain access to their default
chatflows
- ✅ **Performance Improvement**: Fewer duplicate chatflows reduce
database load
- ✅ **Data Integrity**: Guaranteed unique default chatflows per user per
template

## 🔄 Deployment Steps

1. **Pre-deployment**:
   - [ ] Run duplicate analysis scripts
   - [ ] Execute manual cleanup of duplicate chatflows
   - [ ] Verify all user `defaultChatflowId` references are valid

2. **Deployment**:
   - [ ] Deploy code changes
   - [ ] Run migration (will validate no duplicates remain)
   - [ ] Verify unique constraint is active

3. **Post-deployment**:
   - [ ] Monitor for any constraint violations (should be none)
   - [ ] Verify user login experience is normal
   - [ ] Confirm no new duplicate chatflows are created

## 🔍 Verification Queries

After deployment, verify the fix:

```sql
-- Should return 0
SELECT COUNT(*) FROM (
    SELECT "userId", "parentChatflowId"
    FROM "chat_flow"
    WHERE "parentChatflowId" IS NOT NULL AND "deletedDate" IS NULL
    GROUP BY "userId", "parentChatflowId"
    HAVING COUNT(*) > 1
) duplicates;

-- Should show the unique constraint exists
SELECT indexname, indexdef 
FROM pg_indexes 
WHERE tablename = 'chat_flow' 
  AND indexname = 'idx_unique_user_parent_chatflow';
```

## 🎯 Related Issues
- Fixes: Race condition in default chatflow creation during concurrent
user authentication
- Prevents: Multiple default chatflows per user per template
- Improves: Database integrity and application performance

---------

Co-authored-by: DiegoC <diecoscai@gmail.com>
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Cameron Taylor <50385537+ct3685@users.noreply.github.com>
Co-authored-by: Max Techera <maxi.techerag@gmail.com>
…yaml formatting (#568)

chore: update submodule URL for embed package and clean up
pnpm-lock.yaml formatting
## Summary
- Integrated Meta Pixel (ID: 25220750360842472) for conversion tracking
- Enhanced tracking service to support Facebook Pixel events
- Added comprehensive form interaction tracking to
WebinarRegistrationForm

## Changes
- **Docusaurus Config**: Added Meta Pixel initialization script with
PageView tracking
- **Tracking Service**: Enhanced with Facebook Pixel support including
CompleteRegistration, InitiateCheckout events
- **WebinarRegistrationForm**: 
  - Track form start when user begins typing
- Track successful registration with lead score and estimated value
($100)
  - Track form abandonment on errors or page leave
- **Fixed**: React unescaped entities warnings in webinar pages

## Testing
- [x] Verify Meta Pixel loads on all pages (check Network tab for
facebook.com requests)
- [x] Test form interaction tracking (start, complete, abandon)
- [x] Confirm CompleteRegistration event fires with correct data
- [ ] Validate events in Meta Events Manager
- [ ] Test with Meta Pixel Helper Chrome extension

## Context
This enables conversion tracking for perpetual bi-weekly webinar
campaigns, providing proper attribution and optimization signals for
Meta Ads campaigns focused on our proven use cases:
- IAS: Chief Sidekick + Help Center chatbot
- WOW: Call transcript analysis + support automation
- Content management and enterprise search

🤖 Generated with [Claude Code](https://claude.ai/code)

---------

Co-authored-by: Claude <noreply@anthropic.com>
…#569)

chore: update pnpm-lock.yaml formatting and embed submodule reference
Key Changes
1. Tracking Metadata Field
Interface & Entity Changes:
Added trackingMetadata (type: object or string, depending on module) to:
IChatMessage interface
IncomingInput interface
The ChatMessage TypeORM entity
Database Migration:
Introduced migration scripts for all major DBs (MariaDB, MySQL,
Postgres, SQLite) to add the tracking_metadata column to the
chat_message table.
Registered new migration in each database’s migration index.
2. End-to-End Metadata Handling
Backend:
Ensured trackingMetadata is properly passed and stored with user and
agent messages throughout the chat flow execution.
Extended buildChatflow.ts and handler.ts to augment records and
callbacks with this metadata.
Metadata is stored as JSON (or text) in the DB and sent to Langfuse with
each field prefixed as tracking_*.
API Specification:
Updated the OpenAPI YAML to document the trackingMetadata property for
prediction requests.
Frontend:
AnswersProvider: Adds trackingMetadata (with url and source fields) to
the chat request payload.
3. Dependency Cleanup
aai-embed-react:
Removed direct dependency from packages-answers/ui/package.json and
pnpm-lock.yaml.
Now resolved via workspace protocol from apps/web instead.
Other Dependency Updates:
Upgraded eslint, rollup, tailwindcss, and related plugins to latest
versions.
Replaced old dependency versions where needed for improved compatibility
(see pnpm-lock.yaml changes).
Motivation
Analytics & Reporting: Allows more granular tracking of user actions and
chat contexts (e.g., what page, product, or source initiated a chat).
Flexibility: Lets clients and frontends attach any relevant
tags/identifiers to chat requests for downstream observability tools
(Langfuse, etc).
Dependency Hygiene: Removes unnecessary/duplicated dependencies and
brings key dev/build tooling up to date.
)

chore: update embed submodule reference to latest commit 09bc07d74
chore: add package.json for embed-react to Dockerfile
## Summary
- Adds JLINC integration for comprehensive AI observability and
compliance tracking
- Implements LangChain callback handler to track LLM and tool events
- Provides Flowise UI configuration for easy setup

## Changes

### New Package: `packages-jlinc/jlinc-tracer`
- Custom LangChain callback handler that extends `LangChainTracer`
- Tracks events: `llm_start`, `llm_end`, `tool_start`, `tool_end`
- Sends telemetry data to JLINC API endpoints for archival and
compliance

### Flowise Integration
- **Credentials**: Added `JlincApi.credential.ts` for API configuration
- **Analytics Node**: Created JLINC analytics node for Flowise workflows
- **Handler Integration**: Modified `handler.ts` to instantiate
JLINCTracer when JLINC is selected

### UI Updates  
- Added JLINC to analytics providers in `AnalyseFlow.jsx`
- Included configuration fields for Agreement ID and System Prefix
- Added JLINC logo assets

## Configuration

Users can enable JLINC tracking by:
1. Adding JLINC API credentials in Flowise
2. Selecting JLINC as the analytics provider in their flow
3. Configuring Agreement ID (optional) and System Prefix

## Test Plan
- [ ] Verify JLINC credentials can be created and saved
- [ ] Test JLINC analytics node appears in Flowise UI
- [ ] Confirm events are logged when JLINC is enabled
- [ ] Validate API connectivity with test endpoints

🤖 Generated with [Claude Code](https://claude.ai/code)

---------

Co-authored-by: Claude <noreply@anthropic.com>
@vercel

vercel Bot commented Oct 6, 2025

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Updated (UTC)
answerai-docs Ready Ready Preview Oct 6, 2025 2:13pm
the-answerai Ready Ready Preview Oct 6, 2025 2:13pm

@maxtechera
maxtechera merged commit 61b9984 into production Oct 6, 2025
8 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants