Skip to content

fix(docker): normalize bare repo name in git changes API path - #59

Merged
zxkane merged 7 commits into
mainfrom
fix/git-changes-repo-name
Mar 10, 2026
Merged

fix(docker): normalize bare repo name in git changes API path#59
zxkane merged 7 commits into
mainfrom
fix/git-changes-repo-name

Conversation

@zxkane

@zxkane zxkane commented Mar 9, 2026

Copy link
Copy Markdown
Owner

Summary

Fix git Changes tab 500 errors when a GitHub repo is connected to a conversation. Both the changes list API and the file diff API were broken because patch-fix.js didn't properly normalize workspace paths containing the repo directory name.

Root Cause

When a GitHub repo is connected via selected_repository, the frontend sends absolute paths to the git API:

API Frontend sends Agent-server expects
Changes %2Fworkspace%2Fproject%2Fopenhands-infra . (workspace root)
Diff %2Fworkspace%2Fproject%2Fopenhands-infra%2F.gitignore .gitignore

Without normalization, the agent-server looks for wrong paths (/workspace/openhands-infra or /workspace/openhands-infra/project/openhands-infra) and returns HTTP 500.

Fix

The normalizeGitUrl() function in patch-fix.js now handles all path forms:

  1. URL-encoded workspace+repo prefix (%2Fworkspace%2Fproject%2F<repo>) β€” strips prefix, keeps file path or returns .
  2. Non-encoded workspace+repo prefix (//workspace/project/<repo>) β€” same treatment
  3. Bare repo name (openhands-infra) β€” rewrites to .
  4. Bare repo+file (openhands-infra%2F.gitignore) β€” extracts file path

The bare-name catch-all is guarded by if (url === before) to avoid clobbering valid file paths already extracted by workspace stripping.

Test plan

  • Build passes (npm run build)
  • Unit tests pass (npm run test) β€” 19 regression tests for all path patterns
  • CI checks pass (all 4 checks green)
  • Deployed to staging
  • Verified on actual bug conversation (908266872b374b039fb60bdb4236f36d)
    • Changes API: %2Fworkspace%2Fproject%2Fopenhands-infra β†’ /api/git/changes/. β†’ 200
    • Diff API: %2Fworkspace%2Fproject%2Fopenhands-infra%2F.gitignore β†’ /api/git/diff/.gitignore β†’ 200
    • Changes tab loads with file list and expandable diffs (screenshot verified)

Checklist

  • Regression tests (19 tests in docker/test_patch_fix_git_paths.js)
  • E2E test cases updated (TC-030, TC-031 in test/E2E_TEST_CASES.md)
  • Test selector updated (test/select-e2e-tests.sh)

@amazon-q-developer amazon-q-developer Bot 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.

The fix correctly addresses the 500 error when the frontend sends bare GitHub repo names instead of . for the workspace root. The implementation extracts a shared normalizeGitUrl() function with proper fallback logic and includes comprehensive test coverage (10 test cases). The regex patterns correctly handle URL-encoded paths, non-encoded paths, and bare repo names in the right priority order. No defects found that block merge.


You can now have the agent implement changes and create commits directly on your pull request's source branch. Simply comment with /q followed by your request in natural language to ask the agent to make changes.

@github-actions

github-actions Bot commented Mar 9, 2026

Copy link
Copy Markdown
Contributor

πŸ”’ Security Scan Results

Status: 🟑 HIGH ISSUES - Review required!

Summary

  • Critical Issues: 0
  • High Issues: 0
  • Medium Issues: 0
  • Low Issues: 0

NPM Vulnerabilities

  • Critical: 0
  • High: 2

Security Score: N/A/10

Please run ./security-check.sh locally for detailed findings.

πŸ“‹ View detailed reports

@github-actions

github-actions Bot commented Mar 9, 2026

Copy link
Copy Markdown
Contributor

πŸ”’ Security Scan Results

Status: 🟑 HIGH ISSUES - Review required!

Summary

  • Critical Issues: 0
  • High Issues: 0
  • Medium Issues: 0
  • Low Issues: 0

NPM Vulnerabilities

  • Critical: 0
  • High: 2

Security Score: N/A/10

Please run ./security-check.sh locally for detailed findings.

πŸ“‹ View detailed reports

@github-actions

github-actions Bot commented Mar 9, 2026

Copy link
Copy Markdown
Contributor

πŸ”’ Security Scan Results

Status: 🟑 HIGH ISSUES - Review required!

Summary

  • Critical Issues: 0
  • High Issues: 0
  • Medium Issues: 0
  • Low Issues: 0

NPM Vulnerabilities

  • Critical: 0
  • High: 2

Security Score: N/A/10

Please run ./security-check.sh locally for detailed findings.

πŸ“‹ View detailed reports

@github-actions

github-actions Bot commented Mar 9, 2026

Copy link
Copy Markdown
Contributor

πŸ”’ Security Scan Results

Status: 🟑 HIGH ISSUES - Review required!

Summary

  • Critical Issues: 0
  • High Issues: 0
  • Medium Issues: 0
  • Low Issues: 0

NPM Vulnerabilities

  • Critical: 0
  • High: 2

Security Score: N/A/10

Please run ./security-check.sh locally for detailed findings.

πŸ“‹ View detailed reports

@github-actions

github-actions Bot commented Mar 9, 2026

Copy link
Copy Markdown
Contributor

πŸ”’ Security Scan Results

Status: 🟑 HIGH ISSUES - Review required!

Summary

  • Critical Issues: 0
  • High Issues: 0
  • Medium Issues: 0
  • Low Issues: 0

NPM Vulnerabilities

  • Critical: 0
  • High: 2

Security Score: N/A/10

Please run ./security-check.sh locally for detailed findings.

πŸ“‹ View detailed reports

@github-actions

github-actions Bot commented Mar 9, 2026

Copy link
Copy Markdown
Contributor

πŸ”’ Security Scan Results

Status: 🟑 HIGH ISSUES - Review required!

Summary

  • Critical Issues: 0
  • High Issues: 0
  • Medium Issues: 0
  • Low Issues: 0

NPM Vulnerabilities

  • Critical: 0
  • High: 2

Security Score: N/A/10

Please run ./security-check.sh locally for detailed findings.

πŸ“‹ View detailed reports

@github-actions

github-actions Bot commented Mar 9, 2026

Copy link
Copy Markdown
Contributor

πŸ”’ Security Scan Results

Status: 🟑 HIGH ISSUES - Review required!

Summary

  • Critical Issues: 0
  • High Issues: 0
  • Medium Issues: 0
  • Low Issues: 0

NPM Vulnerabilities

  • Critical: 0
  • High: 2

Security Score: N/A/10

Please run ./security-check.sh locally for detailed findings.

πŸ“‹ View detailed reports

zxkane added 7 commits March 9, 2026 23:03
The frontend sends the GitHub repo name (e.g., "openhands-infra") in
/api/git/changes/<repo-name>, but the agent-server expects "." for the
workspace root since repos are cloned at /workspace/project.

Extract shared normalizeGitUrl() function in patch-fix.js that handles:
- Bare repo names β†’ "." (the new fix)
- URL-encoded /workspace/project paths β†’ "."
- Non-encoded //workspace/project paths β†’ "."
- Subdirectory paths β†’ relative path

Add regression test with 10 cases covering all path formats.
The previous snapshot was generated with a stale Docker build context.
Regenerate to match the current patch-fix.js content hash.
TC-030: Verify Changes tab works for conversations without a GitHub
repo connected (no-repo scenario).

TC-031: Regression test for the bare repo name bug β€” verifies the
Changes tab works when a GitHub repo is connected and the frontend
sends the repo name instead of "." in /api/git/changes/ path.

Also update select-e2e-tests.sh to include both TCs in RUNTIME_TESTS
category (triggered by docker/ changes).
…tion

The bare repo name bug only triggers when a conversation has a GitHub
repo connected via the OpenHands integration. Manual git clone inside
the sandbox does not set the repo in conversation metadata, so the
frontend won't send the repo name in the git changes API path.
TC-031 no longer requires GitHub integration. Instead, it verifies the
normalizeGitUrl() interceptor by calling fetch() with a bare repo name
from the browser console of any running conversation. This was validated
on staging β€” console logs confirm the rewrite works correctly.

Also documents the alternative full-flow approach using
POST /api/v1/app-conversations with selected_repository for public repos.
The previous fix only handled bare repo names sent directly by the
frontend. The actual bug path is: frontend sends URL-encoded
%2Fworkspace%2Fproject%2F<repo-name>, the workspace prefix stripping
regex removes %2Fworkspace%2Fproject%2F leaving just <repo-name>,
but the bare name catch-all was guarded by `if (url === before)` and
skipped since the URL had already been modified.

Fix: Remove the guard and restructure the regexes so that:
1. Workspace root + single trailing segment (repo name) -> "."
2. Workspace root + multi-segment sub-path -> preserved
3. Bare repo name (no workspace prefix) -> "."

Add 3 new regression tests for the exact bug path observed in
production (URL-encoded workspace path with repo directory name).
The diff API receives paths like %2Fworkspace%2Fproject%2Frepo%2Ffile
which need the workspace+repo prefix stripped to leave just the file
path. Previously only the changes API was handled (repo name -> ".").

The normalizeGitUrl function now:
1. Strips workspace+repo prefix from URL-encoded paths, keeping file
2. Strips workspace+repo prefix from non-encoded paths, keeping file
3. For bare repo%2Ffile paths, extracts file after first %2F
4. For bare repo name only, rewrites to "."

The bare-name catch-all is guarded by if(url===before) to avoid
clobbering valid file paths produced by workspace stripping.

Adds 19 regression tests covering changes and diff API patterns.
Updates TC-031 E2E test case to cover diff API verification.
@zxkane
zxkane force-pushed the fix/git-changes-repo-name branch from 32421a4 to a79b3fa Compare March 9, 2026 15:03
@github-actions

github-actions Bot commented Mar 9, 2026

Copy link
Copy Markdown
Contributor

πŸ”’ Security Scan Results

Status: 🟑 HIGH ISSUES - Review required!

Summary

  • Critical Issues: 0
  • High Issues: 0
  • Medium Issues: 0
  • Low Issues: 0

NPM Vulnerabilities

  • Critical: 0
  • High: 2

Security Score: N/A/10

Please run ./security-check.sh locally for detailed findings.

πŸ“‹ View detailed reports

@zxkane
zxkane merged commit 6a0ace5 into main Mar 10, 2026
4 checks passed
@zxkane
zxkane deleted the fix/git-changes-repo-name branch March 10, 2026 03:43
@kanerelease kanerelease Bot mentioned this pull request Mar 11, 2026
zxkane pushed a commit that referenced this pull request Mar 11, 2026
## [1.2.0] - 2026-03-11

### Added

#### Sandboxes
- **Startup timing instrumentation and SOCI support** (#58)
- Added structured timing logs (`sandbox-startup-timing`) to benchmark
sandbox startup phases in `/start` and `/resume` routes.
- Integrated SOCI v2 index generation via `soci convert` for Fargate
lazy image loading (requires `soci` CLI >= v0.10).
- Introduced `sandboxSociImageUri` CDK context parameter for
SOCI-enabled sandbox image override.
- Exported sandbox image ECR URI as `CfnOutput` for SOCI index
generation scripts.

### Changed

#### Documentation
- **Improved README for discoverability and engagement** (#60)
- Restructured README to include a hero section, badges, and explicit
value propositions.
- Transformed features list into an emoji-tagged Key Features section
for easier scanning.
- Enhanced comparison tables and quick links for first-time visitor
comprehension.

### Fixed

#### Docker
- **Correct VS Code port mapping from 60001 to 8001** (#62)
- Resolved 502 runtime subdomain errors caused by incorrect port mapping
(`60001` β†’ `8001`) in `patch-exposed-urls.py`.
- Fixed `can_connect(ip, 60001)` requests that failed to establish
upstream connections due to mismatched port configurations in the
agent-server SDK.

- **Preserve project/<repo> path for nested repo git changes** (#61)
- Corrected empty Changes tab for conversations linked to GitHub
repositories.
- Updated `normalizeGitUrl()` to preserve `project/<repo>` paths for
accurate nested repo resolution.
- Removed unnecessary intermediate `git init /workspace/project` repo
creation shadowing actual repo changes.

- **Normalize git API paths for connected repos** (#59)
- Fixed 500 errors in git Changes tab when connecting GitHub
repositories to conversations.
- Adjusted `patch-fix.js` to properly normalize workspace paths
containing nested repo directories.

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
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