Skip to content

Fix inconsistent RepoManager base path in RepositoriesResource (Closes #640)#652

Open
arshadshaik0000 wants to merge 1 commit intopotpie-ai:mainfrom
arshadshaik0000:fix/unified-repo-manager-base-path
Open

Fix inconsistent RepoManager base path in RepositoriesResource (Closes #640)#652
arshadshaik0000 wants to merge 1 commit intopotpie-ai:mainfrom
arshadshaik0000:fix/unified-repo-manager-base-path

Conversation

@arshadshaik0000
Copy link
Copy Markdown

@arshadshaik0000 arshadshaik0000 commented Feb 25, 2026

RepositoriesResource initialized RepoManager without passing
RuntimeConfig.repos_base_path, causing worktree creation to use
a different repo directory than parsing/runtime flows.

This change wires repos_base_path into RepoManager initialization
so all runtime components use the same repository base path.

Closes #640

Summary by CodeRabbit

  • Bug Fixes
    • Improved repository base path configuration to ensure proper settings are applied from configuration files.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Feb 25, 2026

Walkthrough

RepoManager constructor signature was updated to accept a repos_base_path parameter. RepositoriesResource now passes the configured repos_base_path from RuntimeConfig when initializing RepoManager, ensuring consistent repository base directory usage across the runtime.

Changes

Cohort / File(s) Summary
RepoManager Configuration
app/modules/repo_manager, potpie/resources/repositories.py
Updated RepoManager constructor to accept repos_base_path parameter and modified RepositoriesResource to wire the configured base path during initialization, replacing parameterless constructor call.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A rabbit hops through paths now clear,
Where base repos were lost, they now appear!
Configuration flows like morning dew,
Same ground for all—old paths made new! 🌿

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title clearly and concisely summarizes the main change: fixing inconsistent RepoManager base path in RepositoriesResource and references the closed issue.
Linked Issues check ✅ Passed The code changes directly address all objectives from issue #640: wiring repos_base_path into RepoManager initialization to ensure consistent base path usage across runtime components.
Out of Scope Changes check ✅ Passed All changes in the PR are directly related to fixing the inconsistent RepoManager base path issue; no out-of-scope modifications are present.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sonarqubecloud
Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
D Maintainability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
potpie/resources/repositories.py (1)

120-123: ⚠️ Potential issue | 🟠 Major

Expose _get_repo_local_path as a public method or avoid the private API access.

The fallback accesses RepoManager._get_repo_local_path(), a private method with no public equivalent in IRepoManager. If this method is renamed or its return type changes, the fallback will silently fail or raise AttributeError (which may be swallowed by exception handlers). Either add a public method to IRepoManager for this lookup (this method is legitimately needed by sync_helper.py and parsing_helper.py as well), or drop this fallback and return None (the two rm.get_repo_path(...) calls above already handle the primary use cases).

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@potpie/resources/repositories.py` around lines 120 - 123, The fallback is
calling the private RepoManager._get_repo_local_path(repo_name); either add a
public accessor on IRepoManager (e.g., get_repo_local_path or repo_local_path)
and replace rm._get_repo_local_path(...) with rm.get_repo_local_path(repo_name)
(also update callers in sync_helper.py and parsing_helper.py), or remove the
fallback entirely and return None so we rely on the existing
rm.get_repo_path(...) semantics; ensure the chosen public method
signature/return type matches other usages and update interface and
implementations accordingly.
🧹 Nitpick comments (3)
potpie/resources/repositories.py (3)

48-72: _get_repo_manager re-evaluates the env var on every call when disabled.

self._repo_manager is only cached on successful initialization. When REPO_MANAGER_ENABLED is false (or initialization fails), the env var is parsed from scratch on every create_worktree call.

♻️ Cache the disabled state with a sentinel
+_REPO_MANAGER_DISABLED = object()  # sentinel

 def _get_repo_manager(self):
     """Get RepoManager instance if enabled."""
-    if self._repo_manager is not None:
+    if self._repo_manager is _REPO_MANAGER_DISABLED:
+        return None
+    if self._repo_manager is not None:
         return self._repo_manager
     enabled = os.getenv("REPO_MANAGER_ENABLED", "false").lower() in (
         "true", "1", "yes", "y",
     )
     if not enabled:
+        self._repo_manager = _REPO_MANAGER_DISABLED
         return None
     try:
         from app.modules.repo_manager import RepoManager
         self._repo_manager = RepoManager(
             repos_base_path=self._config.repos_base_path
         )
         logger.info("RepositoriesResource: RepoManager initialized")
         return self._repo_manager
     except Exception as e:
         logger.warning(
             "RepositoriesResource: Failed to initialize RepoManager: %s", e
         )
+        self._repo_manager = _REPO_MANAGER_DISABLED
         return None
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@potpie/resources/repositories.py` around lines 48 - 72, The _get_repo_manager
currently re-parses REPO_MANAGER_ENABLED every call because self._repo_manager
is only set on success; change it to cache a disabled sentinel so disabled or
failed initialization is remembered: set self._repo_manager to a sentinel value
(e.g., False or a dedicated object) when enabled is false or when initialization
fails, and update callers (e.g., create_worktree) to treat that sentinel as
"disabled" and return None without re-checking the env var; keep successful
initialization storing the RepoManager instance in self._repo_manager as before.

257-258: Replace asyncio.get_event_loop() with asyncio.get_running_loop() inside a coroutine.

asyncio.get_event_loop() when called from a coroutine returns the running event loop, so this doesn't break today. However, asyncio.get_event_loop() is deprecated since Python 3.10 when called without a running loop, and is planned to become an alias for get_running_loop() in the future. Since create_worktree is async, asyncio.get_running_loop() is the semantically correct and forward-compatible replacement.

♻️ Proposed fix
-                loop = asyncio.get_event_loop()
+                loop = asyncio.get_running_loop()
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@potpie/resources/repositories.py` around lines 257 - 258, In the async
function create_worktree replace the deprecated call asyncio.get_event_loop()
with asyncio.get_running_loop() before calling loop.run_in_executor so the
coroutine obtains the current running loop; update the symbol usage in the
create_worktree function (where loop is used with run_in_executor to compute
path) to call asyncio.get_running_loop() instead of asyncio.get_event_loop().

109-113: Extract the repeated commit-SHA heuristic into a helper.

The pattern len(ref) >= 7 and all(c in "0123456789abcdefABCDEF" for c in ref[:7]) appears identically at lines 109–113, 180–182, and 269–271. A single module-level helper removes the duplication and makes future refinements (e.g., checking full SHA length) a one-line change.

♻️ Proposed refactor
+def _is_commit_sha(ref: str) -> bool:
+    """Heuristic: treat ref as a commit SHA if its first 7 chars are all hex digits."""
+    return len(ref) >= 7 and all(c in "0123456789abcdefABCDEF" for c in ref[:7])
+
+
 class RepositoriesResource(BaseResource):
     ...

Then replace each inline occurrence:

-        is_commit = len(ref) >= 7 and all(
-            c in "0123456789abcdefABCDEF" for c in ref[:7]
-        )
+        is_commit = _is_commit_sha(ref)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@potpie/resources/repositories.py` around lines 109 - 113, Extract the
repeated SHA-guessing logic into a single module-level helper (e.g.,
is_commit_sha(ref) or looks_like_commit_sha) that returns the boolean result of
the existing heuristic, then replace each inline occurrence that sets is_commit
(the expressions in the blocks that compute `is_commit = len(ref) >= 7 and all(c
in "0123456789abcdefABCDEF" for c in ref[:7])`) with a call to that helper and
adjust subsequent uses of branch/commit_id accordingly; update all three places
where that exact expression appears so future changes to the heuristic are made
in one location.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@potpie/resources/repositories.py`:
- Around line 120-123: The fallback is calling the private
RepoManager._get_repo_local_path(repo_name); either add a public accessor on
IRepoManager (e.g., get_repo_local_path or repo_local_path) and replace
rm._get_repo_local_path(...) with rm.get_repo_local_path(repo_name) (also update
callers in sync_helper.py and parsing_helper.py), or remove the fallback
entirely and return None so we rely on the existing rm.get_repo_path(...)
semantics; ensure the chosen public method signature/return type matches other
usages and update interface and implementations accordingly.

---

Nitpick comments:
In `@potpie/resources/repositories.py`:
- Around line 48-72: The _get_repo_manager currently re-parses
REPO_MANAGER_ENABLED every call because self._repo_manager is only set on
success; change it to cache a disabled sentinel so disabled or failed
initialization is remembered: set self._repo_manager to a sentinel value (e.g.,
False or a dedicated object) when enabled is false or when initialization fails,
and update callers (e.g., create_worktree) to treat that sentinel as "disabled"
and return None without re-checking the env var; keep successful initialization
storing the RepoManager instance in self._repo_manager as before.
- Around line 257-258: In the async function create_worktree replace the
deprecated call asyncio.get_event_loop() with asyncio.get_running_loop() before
calling loop.run_in_executor so the coroutine obtains the current running loop;
update the symbol usage in the create_worktree function (where loop is used with
run_in_executor to compute path) to call asyncio.get_running_loop() instead of
asyncio.get_event_loop().
- Around line 109-113: Extract the repeated SHA-guessing logic into a single
module-level helper (e.g., is_commit_sha(ref) or looks_like_commit_sha) that
returns the boolean result of the existing heuristic, then replace each inline
occurrence that sets is_commit (the expressions in the blocks that compute
`is_commit = len(ref) >= 7 and all(c in "0123456789abcdefABCDEF" for c in
ref[:7])`) with a call to that helper and adjust subsequent uses of
branch/commit_id accordingly; update all three places where that exact
expression appears so future changes to the heuristic are made in one location.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f0711ea and ce11d6c.

📒 Files selected for processing (1)
  • potpie/resources/repositories.py

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.

[Bug]: RepositoriesResource uses RepoManager with inconsistent base path (ignores RuntimeConfig.repos_base_path)

2 participants