Skip to content

chore: implement prefect task scheduler#955

Closed
iziang wants to merge 2 commits into
mainfrom
support/prefect
Closed

chore: implement prefect task scheduler#955
iziang wants to merge 2 commits into
mainfrom
support/prefect

Conversation

@iziang

@iziang iziang commented Jun 18, 2025

Copy link
Copy Markdown
Contributor

No description provided.

@apecloud-bot apecloud-bot added the size/XXL Denotes a PR that changes 1000+ lines. label Jun 18, 2025
cursor[bot]

This comment was marked as outdated.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: Prefect Scheduler Incorrectly Retrieves Flow Run ID

The PrefectTaskScheduler methods (e.g., schedule_create_index, schedule_collection_init, schedule_collection_delete, schedule_reconcile_indexes) incorrectly attempt to retrieve a flow run ID by accessing a .id attribute on the return value of Prefect flow functions. These flow functions are designed to return dictionaries, not objects with an .id attribute. While a hasattr check prevents an AttributeError, it causes the flow_run_id to be set to the string representation of the returned dictionary, which is not a valid or trackable Prefect flow run ID.

aperag/tasks/scheduler.py#L434-L440

# Execute workflow and return flow run ID
flow_state = create_document_indexes_flow(document_id, index_types)
flow_run_id = flow_state.id if hasattr(flow_state, 'id') else str(flow_state)
logger.debug(
f"Scheduled create indexes flow {flow_run_id} for document {document_id} with types {index_types}"
)
return flow_run_id

aperag/tasks/scheduler.py#L466-L471

# Execute workflow and return flow run ID
flow_state = delete_document_indexes_flow(document_id, index_types)
flow_run_id = flow_state.id if hasattr(flow_state, 'id') else str(flow_state)
logger.debug(
f"Scheduled delete indexes flow {flow_run_id} for document {document_id} with types {index_types}"
)

aperag/tasks/scheduler.py#L482-L484

flow_state = collection_init_flow(collection_id, document_user_quota)
flow_run_id = flow_state.id if hasattr(flow_state, 'id') else str(flow_state)
logger.debug(f"Scheduled collection init flow {flow_run_id} for collection {collection_id}")

Fix in Cursor


Bug: Quota Initialization Bug

The if not document_user_quota: condition incorrectly defaults document_user_quota to 100. This changes valid quota values of 0 (meaning no documents allowed) and None (potentially signifying an unlimited quota) to 100, fundamentally altering the intended collection initialization behavior.

aperag/service/collection_service.py#L91-L94

document_user_quota = await self.db_ops.query_user_quota(user, QuotaType.MAX_DOCUMENT_COUNT)
if not document_user_quota:
document_user_quota = 100

Fix in Cursor


Bug: Flow State Access Error in Scheduler Methods

Incorrect attribute access pattern in PrefectTaskScheduler methods, including schedule_update_index and schedule_collection_delete. The code attempts to access flow_state.id when flow_state can be a dictionary, leading to an AttributeError.

aperag/tasks/scheduler.py#L450-L455

# Execute workflow and return flow run ID
flow_state = update_document_indexes_flow(document_id, index_types)
flow_run_id = flow_state.id if hasattr(flow_state, 'id') else str(flow_state)
logger.debug(
f"Scheduled update indexes flow {flow_run_id} for document {document_id} with types {index_types}"
)

aperag/tasks/scheduler.py#L494-L496

try:
flow_state = collection_delete_flow(collection_id)
flow_run_id = flow_state.id if hasattr(flow_state, 'id') else str(flow_state)

Fix in Cursor


Was this report helpful? Give feedback by reacting with 👍 or 👎

@iziang iziang closed this Jun 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/XXL Denotes a PR that changes 1000+ lines.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants