Skip to content

feat(logging)!: Add context variables to query logs.#2341

Open
rishikeshdevsot wants to merge 3 commits into
y-scope:mainfrom
rishikeshdevsot:pr-query-log-correlation
Open

feat(logging)!: Add context variables to query logs.#2341
rishikeshdevsot wants to merge 3 commits into
y-scope:mainfrom
rishikeshdevsot:pr-query-log-correlation

Conversation

@rishikeshdevsot

@rishikeshdevsot rishikeshdevsot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor
  • Adds scoped log context variables to query scheduler and worker logs. The logs now include job_id, task_id, query_job_type, query, query_hash, archive_id and dataset where available.
  • This makes it easier to follow a query job across scheduler logs, worker logs, and subprocess log dumps.

Note

BREAKING CHANGE:
This PR changes the log text in query scheduler and worker.

Description

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

  • Ran successful wildcard, log-text, and variable queries on hive dataset
  • Ran a failing query 'MapTask metrics system started'
    • Query scheduler logs
{"event": "Got reducer at reducer:14011", "job_id": "1", "query_hash": "2912be0eedb438f54549b2f09a5be5ff1570a07a89934c6c35e2b433bc5c2a88", "query": "482dbdc2", "query_job_type": "SEARCH_OR_AGGREGATION", "logger": "search-job-handler", "level": "info", "timestamp": "2026-07-10T22:09:49.588343Z", "filename": "query_scheduler.py", "lineno": 790, "func_name": "acquire_reducer_for_job"}
{"event": "Dispatched job with 13 archives to search.", "job_id": "1", "query_hash": "2912be0eedb438f54549b2f09a5be5ff1570a07a89934c6c35e2b433bc5c2a88", "query": "482dbdc2", "query_job_type": "SEARCH_OR_AGGREGATION", "logger": "search-job-handler", "level": "info", "timestamp": "2026-07-10T22:09:50.881980Z", "filename": "query_scheduler.py", "lineno": 930, "func_name": "handle_pending_query_jobs"}
{"event": "Got reducer at reducer:14010", "job_id": "2", "query_hash": "f3547bd468cc4db2f442df239175976cc5969706ceb2319470f951ddd07a5270", "query": "job_1427088391284_0001", "query_job_type": "SEARCH_OR_AGGREGATION", "logger": "search-job-handler", "level": "info", "timestamp": "2026-07-10T22:09:50.989890Z", "filename": "query_scheduler.py", "lineno": 790, "func_name": "acquire_reducer_for_job"}
{"event": "Got reducer at reducer:14012", "job_id": "3", "query_hash": "6395fbecb81e23edb51cbd01542c571d636f5879eeb76a6894cd255c3e4f0783", "query": "\"MapTask metrics system started\"", "query_job_type": "SEARCH_OR_AGGREGATION", "logger": "search-job-handler", "level": "info", "timestamp": "2026-07-10T22:09:50.990248Z", "filename": "query_scheduler.py", "lineno": 790, "func_name": "acquire_reducer_for_job"}
{"event": "Got reducer at reducer:14015", "job_id": "4", "query_hash": "684888c0ebb17f374298b65ee2807526c066094c701bcc7ebbe1c1095f494fc1", "query": "*", "query_job_type": "SEARCH_OR_AGGREGATION", "logger": "search-job-handler", "level": "info", "timestamp": "2026-07-10T22:09:50.990609Z", "filename": "query_scheduler.py", "lineno": 790, "func_name": "acquire_reducer_for_job"}
{"event": "Dispatched job with 13 archives to search.", "job_id": "2", "query_hash": "f3547bd468cc4db2f442df239175976cc5969706ceb2319470f951ddd07a5270", "query": "job_1427088391284_0001", "query_job_type": "SEARCH_OR_AGGREGATION", "logger": "search-job-handler", "level": "info", "timestamp": "2026-07-10T22:09:51.064868Z", "filename": "query_scheduler.py", "lineno": 930, "func_name": "handle_pending_query_jobs"}
{"event": "Dispatched job with 13 archives to search.", "job_id": "3", "query_hash": "6395fbecb81e23edb51cbd01542c571d636f5879eeb76a6894cd255c3e4f0783", "query": "\"MapTask metrics system started\"", "query_job_type": "SEARCH_OR_AGGREGATION", "logger": "search-job-handler", "level": "info", "timestamp": "2026-07-10T22:09:51.115615Z", "filename": "query_scheduler.py", "lineno": 930, "func_name": "handle_pending_query_jobs"}
{"event": "Dispatched job with 13 archives to search.", "job_id": "4", "query_hash": "684888c0ebb17f374298b65ee2807526c066094c701bcc7ebbe1c1095f494fc1", "query": "*", "query_job_type": "SEARCH_OR_AGGREGATION", "logger": "search-job-handler", "level": "info", "timestamp": "2026-07-10T22:09:51.180628Z", "filename": "query_scheduler.py", "lineno": 930, "func_name": "handle_pending_query_jobs"}
  • Query worker logs
{"event": "Started search task", "job_id": "1", "query_hash": "2912be0eedb438f54549b2f09a5be5ff1570a07a89934c6c35e2b433bc5c2a88", "archive_id": "90c97519-2cc1-4159-9952-143a7cb19d5b", "query": "482dbdc2", "query_job_type": "SEARCH_OR_AGGREGATION", "dataset": "default", "task_id": 8, "logger": "job_orchestration.executor.query.fs_search_task", "level": "info", "timestamp": "2026-07-10T22:09:50.800981Z", "func_name": "search_entry_point", "lineno": 266, "filename": "fs_search_task.py"}
{"event": "Started search task", "archive_id": "075d7338-9d9f-4f1e-86f5-e0fb63010e2e", "query_hash": "2912be0eedb438f54549b2f09a5be5ff1570a07a89934c6c35e2b433bc5c2a88", "task_id": 13, "query": "482dbdc2", "job_id": "1", "query_job_type": "SEARCH_OR_AGGREGATION", "dataset": "default", "logger": "job_orchestration.executor.query.fs_search_task", "level": "info", "timestamp": "2026-07-10T22:09:50.802210Z", "func_name": "search_entry_point", "lineno": 266, "filename": "fs_search_task.py"}
{"event": "Started search task", "archive_id": "75e2226f-80b3-4a2f-b90d-55748ad69e7b", "job_id": "1", "dataset": "default", "query_job_type": "SEARCH_OR_AGGREGATION", "query": "482dbdc2", "task_id": 12, "query_hash": "2912be0eedb438f54549b2f09a5be5ff1570a07a89934c6c35e2b433bc5c2a88", "logger": "job_orchestration.executor.query.fs_search_task", "level": "info", "timestamp": "2026-07-10T22:09:50.802400Z", "func_name": "search_entry_point", "lineno": 266, "filename": "fs_search_task.py"}
{"event": "Started search task", "task_id": 11, "archive_id": "15873667-2da2-4dda-ae03-0bc6b6b7149d", "job_id": "1", "dataset": "default", "query_job_type": "SEARCH_OR_AGGREGATION", "query": "482dbdc2", "query_hash": "2912be0eedb438f54549b2f09a5be5ff1570a07a89934c6c35e2b433bc5c2a88", "logger": "job_orchestration.executor.query.fs_search_task", "level": "info", "timestamp": "2026-07-10T22:09:50.802965Z", "func_name": "search_entry_point", "lineno": 266, "filename": "fs_search_task.py"}
{"event": "Running: /opt/clp/bin/clp-s s /var/data/archives/default --archive-id 73af0489-cfa4-4f4f-8726-f7d77e873a80 482dbdc2 reducer --host reducer --port 14011 --job-id 1 --count", "query": "482dbdc2", "query_hash": "2912be0eedb438f54549b2f09a5be5ff1570a07a89934c6c35e2b433bc5c2a88", "archive_id": "73af0489-cfa4-4f4f-8726-f7d77e873a80", "task_id": 1, "job_id": "1", "query_job_type": "SEARCH_OR_AGGREGATION", "dataset": "default", "logger": "job_orchestration.executor.query.fs_search_task", "level": "info", "timestamp": "2026-07-10T22:09:50.804174Z", "func_name": "run_query_task", "lineno": 67, "filename": "utils.py"}
{"event": "Running: /opt/clp/bin/clp-s s /var/data/archives/default --archive-id 511a89cb-b7b6-4263-bb47-dbb15220c427 482dbdc2 reducer --host reducer --port 14011 --job-id 1 --count", "query": "482dbdc2", "query_hash": "2912be0eedb438f54549b2f09a5be5ff1570a07a89934c6c35e2b433bc5c2a88", "task_id": 3, "archive_id": "511a89cb-b7b6-4263-bb47-dbb15220c427", "job_id": "1", "dataset": "default", "query_job_type": "SEARCH_OR_AGGREGATION", "logger": "job_orchestration.executor.query.fs_search_task", "level": "info", "timestamp": "2026-07-10T22:09:50.804354Z", "func_name": "run_query_task", "lineno": 67, "filename": "utils.py"}
{"event": "Started search task", "job_id": "4", "query_hash": "684888c0ebb17f374298b65ee2807526c066094c701bcc7ebbe1c1095f494fc1", "archive_id": "73af0489-cfa4-4f4f-8726-f7d77e873a80", "query": "*", "query_job_type": "SEARCH_OR_AGGREGATION", "dataset": "default", "task_id": 40, "logger": "job_orchestration.executor.query.fs_search_task", "level": "info", "timestamp": "2026-07-10T22:09:51.161782Z", "func_name": "search_entry_point", "lineno": 266, "filename": "fs_search_task.py"}
{"event": "Started search task", "dataset": "default", "task_id": 41, "query_job_type": "SEARCH_OR_AGGREGATION", "query": "*", "query_hash": "684888c0ebb17f374298b65ee2807526c066094c701bcc7ebbe1c1095f494fc1", "job_id": "4", "archive_id": "4431ab20-0b5a-4aa6-b102-a92c7a83bd96", "logger": "job_orchestration.executor.query.fs_search_task", "level": "info", "timestamp": "2026-07-10T22:09:51.164036Z", "func_name": "search_entry_point", "lineno": 266, "filename": "fs_search_task.py"}
{"event": "Waiting for search to finish", "query_hash": "6395fbecb81e23edb51cbd01542c571d636f5879eeb76a6894cd255c3e4f0783", "archive_id": "075d7338-9d9f-4f1e-86f5-e0fb63010e2e", "query_job_type": "SEARCH_OR_AGGREGATION", "dataset": "default", "job_id": "3", "query": "\"MapTask metrics system started\"", "task_id": 39, "logger": "job_orchestration.executor.query.fs_search_task", "level": "info", "timestamp": "2026-07-10T22:09:51.168518Z", "func_name": "run_query_task", "lineno": 92, "filename": "utils.py"}
  • Ran a successful extraction task
    • Query scheduler logs:
{"event": "Creating json extraction job on archive: 75e2226f-80b3-4a2f-b90d-55748ad69e7b", "job_id": "6", "query_job_type":
"EXTRACT_JSON", "logger": "search-job-handler", "level": "info", "timestamp": "2026-07-11T02:08:54.449800Z", "filename": "qu
ery_scheduler.py", "lineno": 346, "func_name": "create_stream_extraction_job"}
{"event": "Dispatched stream extraction job for archive: 75e2226f-80b3-4a2f-b90d-55748ad69e7b", "job_id": "6", "query_job_ty
pe": "EXTRACT_JSON", "logger": "search-job-handler", "level": "info", "timestamp": "2026-07-11T02:08:54.494076Z", "filename"
: "query_scheduler.py", "lineno": 1619, "func_name": "_handle_new_extraction_job"}
{"event": "Extraction task succeeded in 0.55007 second(s).", "job_id": "6", "task_id": 66, "query_job_type": "EXTRACT_JSON",
 "logger": "search-job-handler", "level": "info", "timestamp": "2026-07-11T02:08:55.107756Z", "filename": "query_scheduler.p
y", "lineno": 1092, "func_name": "handle_finished_stream_extraction_job"}
{"event": "Completed stream extraction job.", "job_id": "6", "query_job_type": "EXTRACT_JSON", "logger": "search-job-handler
", "level": "info", "timestamp": "2026-07-11T02:08:55.135333Z", "filename": "query_scheduler.py", "lineno": 1108, "func_name
": "handle_finished_stream_extraction_job"}
  • Query worker logs:
{"event": "Started Stream Extraction task", "archive_id": "75e2226f-80b3-4a2f-b90d-55748ad69e7b", "task_id": 66, "job_id": "6", "query_job_type": "EXTRACT_JSON", "dataset": "default", "logger": "job_orchestration.executor.query.extract_stream_task", "level": "info", "timestamp": "2026-07-11T02:08:54.491833Z", "func_name": "extract_stream_entry_point", "lineno": 221, "filename": "extract_stream_task.py"}
{"event": "Starting JSON extraction", "archive_id": "75e2226f-80b3-4a2f-b90d-55748ad69e7b", "task_id": 66, "job_id": "6", "query_job_type": "EXTRACT_JSON", "dataset": "default", "logger": "job_orchestration.executor.query.extract_stream_task", "level": "info", "timestamp": "2026-07-11T02:08:54.494984Z", "func_name": "_make_clp_s_command_and_env_vars", "lineno": 113, "filename": "extract_stream_task.py"}
{"event": "Running: /opt/clp/bin/clp-s x /var/data/archives/default /var/data/streams --archive-id 75e2226f-80b3-4a2f-b90d-55748ad69e7b --ordered --mongodb-uri mongodb://results_cache:27017/clp-query-results --mongodb-collection stream-files", "archive_id": "75e2226f-80b3-4a2f-b90d-55748ad69e7b", "task_id": 66, "job_id": "6", "query_job_type": "EXTRACT_JSON", "dataset": "default", "logger": "job_orchestration.executor.query.extract_stream_task", "level": "info", "timestamp": "2026-07-11T02:08:54.498669Z", "func_name": "run_query_task", "lineno": 67, "filename": "utils.py"}
{"event": "Waiting for Stream Extraction to finish", "archive_id": "75e2226f-80b3-4a2f-b90d-55748ad69e7b", "task_id": 66, "job_id": "6", "query_job_type": "EXTRACT_JSON", "dataset": "default", "logger": "job_orchestration.executor.query.extract_stream_task", "level": "info", "timestamp": "2026-07-11T02:08:54.505375Z", "func_name": "run_query_task", "lineno": 92, "filename": "utils.py"}
{"event": "Stream Extraction task completed", "archive_id": "75e2226f-80b3-4a2f-b90d-55748ad69e7b", "task_id": 66, "job_id": "6", "query_job_type": "EXTRACT_JSON", "dataset": "default", "logger": "job_orchestration.executor.query.extract_stream_task", "level": "info", "timestamp": "2026-07-11T02:08:55.041869Z", "func_name": "run_query_task", "lineno": 102, "filename": "utils.py"}

Summary by CodeRabbit

  • Improvements
    • Enhanced search and stream-extraction logging with consistent structured context (including job/task identifiers and query job type) for clearer tracking across scheduling and execution.
    • Added SHA-256 query hashing to strengthen monitoring without exposing full query text.
    • Standardized “started/completed/failure/timeout” log messages for more consistent, less noisy output.
  • Bug Fixes
    • Improved handling and logging for soft time limit interruptions and unexpected errors in search and stream extraction, while preserving existing error propagation.

@coderabbitai

coderabbitai Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: e16f2edb-c7d4-4139-93a8-5d90ea4d9ab0

📥 Commits

Reviewing files that changed from the base of the PR and between ce70100 and 551d36b.

📒 Files selected for processing (4)
  • components/job-orchestration/job_orchestration/executor/query/extract_stream_task.py
  • components/job-orchestration/job_orchestration/executor/query/fs_search_task.py
  • components/job-orchestration/job_orchestration/executor/query/utils.py
  • components/job-orchestration/job_orchestration/scheduler/query/query_scheduler.py

Walkthrough

Query task execution and scheduling now use structured context variables for identifiers and query metadata. Extraction task dispatch passes the query job type, while task, completion, failure, cancellation, validation, and stream-state log messages use simplified text.

Changes

Query task context and execution

Layer / File(s) Summary
Task context and execution logging
components/job-orchestration/job_orchestration/executor/query/extract_stream_task.py, components/job-orchestration/job_orchestration/executor/query/fs_search_task.py, components/job-orchestration/job_orchestration/executor/query/utils.py
Search and extraction tasks bind structured log context, including query metadata and hashes, and separately log soft time limits and unexpected exceptions before re-raising.
Scheduler context and dispatch wiring
components/job-orchestration/job_orchestration/scheduler/query/query_scheduler.py
The scheduler derives job context for dispatch and cancellation paths and passes query_job_type to extraction tasks.
Completion and failure handling
components/job-orchestration/job_orchestration/scheduler/query/query_scheduler.py
Completion, polling, metrics, counters, reducer handling, and status updates bind task or job context and revise lifecycle logging.
Validation and stream state logging
components/job-orchestration/job_orchestration/scheduler/query/query_scheduler.py
Validation and stream extraction state paths use updated generic messages for skipped, failed, running, extracted, and dispatched jobs.

Estimated code review effort: 4 (Complex) | ~45 minutes

Suggested reviewers: jackluo923

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 7.69% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarises the main change: adding logging context variables to query logs.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@rishikeshdevsot rishikeshdevsot changed the title Pr query log correlation feat(logging): add query job log correlation fields Jun 18, 2026
@rishikeshdevsot rishikeshdevsot changed the title feat(logging): add query job log correlation fields feat(logging): add query job log and task correlation fields Jun 18, 2026
@rishikeshdevsot rishikeshdevsot force-pushed the pr-query-log-correlation branch from a61bedd to 9ba21a9 Compare June 22, 2026 00:40
@rishikeshdevsot rishikeshdevsot changed the title feat(logging): add query job log and task correlation fields feat(logging)!: Add context variables to query logs. Jul 11, 2026
@rishikeshdevsot rishikeshdevsot force-pushed the pr-query-log-correlation branch from 9ba21a9 to edd5c7e Compare July 11, 2026 02:27
@rishikeshdevsot rishikeshdevsot marked this pull request as ready for review July 11, 2026 02:28
@rishikeshdevsot rishikeshdevsot requested a review from a team as a code owner July 11, 2026 02:28

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@components/job-orchestration/job_orchestration/executor/query/fs_search_task.py`:
- Around line 58-60: Deserialize the job configuration only once in the search
wrapper, then pass the resulting SearchJobConfig to both the context setup logic
and search_entry_point. Update the relevant function signatures and callers so
search_entry_point no longer invokes msgpack.unpackb or
SearchJobConfig.model_validate, while preserving context["query"] and
context["query_hash"] population from the shared config.
- Around line 340-344: Move the potentially failing _get_search_task_log_context
call inside the task’s existing try/except structure so malformed job
configuration errors are handled by the SoftTimeLimitExceeded/Exception
handlers. Bind only a minimal job_id/task_id context before the try, then enrich
the logging context after successful context construction while preserving the
existing handlers and cross-log fields.

In
`@components/job-orchestration/job_orchestration/scheduler/query/query_scheduler.py`:
- Around line 1152-1153: In the exception handling around
try_getting_task_result(), replace logger.error(f"Job failed: {e}.") with
logger.exception using the same failure context so unexpected failures retain
their traceback; keep the TimeoutError branch separate and unchanged because it
already logs upstream.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 33764b30-ba7d-4066-98ef-badb8b89c8ee

📥 Commits

Reviewing files that changed from the base of the PR and between 3c6ad26 and edd5c7e.

📒 Files selected for processing (4)
  • components/job-orchestration/job_orchestration/executor/query/extract_stream_task.py
  • components/job-orchestration/job_orchestration/executor/query/fs_search_task.py
  • components/job-orchestration/job_orchestration/executor/query/utils.py
  • components/job-orchestration/job_orchestration/scheduler/query/query_scheduler.py

Comment on lines +58 to +60
search_config = SearchJobConfig.model_validate(msgpack.unpackb(job_config_blob))
context["query"] = search_config.query_string
context["query_hash"] = get_query_hash(search_config.query_string)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Job config blob is deserialized twice per task.

SearchJobConfig.model_validate(msgpack.unpackb(job_config_blob)) is called here and again in search_entry_point at line 283. Consider deserializing once in the search wrapper and passing the SearchJobConfig to both the context helper and the entry point, eliminating the duplicate parse.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@components/job-orchestration/job_orchestration/executor/query/fs_search_task.py`
around lines 58 - 60, Deserialize the job configuration only once in the search
wrapper, then pass the resulting SearchJobConfig to both the context setup logic
and search_entry_point. Update the relevant function signatures and callers so
search_entry_point no longer invokes msgpack.unpackb or
SearchJobConfig.model_validate, while preserving context["query"] and
context["query_hash"] population from the shared config.

Comment on lines +340 to +344
with bound_contextvars(
**_get_search_task_log_context(
job_id, task_id, job_config_blob, archive_id, dataset
)
except SoftTimeLimitExceeded:
logger.exception(f"Search task job_id={job_id} task_id={task_id} exceeded soft time limit.")
raise
):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

Context setup exceptions bypass the task's error handlers.

_get_search_task_log_context deserializes and validates the job config blob (msgpack.unpackb + SearchJobConfig.model_validate), which can raise on a corrupted or malformed blob. Because this call is in the with expression — evaluated before the try block — any exception propagates uncaught by the SoftTimeLimitExceeded/Exception handlers below. The failure won't be logged with job_id/task_id context, undermining the PR's cross-log tracking goal.

Consider binding a minimal context first, then enriching inside the try:

🛡️ Proposed fix
 def search(
     self: Task,
     job_id: str,
     task_id: int,
     job_config_blob: bytes,
     archive_id: str,
     clp_metadata_db_conn_params: dict,
     results_cache_uri: str,
     dataset: str | None = None,
 ) -> dict[str, Any]:
-    with bound_contextvars(
-        **_get_search_task_log_context(
-            job_id, task_id, job_config_blob, archive_id, dataset
-        )
-    ):
-        try:
+    with bound_contextvars(job_id=job_id, task_id=task_id):
+        try:
+            with bound_contextvars(
+                **_get_search_task_log_context(
+                    job_id, task_id, job_config_blob, archive_id, dataset
+                )
+            ):
             return search_entry_point(
                 job_id,
                 task_id,
                 job_config_blob,
                 archive_id,
                 clp_metadata_db_conn_params,
                 results_cache_uri,
                 dataset,
             )
         except SoftTimeLimitExceeded:
             logger.exception("Search task exceeded soft time limit.")
             raise
         except Exception:
             logger.exception("Search task failed with an unexpected exception.")
             raise
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
with bound_contextvars(
**_get_search_task_log_context(
job_id, task_id, job_config_blob, archive_id, dataset
)
except SoftTimeLimitExceeded:
logger.exception(f"Search task job_id={job_id} task_id={task_id} exceeded soft time limit.")
raise
):
with bound_contextvars(job_id=job_id, task_id=task_id):
try:
with bound_contextvars(
**_get_search_task_log_context(
job_id, task_id, job_config_blob, archive_id, dataset
)
):
return search_entry_point(
job_id,
task_id,
job_config_blob,
archive_id,
clp_metadata_db_conn_params,
results_cache_uri,
dataset,
)
except SoftTimeLimitExceeded:
logger.exception("Search task exceeded soft time limit.")
raise
except Exception:
logger.exception("Search task failed with an unexpected exception.")
raise
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@components/job-orchestration/job_orchestration/executor/query/fs_search_task.py`
around lines 340 - 344, Move the potentially failing
_get_search_task_log_context call inside the task’s existing try/except
structure so malformed job configuration errors are handled by the
SoftTimeLimitExceeded/Exception handlers. Bind only a minimal job_id/task_id
context before the try, then enrich the logging context after successful context
construction while preserving the existing handlers and cross-log fields.

Comment on lines +1152 to +1153
except Exception as e:
logger.error(f"Job failed: {e}.")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

FILE="components/job-orchestration/job_orchestration/scheduler/query/query_scheduler.py"

echo "== around cited lines =="
sed -n '1120,1188p' "$FILE" | cat -n

echo
echo "== locate try_getting_task_result =="
rg -n "try_getting_task_result|TimeoutError|logger\.exception|logger\.error" "$FILE"

Repository: y-scope/clp

Length of output: 6066


🏁 Script executed:

#!/bin/bash
set -euo pipefail

FILE="components/job-orchestration/job_orchestration/scheduler/query/query_scheduler.py"

sed -n '938,1015p' "$FILE" | cat -n

Repository: y-scope/clp

Length of output: 3738


Preserve the traceback for unexpected job failures. logger.error(f"Job failed: {e}.") drops the stack trace for exceptions bubbling out of try_getting_task_result(). Switch this branch to logger.exception(...), but keep TimeoutError separate since that path already logs a traceback upstream.

🧰 Tools
🪛 Ruff (0.15.20)

[warning] 1152-1152: Do not catch blind exception: Exception

(BLE001)


[warning] 1153-1153: Use logging.exception instead of logging.error

Replace with exception

(TRY400)


[warning] 1153-1153: Logging statement uses f-string

(G004)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@components/job-orchestration/job_orchestration/scheduler/query/query_scheduler.py`
around lines 1152 - 1153, In the exception handling around
try_getting_task_result(), replace logger.error(f"Job failed: {e}.") with
logger.exception using the same failure context so unexpected failures retain
their traceback; keep the TimeoutError branch separate and unchanged because it
already logs upstream.

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.

1 participant