fix(data): strip only the key prefix when reading DynamoDB thread ids
Description
str.strip(chars) treats its argument as a set of characters rather than a prefix, so it also eats the identifier's own leading and trailing letters:
>>> "THREAD#DEMO".strip("THREAD#")
'MO'
>>> "THREAD#CODE".strip("THREAD#")
'CO'
The DynamoDB data layer uses strip("THREAD#"), strip("STEP#") and strip("TS#") in four places (lines 180, 181, 503, 504). This corrupts thread and step IDs that happen to start or end with any of those characters. Consequences:
list_threadsreturns truncated IDs to the frontend.delete_feedbackbuilds the primary key from those truncated IDs, so a delete silently targets a different row.
IDs generated by Chainlit are lowercase-hex UUIDs and are unaffected, so this is latent for the default case but real for custom IDs. The same file already uses removeprefix correctly on line 635 (pk.removeprefix("THREAD#")); this PR applies that pattern consistently.
Changes
backend/chainlit/data/dynamodb.py: replace fourstrip(...)calls withremoveprefix(...).backend/tests/data/test_dynamodb.py: add the first tests for the DynamoDB data layer, covering thread-list prefix stripping and feedback-delete key construction.
Tests
cd backend
python -m pytest tests/data/test_dynamodb.py -q
- Before: 2 failures, with the assertion diff showing the truncation (
{'PK': {'S': 'THREAD#CO'}}vs the expected{'PK': {'S': 'THREAD#CODE'}}). - After:
2 passed.
Checklist
- Conventional Commits format used.
- Change is backward-compatible.
- Tests pass locally, and
ruff check/ruff format --checkpass.
Summary by cubic
Fixes DynamoDB thread ID handling where str.strip() removed trailing characters from IDs like THREAD#DEMO → MO, causing list_threads to return truncated IDs and delete_feedback to build delete keys for the wrong rows. Switches to removeprefix() so only the prefix is stripped, and adds the first tests for the DynamoDB data layer covering these paths.