Skip to content

feat(query-coordinator): Add query job lifecycle handling - #2513

Draft
Bill-hbrhbr wants to merge 55 commits into
y-scope:mainfrom
Bill-hbrhbr:query-coordinator/job-handle
Draft

feat(query-coordinator): Add query job lifecycle handling#2513
Bill-hbrhbr wants to merge 55 commits into
y-scope:mainfrom
Bill-hbrhbr:query-coordinator/job-handle

Conversation

@Bill-hbrhbr

Copy link
Copy Markdown
Contributor

Description

Add the query-job lifecycle foundation to the query coordinator:

  • Introduce QueryJobHandle and a coordinator-prepared QueryPlan.
  • Submit new jobs, persist their Spider ID and running state, and recover submitted jobs.
  • Start and poll Spider jobs with bounded exponential backoff.
  • Persist successful, failed, and unexpectedly cancelled outcomes in the query-jobs table.
  • Add the spider_id and status_msg query-job columns, including idempotent upgrades for existing tables.

Spider task-graph construction remains intentionally deferred; submit_query_job retains its existing skeleton.

Checklist

  • The PR satisfies the contribution guidelines.
  • This is a breaking change and that has been indicated in the PR title, OR this isn't a
    breaking change.
  • Necessary docs have been updated, OR no docs need to be updated.

Validation performed

Not run yet. This is a draft PR, and repository checks are deferred until it is prepared for review.

Bill-hbrhbr and others added 30 commits August 27, 2026 13:17
Co-authored-by: Lin Zhihao <59785146+LinZhihao-723@users.noreply.github.com>
Co-authored-by: Lin Zhihao <59785146+LinZhihao-723@users.noreply.github.com>
Co-authored-by: Lin Zhihao <59785146+LinZhihao-723@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@LinZhihao-723 LinZhihao-723 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You should ask codex/claude to do an adversay code review: instead of telling it to code by following the guideline from https://github.com/LinZhihao-723/claude-instruction/tree/main/rust, ask it to:

  • The coding subagent programs by following the guideline.
  • The review subagent reviews the code by checking against the guideline.

That should bring the delivered code much closer to the desirable shape.

Comment on lines +153 to +182
# Upgrade query-job tables created before Spider lifecycle support was added.
query_jobs_table_upgrades = (
(
f"""
ALTER TABLE `{QUERY_JOBS_TABLE_NAME}`
ADD COLUMN `status_msg` VARCHAR(512) NOT NULL DEFAULT '' AFTER `status`
""",
ER_DUP_FIELDNAME,
),
(
f"""
ALTER TABLE `{QUERY_JOBS_TABLE_NAME}`
ADD COLUMN `spider_id` BIGINT UNSIGNED NULL DEFAULT NULL AFTER `job_config`
""",
ER_DUP_FIELDNAME,
),
(
f"""
ALTER TABLE `{QUERY_JOBS_TABLE_NAME}`
ADD INDEX `JOB_SPIDER_ID` (`spider_id`) USING BTREE
""",
ER_DUP_KEYNAME,
),
)
for upgrade_query, duplicate_error_code in query_jobs_table_upgrades:
try:
scheduling_db_cursor.execute(upgrade_query)
except Exception as err:
if not (hasattr(err, "errno") and err.errno == duplicate_error_code):
raise

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Similar to compression job table: we do not need to support backward compatibility.

Comment on lines +45 to +46
/// Drives one already-planned query job through submission and terminal persistence.
pub struct QueryJobHandle<SubmitterType: QueryJobSubmitter> {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Type parameter docstring is missing.

}

impl<SubmitterType: QueryJobSubmitter> QueryJobHandle<SubmitterType> {
/// Constructs a handle for an already-planned query job.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This docstring doesn't match the convention for factories.

result
}

async fn submit_and_wait(&self) -> Result<(), Error> {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I will stop reading since the docstrings are missing for all private methods.

Comment on lines +80 to +83
/// # Errors
///
/// Returns an error if submission, submission persistence, polling, or terminal persistence
/// fails.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The docstring does not match the coding guideline.

Comment on lines +98 to +100
/// # Errors
///
/// Returns an error if polling or terminal persistence fails.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The docstring does not match the coding guideline.

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.

2 participants