-
Notifications
You must be signed in to change notification settings - Fork 37
fix: change message indexes to sort created_at descending #147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 5 commits
fed71b2
9dd7b45
c758a6d
2b32243
f3764a3
a9c458c
1cc69f0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,12 +21,8 @@ class TaskStateRepository(MongoDBCRUDRepository[StateEntity]): | |
| { | ||
| "keys": [("task_id", pymongo.ASCENDING), ("agent_id", pymongo.ASCENDING)], | ||
| "name": "task_agent_compound_idx", | ||
| "description": "Compound index for get_by_task_and_agent queries", | ||
| }, | ||
| { | ||
| "keys": [("task_id", pymongo.ASCENDING)], | ||
| "name": "task_id_idx", | ||
| "description": "Single index for task_id queries", | ||
| "unique": True, | ||
| "description": "Unique compound index for get_by_task_and_agent queries", | ||
| }, | ||
|
Comment on lines
22
to
26
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Adding The same applies to the sort-direction changes in To actually apply these changes, you need a one-time migration step (e.g., in # In ensure_mongodb_indexes or a migration script, before create_index:
try:
collection.drop_index("task_agent_compound_idx")
except Exception:
pass # index might not exist yet
collection.create_index(keys, name="task_agent_compound_idx", unique=True)Or expose the existing Prompt To Fix With AIThis is a comment left during a code review.
Path: agentex/src/domain/repositories/task_state_repository.py
Line: 22-26
Comment:
**Unique constraint won't apply to existing deployments**
Adding `unique: True` here will **not** enforce uniqueness on any environment where the `task_agent_compound_idx` index already exists as a non-unique index. When `ensure_mongodb_indexes` calls `collection.create_index(keys, name="task_agent_compound_idx", unique=True)` and an index with that name already exists without `unique`, MongoDB raises `OperationFailure: "already exists with different options"`. The catch block in `mongodb_indexes.py` (lines 87–93) silently logs a warning and moves on — the old index remains in place and **the uniqueness constraint is never applied**.
The same applies to the sort-direction changes in `task_message_repository.py`: the pre-existing `task_id_created_at_idx` (with `ASCENDING`) won't be replaced with the `DESCENDING` variant on any running database.
To actually apply these changes, you need a one-time migration step (e.g., in `ensure_mongodb_indexes` or a separate script) that drops the old indexes before recreating them:
```python
# In ensure_mongodb_indexes or a migration script, before create_index:
try:
collection.drop_index("task_agent_compound_idx")
except Exception:
pass # index might not exist yet
collection.create_index(keys, name="task_agent_compound_idx", unique=True)
```
Or expose the existing `drop_all_indexes` helper and run it once as part of the deploy process. Until this is addressed, the unique invariant described in the PR summary will only be enforced on fresh databases.
How can I resolve this? If you propose a fix, please make it concise. |
||
| { | ||
| "keys": [("agent_id", pymongo.ASCENDING)], | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.