Skip to content

refactor: task handlers #355

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

Merged
merged 25 commits into from
Apr 15, 2025

Conversation

declark1
Copy link
Collaborator

@declark1 declark1 commented Mar 27, 2025

Major changes:

  • Implements new task handlers using reusable common tasks where possible
    • Reduces code duplication and lines of code for each implementation
    • Better organization, one file per handler
    • Simplified error handling, propagating Result<T, Error> through tasks
    • Added placeholder for chat completions streaming task handler (not yet implemented)
  • Drop all existing task handlers
  • Move task types to handler files
  • Update route handlers to call new task handlers

Other Changes:

  • Fix default thresholds for common detector tasks
  • Add apply_chunk_offset parameter and fix offsets for detect_text_contents task
  • Set detector_id in client helpers instead of tasks
  • Drop input_id from common detector tasks except text_contents_detections (not needed)
  • Drop Option from DetectorConfig fields to improve ergonomics
  • Add missing Detection / Detections conversions
  • Use buffer size 128 for mpsc and broadcast channels (reasonable default)
  • Add current_timestamp util function
  • Add Task struct (not yet used, will adopt in next PR as there are cleanups needed first for request types)
  • Update chat completions detections to return None instead of Some(ChatDetections { ..default }) when there are no detections, update test accordingly

@declark1 declark1 force-pushed the refactor_handlers branch 2 times, most recently from b9b6870 to 824824e Compare April 1, 2025 18:19
@declark1 declark1 force-pushed the refactor_handlers branch 4 times, most recently from 26c040a to 9807fb0 Compare April 7, 2025 18:20
@declark1 declark1 marked this pull request as ready for review April 7, 2025 19:24
Copy link
Collaborator

@evaline-ju evaline-ju left a comment

Choose a reason for hiding this comment

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

🎉 Nice, what a net negative diff! Couple of small comments and generally want to confirm:
(1) functional tests have been run against this change and still pass
(2) telemetry traces are expected [as noted separately]

@declark1
Copy link
Collaborator Author

declark1 commented Apr 8, 2025

🎉 Nice, what a net negative diff! Couple of small comments and generally want to confirm: (1) functional tests have been run against this change and still pass (2) telemetry traces are expected [as noted separately]

Thanks @evaline-ju. I'm working on addressing your comments inline and diving into the tracing issue, which will require some changes to fix. We do still need to run the functional tests, so it would be good if someone can help with this in the meantime while I work on the tracing, or it can wait until after that is resolved if you prefer.

@declark1 declark1 force-pushed the refactor_handlers branch from 855776f to e084c67 Compare April 8, 2025 18:36
declark1 and others added 17 commits April 8, 2025 11:37
…dlers, add DetectionWarning convenience methods

Signed-off-by: declark1 <[email protected]>
Signed-off-by: declark1 <[email protected]>
.
Signed-off-by: declark1 <[email protected]>
Signed-off-by: declark1 <[email protected]>
Signed-off-by: declark1 <[email protected]>
Signed-off-by: declark1 <[email protected]>
Signed-off-by: declark1 <[email protected]>
Signed-off-by: declark1 <[email protected]>
@declark1 declark1 force-pushed the refactor_handlers branch from e084c67 to 6b3915f Compare April 8, 2025 18:44
@declark1 declark1 force-pushed the refactor_handlers branch from 6b3915f to cb2cbca Compare April 8, 2025 18:49
@declark1 declark1 force-pushed the refactor_handlers branch from b3e195f to 8bda45e Compare April 8, 2025 20:22
declark1 added 3 commits April 9, 2025 12:44
…ethods, update conditional logic

Signed-off-by: declark1 <[email protected]>
Signed-off-by: declark1 <[email protected]>
@declark1
Copy link
Collaborator Author

I made some additional changes for tracing and this is now ready for final review. The primary issue was that span context was not being injected into spawned sub-tasks. A bug fix was also implemented to ensure proper handling of no detectors scenarios in (streaming)_classification_with_gen.

While testing tracing further locally with jaeger, I noticed that we were creating an excessive number of spans as essentially every function in the call stack was instrumented and creating a new span, rather than spans corresponding to a "unit of work". We were also instrumenting some functions that didn't need to be.

I did some limited cleanup to:

  1. Reduce the number of spans being created for each request
  2. Avoid logging essentially the same or redundant information at multiple layers
  3. Changed the default logging format from "full" to "compact"
  4. Reduced "incoming_orchestrator_http_request" being logged for every line from the parent span to "request"

There are opportunities for further enhancements, but we can address them later as this is out of the scope of this PR.

@declark1 declark1 requested review from evaline-ju and mdevino April 11, 2025 18:29
@declark1 declark1 force-pushed the refactor_handlers branch from 1d013f6 to eec8c3f Compare April 11, 2025 18:52
Copy link
Collaborator

@evaline-ju evaline-ju left a comment

Choose a reason for hiding this comment

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

LGTM - thanks for the updates!

@declark1 declark1 merged commit 3a78353 into foundation-model-stack:main Apr 15, 2025
2 checks passed
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.

3 participants