Skip to content

Comments

fix: prevent empty strings from overwriting step content in data layer#2790

Open
Pranjalya wants to merge 2 commits intoChainlit:mainfrom
Pranjalya:main
Open

fix: prevent empty strings from overwriting step content in data layer#2790
Pranjalya wants to merge 2 commits intoChainlit:mainfrom
Pranjalya:main

Conversation

@Pranjalya
Copy link

@Pranjalya Pranjalya commented Feb 18, 2026

fixes #2789

Description
In the ChainlitDataLayer, the create_step method uses an INSERT ... ON CONFLICT DO UPDATE pattern with COALESCE. Because Step objects initialize input and output as "" (empty string) instead of None, the database treats the empty string as a valid value to update, rather than a "missing" value to ignore.

This PR ensures that input and output are passed as None (SQL NULL) if they are empty strings. This allows the existing COALESCE logic in the SQL query to correctly preserve existing content if a late-arriving "initial" save task executes after a "final" update task.

Changes
Modified backend/chainlit/data/chainlit_data_layer.py:

  • Updated the params dictionary in create_step to convert empty input and output strings to None.

Testing
Verified using the reproduction script provided in the associated issue. With this change, the COALESCE function correctly identifies the NULL value and maintains the existing content even if the tasks finish out of order.


Summary by cubic

Prevents empty input/output strings from overwriting existing step content by treating them as NULL in the data layer, preserving final step data when saves finish out of order.

  • Bug Fixes
    • In ChainlitDataLayer.create_step, pass input/output as None when empty so SQL COALESCE keeps existing values; minor Ruff lint cleanup.

Written for commit 1d92838. Summary will update on new commits.

@dosubot dosubot bot added size:XS This PR changes 0-9 lines, ignoring generated files. data layer Pertains to data layers. labels Feb 18, 2026
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 1 file

@Pranjalya Pranjalya changed the title FIX: prevent empty strings from overwriting step content in data layer fix: prevent empty strings from overwriting step content in data layer Feb 18, 2026
@dokterbob dokterbob added the bug Something isn't working label Feb 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working data layer Pertains to data layers. size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Race condition in ChainlitDataLayer causes Steps to lose content in History

2 participants