Skip to content

perf(useLocalGitInfo): consolidate git probe into single bash round-trip#792

Merged
tofarr merged 3 commits into
mainfrom
fix/consolidate-git-info-command
May 27, 2026
Merged

perf(useLocalGitInfo): consolidate git probe into single bash round-trip#792
tofarr merged 3 commits into
mainfrom
fix/consolidate-git-info-command

Conversation

@tofarr
Copy link
Copy Markdown
Contributor

@tofarr tofarr commented May 26, 2026

Summary

Addresses the polling inefficiency noted in #776 by collapsing the 2–3 serial bash WebSocket round-trips that useLocalGitInfo issued on every 10-second tick into a single round-trip.

Changes

src/hooks/query/use-local-git-info.ts

Replaced probeGitInfoAtDir + probeNestedRepoInDir (which issued Promise.all of 2 bash calls, then conditionally a 3rd find + 2 more calls for nested repos) with:

  • GIT_INFO_COMMAND — a single multi-line shell script that handles both the root and nested-repo cases in one run() call. It outputs two newline-separated lines: <remote-url>\n<branch>.
  • probeGitInfo — a single replacement function that sends the script and splits the two-line output on the first \n.
  • queryFn — simplified from the old two-step conditional chain to return probeGitInfo(run, workingDir).

__tests__/hooks/query/use-local-git-info.test.tsx

Updated the “local backend” test to:

  • Mock one runCommandMock call returning "git@github.com:acme/widgets.git\nmain" (new two-line format)
  • Assert toHaveBeenCalledTimes(1) (was previously two chained mock calls)
  • Assert expect.stringContaining("git remote get-url origin") so the test confirms the git operations are still present without hard-coding the full script

Before / After

Scenario Round-trips before Round-trips after
Root is a git repo 2 (remote + branch in parallel) 1
Root is not git, 1 nested repo 3 (findremote + branch) 1
Root is not git, 0 or 2+ nested repos 1 (find only) 1

This PR was created by an AI agent (OpenHands) on behalf of the user.


🐳 Docker images for this PR

GHCR package: https://github.com/OpenHands/agent-canvas/pkgs/container/agent-canvas

Component Value
Image ghcr.io/openhands/agent-canvas
Architectures amd64, arm64
Agent Server ghcr.io/openhands/agent-server:1.23.1-python
Automation openhands-automation==1.0.0a5
Commit d92ca3ee7fa6e2e95606aa943eb476d97a8a22fc

Pull (multi-arch manifest)

# Multi-arch manifest — Docker automatically pulls the correct architecture
docker pull ghcr.io/openhands/agent-canvas:sha-d92ca3e

Run

docker run -it --rm \
  -p 8000:8000 \
  ghcr.io/openhands/agent-canvas:sha-d92ca3e

All tags pushed for this build

ghcr.io/openhands/agent-canvas:sha-d92ca3e-amd64
ghcr.io/openhands/agent-canvas:fix-consolidate-git-info-command-amd64
ghcr.io/openhands/agent-canvas:pr-792-amd64
ghcr.io/openhands/agent-canvas:sha-d92ca3e-arm64
ghcr.io/openhands/agent-canvas:fix-consolidate-git-info-command-arm64
ghcr.io/openhands/agent-canvas:pr-792-arm64
ghcr.io/openhands/agent-canvas:sha-d92ca3e
ghcr.io/openhands/agent-canvas:fix-consolidate-git-info-command
ghcr.io/openhands/agent-canvas:pr-792

About Multi-Architecture Support

  • Each tag (e.g., sha-d92ca3e) is a multi-arch manifest supporting both amd64 and arm64
  • Docker automatically pulls the correct architecture for your platform
  • Individual architecture tags (e.g., sha-d92ca3e-amd64) are also available if needed

Replace the former probeGitInfoAtDir + probeNestedRepoInDir pair (which
issued 2-3 serial bash WebSocket round-trips per poll cycle) with a single
GIT_INFO_COMMAND shell script that handles both the root and nested-repo
cases in one run() call.

The script outputs two newline-separated lines: <remote-url>\n<branch>.
The new probeGitInfo function runs the script and splits on the first
newline to recover the same LocalGitInfo struct as before.

Co-authored-by: openhands <openhands@all-hands.dev>
@vercel
Copy link
Copy Markdown

vercel Bot commented May 26, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
agent-canvas Ready Ready Preview, Comment May 27, 2026 12:48pm

Request Review

Copy link
Copy Markdown
Contributor

@all-hands-bot all-hands-bot left a comment

Choose a reason for hiding this comment

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

🟢 Good taste - Elegant solution to a real performance problem.

This PR consolidates 2-3 serial bash WebSocket round-trips into a single shell script, significantly improving polling efficiency. The implementation preserves the public API while optimizing internal execution. The shell script correctly handles both root and nested repo cases, and the parsing logic properly handles all edge cases (empty values, single values, both values present).

[RISK ASSESSMENT]

  • [Overall PR] ⚠️ Risk Assessment: 🟢 LOW

This is a well-scoped performance optimization that changes internal implementation without affecting the public API. The behavior remains identical, just more efficient. Tests have been updated to verify the single round-trip behavior, and the script properly handles edge cases like paths with spaces through correct variable quoting.

VERDICT:
Worth merging: Clean performance optimization addressing a real inefficiency (issue #776).

KEY INSIGHT:
Collapsing serial WebSocket calls into a single bash script demonstrates good pragmatism—solving real latency without adding architectural complexity.


Was this automated review useful? React with 👍 or 👎 to this review to help us measure review quality.
Workflow run: https://github.com/OpenHands/agent-canvas/actions/runs/26477651018

Co-authored-by: openhands <openhands@all-hands.dev>
@tofarr tofarr merged commit f64417d into main May 27, 2026
14 of 15 checks passed
@tofarr tofarr deleted the fix/consolidate-git-info-command branch May 27, 2026 13:16
@github-actions
Copy link
Copy Markdown
Contributor

📸 Snapshot Test Report

✅ No baseline found on main — all 1 snapshot are new and will become the baseline once this PR merges.

Category Count
🔴 Changed 0
🆕 New 1
✅ Unchanged 0
Total 1
🆕 New snapshots (1)

These snapshots have no baseline on main and will become the new baseline once this PR merges.

settings-page

add-backend-modal

new snapshot


Generated by the Snapshot Tests workflow. This comment was created by an AI agent (OpenHands) on behalf of the repo maintainers.

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