Skip to content

feat: enhance Repo-Agent capabilities by codebase#29

Merged
iohub merged 2 commits into
mainfrom
feat-0505
May 4, 2026
Merged

feat: enhance Repo-Agent capabilities by codebase#29
iohub merged 2 commits into
mainfrom
feat-0505

Conversation

@iohub
Copy link
Copy Markdown
Owner

@iohub iohub commented May 4, 2026

Summary by Sourcery

Introduce robust HTTP retry handling and health checks for codebase service interactions and clarify Repo-Agent’s role and capabilities in the multi-agent conductor prompt.

Enhancements:

  • Refactor repo operations to use a shared HTTP helper with retry logic for semantic search and code query endpoints.
  • Add retry-based pre-investigation HTTP flow in Repo-Agent with stronger error handling.
  • Add startup health check for the external codebase server, failing fast if it does not become healthy.
  • Clarify and expand conductor prompt guidance around Repo-Agent’s semantic code tools and when to delegate repository analysis.

iohub and others added 2 commits May 4, 2026 13:47
- startCodebaseServer启动后轮询/health最多30s,未就绪则kill进程
- repo_operations.go提取doCodebaseRequest辅助函数,3次重试(500ms退避)
- RepoAgent.doPreInvestigate添加3次重试
- 删除task_executor.go中废弃的codebase_init注释代码

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Expand Repo-Agent description to include codebase semantic tools
  (semantic_search, query_code_skeleton, query_code_snippet)
- Add guidance for Phase 1 context gathering to leverage semantic search
- Strengthen rule 5: make Repo-Agent the primary agent for all repo
  exploration, demoting Conductor's own file tools to fallback-only
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented May 4, 2026

Reviewer's Guide

Adds reusable HTTP+retry helpers for the codebase service, applies them across RepoOperationsTool and RepoAgent, introduces health checking for the codebase server startup, and strengthens Conductor/Repo-Agent documentation to prioritize semantic codebase tools while cleaning up unused code.

Sequence diagram for RepoOperationsTool.doCodebaseRequest with retry logic

sequenceDiagram
    participant Caller as RepoOperationsTool_method
    participant RepoOperationsTool
    participant HTTPClient as http_Client
    participant CodebaseService

    Caller->>RepoOperationsTool: doCodebaseRequest(endpoint, body)
    RepoOperationsTool->>RepoOperationsTool: json.Marshal(body)
    alt marshal fails
        RepoOperationsTool-->>Caller: error
    else marshal ok
        loop up to 3 attempts
            RepoOperationsTool->>RepoOperationsTool: build URL CodebaseURL+endpoint
            RepoOperationsTool->>HTTPClient: http.NewRequest(POST, URL, bodyBytes)
            alt request creation fails
                RepoOperationsTool-->>Caller: error
            else request ok
                HTTPClient->>CodebaseService: POST endpoint
                alt network error
                    HTTPClient-->>RepoOperationsTool: error
                    RepoOperationsTool->>RepoOperationsTool: lastErr = send error
                else response received
                    CodebaseService-->>HTTPClient: HTTP response
                    HTTPClient-->>RepoOperationsTool: response
                    RepoOperationsTool->>RepoOperationsTool: io.ReadAll(resp.Body)
                    alt read error
                        RepoOperationsTool->>RepoOperationsTool: lastErr = read error
                    else body ok
                        alt status != 200
                            RepoOperationsTool->>RepoOperationsTool: lastErr = status error
                        else status == 200
                            RepoOperationsTool-->>Caller: response body
                        end
                    end
                end
                opt need another attempt
                    RepoOperationsTool->>RepoOperationsTool: sleep(backoff)
                end
            end
        end
        alt all attempts failed
            RepoOperationsTool-->>Caller: error with lastErr
        end
    end
Loading

Sequence diagram for startCodebaseServer and waitForCodebase health checks

sequenceDiagram
    actor User
    participant MainProcess
    participant CodebaseServer as codeactor_codebase
    participant HealthClient as nethttp_Client

    User->>MainProcess: startCodebaseServer(port, repoPath)
    MainProcess->>MainProcess: build command and args
    MainProcess->>CodebaseServer: start process
    CodebaseServer-->>MainProcess: pid
    MainProcess->>MainProcess: waitForCodebase(address, timeout)

    MainProcess->>HealthClient: GET http://address/health
    loop until timeout or healthy
        alt network error
            HealthClient-->>MainProcess: error
            MainProcess->>MainProcess: lastErr = error
            MainProcess->>MainProcess: sleep(500ms)
            MainProcess->>HealthClient: GET /health
        else response received
            HealthClient-->>MainProcess: response
            alt status == 200
                MainProcess->>MainProcess: log healthy
                MainProcess-->>User: cmd (ready)
            else status != 200
                MainProcess->>MainProcess: lastErr = status error
                MainProcess->>MainProcess: sleep(500ms)
                MainProcess->>HealthClient: GET /health
            end
        end
    end
    alt deadline exceeded and not healthy
        MainProcess-->>User: error
        MainProcess->>CodebaseServer: kill process
    end
Loading

Class diagram for RepoOperationsTool and RepoAgent retry-enabled HTTP interactions

classDiagram
    class RepoOperationsTool {
        string CodebaseURL
        string ProjectPath
        NewRepoOperationsTool(codebaseURL string, projectPath string) RepoOperationsTool
        doCodebaseRequest(endpoint string, body interface_any) []byte
        ExecuteSemanticSearch(ctx context_Context, params map_string_interface) (interface, error)
        ExecuteQueryCodeSkeleton(ctx context_Context, params map_string_interface) (interface, error)
        ExecuteQueryCodeSnippet(ctx context_Context, params map_string_interface) (interface, error)
    }

    class RepoAgent {
        GlobalCtx globalctx_GlobalContext
        TaskManagerPtr *TaskManager
        Name() string
        doPreInvestigate(projectDir string) (*PreInvestigateResponse, error)
        Run(ctx context_Context, input string) (string, error)
    }

    class PreInvestigateResponse {
        bool Success
        string Message
        string OtherFields_information
    }

    RepoAgent --> PreInvestigateResponse : uses

    class CodebaseServiceEndpoints {
        investigate_repo
        semantic_search
        query_code_skeleton
        query_code_snippet
    }

    RepoOperationsTool --> CodebaseServiceEndpoints : HTTP POST with retry
    RepoAgent --> CodebaseServiceEndpoints : HTTP POST with retry

    class MainProcess {
        startCodebaseServer(port int, repoPath string) *exec_Cmd
        waitForCodebase(address string, timeout time_Duration) error
    }

    MainProcess --> CodebaseServiceEndpoints : manages lifecycle and health
Loading

File-Level Changes

Change Details Files
Introduce a shared HTTP POST helper with retry logic for codebase operations and refactor RepoOperationsTool methods to use it.
  • Add doCodebaseRequest method to RepoOperationsTool that marshals request bodies, performs POSTs with up to three retries and exponential-ish backoff, and returns raw response bytes on success.
  • Refactor ExecuteSemanticSearch to delegate HTTP transport and error handling to doCodebaseRequest, simplifying it to JSON (un)marshalling and fallback-to-string behavior.
  • Refactor ExecuteQueryCodeSkeleton to use doCodebaseRequest and keep only request shaping, response unmarshalling, and success flag validation in the method.
  • Refactor ExecuteQueryCodeSnippet similarly to use doCodebaseRequest and centralize HTTP handling while retaining success checks.
internal/tools/repo_operations.go
Add retrying pre-investigation HTTP logic to RepoAgent with better error handling and success checks.
  • Replace the single-shot HTTP POST in RepoAgent.doPreInvestigate with a loop that retries up to three times with incremental sleep delays.
  • Use bytes readers instead of strings for JSON request payloads and ensure response bodies are always closed.
  • Validate both HTTP 200 status and PreInvestigateResponse.Success before returning; propagate detailed error messages otherwise.
  • Add time-based backoff using time.Sleep and import time (and bytes) accordingly.
internal/agents/repo.go
Remove unused, commented-out codebase_init background initialization logic from task execution.
  • Delete the commented goroutine that POSTed to /codebase_init in ExecuteTask, simplifying task startup.
  • Leave ExecuteTask focused on task context handling without unused HTTP initialization paths.
internal/http/task_executor.go
Ensure the embedded codebase server is healthy before use by polling a health endpoint with timeout.
  • Extend startCodebaseServer to wait for the codebase server to become healthy by calling a new waitForCodebase helper after start.
  • Implement waitForCodebase to poll the /health endpoint until it receives HTTP 200 or a configurable timeout elapses, with small request timeouts and backoff between attempts.
  • Kill the codebase server process and return nil from startCodebaseServer if the health check never succeeds, logging appropriate errors.
  • Alias net/http as nethttp to avoid import conflicts and use it for the health check client.
main.go
Update Conductor prompt to position Repo-Agent as the primary codebase understanding agent with explicit semantic tool guidance and de-emphasize raw file tools.
  • Expand Repo-Agent description to enumerate its semantic tools (semantic_search, query_code_skeleton, query_code_snippet) and preferred usage scenarios.
  • Clarify phase 1 guidance that Repo-Agent has powerful semantic tools and should be used conceptually rather than via direct file reads.
  • Strengthen the delegation rule to mark Conductor file tools as low-priority fallbacks and mandate delegating repo exploration to Repo-Agent unless unavailable.
  • Adjust instructions to highlight that Conductor should not use its own read_file/search_by_regex for repo exploration when Repo-Agent is available.
internal/agents/conductor.prompt.md

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@iohub iohub merged commit 56068f6 into main May 4, 2026
1 check passed
Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • In both doCodebaseRequest and RepoAgent.doPreInvestigate, the context.Context passed into the public methods is ignored—consider using http.NewRequestWithContext and/or a shared http.Client with timeouts so callers can cancel or bound these network operations.
  • internal/agents/repo.go now uses bytes.NewReader(jsonData) but the bytes package is not imported (you only replaced strings with time), which will cause a compile error—add the bytes import or adjust the request body creation.
  • The retry logic for HTTP POSTs is now implemented separately in doCodebaseRequest and RepoAgent.doPreInvestigate; consider extracting a shared helper or reusing doCodebaseRequest for investigate_repo to avoid divergence in backoff behavior and error handling.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In both `doCodebaseRequest` and `RepoAgent.doPreInvestigate`, the `context.Context` passed into the public methods is ignored—consider using `http.NewRequestWithContext` and/or a shared `http.Client` with timeouts so callers can cancel or bound these network operations.
- `internal/agents/repo.go` now uses `bytes.NewReader(jsonData)` but the `bytes` package is not imported (you only replaced `strings` with `time`), which will cause a compile error—add the `bytes` import or adjust the request body creation.
- The retry logic for HTTP POSTs is now implemented separately in `doCodebaseRequest` and `RepoAgent.doPreInvestigate`; consider extracting a shared helper or reusing `doCodebaseRequest` for `investigate_repo` to avoid divergence in backoff behavior and error handling.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

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