Skip to content

feat: optimize pipeline orchestration and thread execution in backend services#1

Open
linroger wants to merge 1 commit into
mainfrom
jules-14128648109808198039-6e72601b
Open

feat: optimize pipeline orchestration and thread execution in backend services#1
linroger wants to merge 1 commit into
mainfrom
jules-14128648109808198039-6e72601b

Conversation

@linroger

Copy link
Copy Markdown
Owner

This change introduces several performance and efficiency improvements across the backend services:

  1. ZepGraphMemoryUpdater:

    • Moved self._send_batch_activities(batch, platform) out of the with self._buffer_lock: block to prevent locking up the buffer across other threads.
    • Added logic to track last_flush_time so that if the queue throws an Empty exception and time since the last flush exceeds 5 seconds, it will flush the buffer even if the platform buffer size isn't exactly at BATCH_SIZE.
    • Updated MAX_RETRIES to use Config.ZEP_MAX_RETRIES rather than hardcoding it to 3.
  2. PipelineOrchestrator:

    • Replaced batch_size=10 with batch_size=20 inside add_text_batches for better ingestion performance.
    • Replaced time.sleep(5) in the _run loop with an event-based wait utilizing cancel_ev.wait(5), fetching the event securely first, so it doesn't block unresponsively and wakes up immediately if a cancellation occurs.
  3. OasisProfileGenerator:

    • Increased the max_workers in the ThreadPoolExecutor from 2 to 5 in _search_zep_for_entity to prevent extreme bottlenecks fetching edges/nodes context.
  4. LLM Client / Zep Tools Backoff limits:

    • Implemented a maximum limit to cap the exponential backoff inside time.sleep calls across llm_client.py and zep_tools.py so they don't lock unexpectedly for multiple minutes on repeated failures.

PR created automatically by Jules for task 14128648109808198039 started by @linroger

… services

Co-authored-by: linroger <136704361+linroger@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 10, 2026 10:02
@google-labs-jules

Copy link
Copy Markdown

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Copilot AI 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.

Pull request overview

This PR targets backend throughput and responsiveness by tuning batching, retry backoff, and thread orchestration in Zep- and pipeline-related services.

Changes:

  • Capped exponential backoff delays in LLM and Zep retry loops to avoid excessively long sleeps on repeated failures.
  • Improved ZepGraphMemoryUpdater concurrency by reducing lock hold time during sends and adding time-based flushing of partial batches.
  • Tuned pipeline graph ingestion batching and made the simulation polling loop cancellation-responsive via Event.wait().

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
backend/app/utils/llm_client.py Caps CLI retry backoff delay.
backend/app/services/zep_tools.py Caps retry delay growth in Zep tool calls.
backend/app/services/zep_graph_memory_updater.py Reduces lock contention and adds timed flushing for partial buffers; uses configured retry count.
backend/app/services/pipeline_orchestrator.py Increases graph ingestion batch size; makes polling loop responsive to cancellation events.
backend/app/services/oasis_profile_generator.py Changes ThreadPoolExecutor worker count during Zep edge/node search.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@@ -1136,7 +1136,7 @@ def add_cb(msg: str, ratio: float):

# batch_size 10:Zep graph.add 按 episode 异步处理,批量提交吞吐近似线性;
try:
# 并行执行edges和nodes搜索
with concurrent.futures.ThreadPoolExecutor(max_workers=2) as executor:
with concurrent.futures.ThreadPoolExecutor(max_workers=5) as executor:
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