Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
b4587c7
Add repository working status management and update handling
dcloud347 Aug 8, 2025
efd12df
Reduce default recursion limit in issue_not_verified_bug_subgraph.py
dcloud347 Aug 8, 2025
a3310a6
Integrate repository service into issue processing and update status …
dcloud347 Aug 8, 2025
599f9f8
Make create_and_push_branch and answer_issue methods asynchronous
dcloud347 Aug 8, 2025
ff9d548
Refactor context extraction to skip empty content and ensure uniqueness
dcloud347 Aug 9, 2025
0254a88
Enhance context extraction by refining prompts and adding context tra…
dcloud347 Aug 9, 2025
19cfe6b
Enhance file reading and context creation by adding line numbers to c…
dcloud347 Aug 9, 2025
ce7b24e
Refactor issue service to use asynchronous invocation for issue graph…
dcloud347 Aug 9, 2025
c4f7b26
Refactor context creation to remove line number prepending and stream…
dcloud347 Aug 9, 2025
5bc5a9e
Refactor issue service tests to use asynchronous invocation and updat…
dcloud347 Aug 9, 2025
58e9229
Add asynchronous writing lock to knowledge graph building process
dcloud347 Aug 9, 2025
c9a1270
Reduce recursion limit in context retrieval subgraph to improve perfo…
dcloud347 Aug 9, 2025
9590c6e
Add thread-specific logging for various nodes to improve traceability
dcloud347 Aug 10, 2025
e27d9ee
Refactor issue service to streamline container initialization and enh…
dcloud347 Aug 10, 2025
05c97c9
Enhance error handling in issue processing and update return types fo…
dcloud347 Aug 10, 2025
0f9073f
Remove outdated configuration details from README.md
dcloud347 Aug 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 0 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,39 +177,6 @@ Verify Neo4J at: [http://localhost:7474](http://localhost:7474)

---

## ⚙️ Configuration

Set the following variables in your `.env` file:

### 🔹 Neo4j

* `PROMETHEUS_NEO4J_URI`
* `PROMETHEUS_NEO4J_USERNAME`
* `PROMETHEUS_NEO4J_PASSWORD`

### 🔹 LLM Models

* `PROMETHEUS_ADVANCED_MODEL`
* `PROMETHEUS_BASE_MODEL`
* API Keys:

* `PROMETHEUS_OPENAI_FORMAT_API_KEY`
* `PROMETHEUS_ANTHROPIC_API_KEY`
* `PROMETHEUS_GEMINI_API_KEY`
* Base URL for LLMs:

* `PROMETHEUS_OPENAI_FORMAT_BASE_URL`

### 🔹 Other Settings

* `PROMETHEUS_WORKING_DIRECTORY`
* `PROMETHEUS_GITHUB_ACCESS_TOKEN`
* `PROMETHEUS_KNOWLEDGE_GRAPH_MAX_AST_DEPTH`
* `PROMETHEUS_NEO4J_BATCH_SIZE`
* `PROMETHEUS_POSTGRES_URL`

---

## 🧪 Development

### Requirements
Expand Down
16 changes: 14 additions & 2 deletions prometheus/app/api/routes/issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from prometheus.app.models.requests.issue import IssueRequest
from prometheus.app.models.response.issue import IssueResponse
from prometheus.app.models.response.response import Response
from prometheus.app.services.issue_service import IssueService
from prometheus.app.services.knowledge_graph_service import KnowledgeGraphService
from prometheus.app.services.repository_service import RepositoryService
from prometheus.configuration.config import settings
Expand All @@ -21,7 +22,7 @@
response_model=Response[IssueResponse],
)
@requireLogin
def answer_issue(issue: IssueRequest, request: Request) -> Response[IssueResponse]:
async def answer_issue(issue: IssueRequest, request: Request) -> Response[IssueResponse]:
repository_service: RepositoryService = request.app.state.service["repository_service"]
repository = repository_service.get_repository_by_id(issue.repository_id)
if not repository:
Expand All @@ -36,6 +37,12 @@ def answer_issue(issue: IssueRequest, request: Request) -> Response[IssueRespons
message="workdir must be provided for user defined environment",
)

if repository.is_working:
raise ServerException(
code=400,
message="The repository is currently being used. Please try again later.",
)

knowledge_graph_service: KnowledgeGraphService = request.app.state.service[
"knowledge_graph_service"
]
Expand All @@ -47,14 +54,18 @@ def answer_issue(issue: IssueRequest, request: Request) -> Response[IssueRespons
repository.kg_chunk_size,
repository.kg_chunk_overlap,
)

issue_service: IssueService = request.app.state.service["issue_service"]

(
remote_branch_name,
patch,
passed_reproducing_test,
passed_build,
passed_existing_test,
issue_response,
) = request.app.state.service["issue_service"].answer_issue(
) = await issue_service.answer_issue(
repository_id=repository.id,
repository=git_repository,
knowledge_graph=knowledge_graph,
issue_number=issue.issue_number,
Expand All @@ -73,6 +84,7 @@ def answer_issue(issue: IssueRequest, request: Request) -> Response[IssueRespons
test_commands=issue.test_commands,
push_to_remote=issue.push_to_remote,
)
repository_service.update_repository_status(repository.id, is_working=False)
return Response(
data=IssueResponse(
patch=patch,
Expand Down
2 changes: 2 additions & 0 deletions prometheus/app/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,11 @@ def initialize_services() -> dict[str, BaseService]:
)
issue_service = IssueService(
neo4j_service,
repository_service,
llm_service,
settings.MAX_TOKEN_PER_NEO4J_RESULT,
settings.WORKING_DIRECTORY,
settings.LOGGING_LEVEL,
)

user_service = UserService(database_service)
Expand Down
4 changes: 4 additions & 0 deletions prometheus/app/entity/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ class Repository(SQLModel, table=True):
max_length=300,
description="The playground path of the repository where the repository was cloned.",
)
is_working: bool = Field(
default=False,
description="Indicates whether the repository is currently being used for processing or not.",
)
user_id: int = Field(
index=True, nullable=True, description="The ID of the user who upload this repository."
)
Expand Down
194 changes: 136 additions & 58 deletions prometheus/app/services/issue_service.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import asyncio
import logging
import threading
import traceback
import uuid
from datetime import datetime
Expand All @@ -10,6 +12,7 @@
from prometheus.app.services.neo4j_service import Neo4jService
from prometheus.docker.general_container import GeneralContainer
from prometheus.docker.user_defined_container import UserDefinedContainer
from prometheus.exceptions.server_exception import ServerException
from prometheus.git.git_repository import GitRepository
from prometheus.graph.knowledge_graph import KnowledgeGraph
from prometheus.lang_graph.graphs.issue_graph import IssueGraph
Expand All @@ -20,19 +23,24 @@ class IssueService(BaseService):
def __init__(
self,
neo4j_service: Neo4jService,
repository_service,
llm_service: LLMService,
max_token_per_neo4j_result: int,
working_directory: str,
logging_level: str,
):
self.neo4j_service = neo4j_service
self.repository_service = repository_service
self.llm_service = llm_service
self.max_token_per_neo4j_result = max_token_per_neo4j_result
self.working_directory = working_directory
self.answer_issue_log_dir = Path(self.working_directory) / "answer_issue_logs"
self.answer_issue_log_dir.mkdir(parents=True, exist_ok=True)
self.logging_level = logging_level

def answer_issue(
async def answer_issue(
self,
repository_id: int,
repository: GitRepository,
knowledge_graph: KnowledgeGraph,
issue_number: int,
Expand All @@ -55,6 +63,7 @@ def answer_issue(
Processes an issue, generates patches if needed, runs optional builds and tests, and returning the results.

Args:
repository_id: The ID of the repository to update.
repository (GitRepository): The Git repository instance.
knowledge_graph (KnowledgeGraph): The knowledge graph instance.
issue_number (int): The number of the issue.
Expand All @@ -80,39 +89,130 @@ def answer_issue(
- passed_existing_test (bool): Whether the existing tests passed.
- issue_response (str): Response generated for the issue.
"""
logger = logging.getLogger("prometheus")

# Initialize the issue graph with the necessary services and parameters
(
edit_patch,
passed_reproducing_test,
passed_build,
passed_existing_test,
issue_response,
issue_type,
) = await asyncio.to_thread(
self.__answer,
repository_id=repository_id,
issue_title=issue_title,
issue_body=issue_body,
issue_comments=issue_comments,
issue_type=issue_type,
run_build=run_build,
run_existing_test=run_existing_test,
run_reproduce_test=run_reproduce_test,
number_of_candidate_patch=number_of_candidate_patch,
knowledge_graph=knowledge_graph,
repository=repository,
build_commands=build_commands,
test_commands=test_commands,
dockerfile_content=dockerfile_content,
image_name=image_name,
workdir=workdir,
)
if (
edit_patch,
passed_reproducing_test,
passed_build,
passed_existing_test,
issue_response,
issue_type,
) == (None, False, False, False, None, None):
raise ServerException(500, "Failed to process the issue due to an internal error.")
if issue_type == IssueType.BUG:
# push to remote if requested
remote_branch_name = None
if edit_patch and push_to_remote:
remote_branch_name = f"prometheus_fix_{uuid.uuid4().hex[:10]}"
await repository.create_and_push_branch(
remote_branch_name, f"Fixes #{issue_number}", edit_patch
)

return (
remote_branch_name,
edit_patch,
passed_reproducing_test,
passed_build,
passed_existing_test,
issue_response,
)
elif issue_type == IssueType.QUESTION:
return (
None,
None,
False,
False,
False,
issue_response,
)
else:
raise ValueError(f"Unknown issue type: {issue_type}. Expected BUG or QUESTION.")

def __answer(
self,
knowledge_graph: KnowledgeGraph,
repository: GitRepository,
repository_id: int,
issue_title: str,
issue_body: str,
issue_comments: Sequence[Mapping[str, str]],
issue_type: IssueType,
run_build: bool,
run_existing_test: bool,
run_reproduce_test: bool,
number_of_candidate_patch: int,
build_commands: Optional[Sequence[str]],
test_commands: Optional[Sequence[str]],
dockerfile_content: Optional[str] = None,
image_name: Optional[str] = None,
workdir: Optional[str] = None,
) -> tuple[None, bool, bool, bool, None, None] | tuple[str, bool, bool, bool, str, IssueType]:
# Set up a dedicated logger for this thread
logger = logging.getLogger(f"thread-{threading.get_ident()}.prometheus")
logger.setLevel(getattr(logging, self.logging_level))
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
log_file = self.answer_issue_log_dir / f"{timestamp}.log"
log_file = self.answer_issue_log_dir / f"{timestamp}_{threading.get_ident()}.log"
file_handler = logging.FileHandler(log_file)
file_handler.setFormatter(formatter)
logger.addHandler(file_handler)

try:
# Construct the working directory
if dockerfile_content or image_name:
container = UserDefinedContainer(
repository.get_working_directory(),
workdir,
build_commands,
test_commands,
dockerfile_content,
image_name,
)
else:
container = GeneralContainer(repository.get_working_directory())
# Initialize the issue graph with the necessary services and parameters
issue_graph = IssueGraph(
advanced_model=self.llm_service.advanced_model,
base_model=self.llm_service.base_model,
kg=knowledge_graph,
git_repo=repository,
neo4j_driver=self.neo4j_service.neo4j_driver,
max_token_per_neo4j_result=self.max_token_per_neo4j_result,
container=container,
build_commands=build_commands,
test_commands=test_commands,
# Construct the working directory
if dockerfile_content or image_name:
container = UserDefinedContainer(
repository.get_working_directory(),
workdir,
build_commands,
test_commands,
dockerfile_content,
image_name,
)
else:
container = GeneralContainer(repository.get_working_directory())

# Initialize the IssueGraph with the provided services and parameters
issue_graph = IssueGraph(
advanced_model=self.llm_service.advanced_model,
base_model=self.llm_service.base_model,
kg=knowledge_graph,
git_repo=repository,
neo4j_driver=self.neo4j_service.neo4j_driver,
max_token_per_neo4j_result=self.max_token_per_neo4j_result,
container=container,
build_commands=build_commands,
test_commands=test_commands,
)

# Update the repository status to working
self.repository_service.update_repository_status(repository_id, is_working=True)
try:
# Invoke the issue graph with the provided parameters
output_state = issue_graph.invoke(
issue_title,
Expand All @@ -124,40 +224,18 @@ def answer_issue(
run_reproduce_test,
number_of_candidate_patch,
)

if output_state["issue_type"] == IssueType.BUG:
# push to remote if requested
remote_branch_name = None
if output_state["edit_patch"] and push_to_remote:
remote_branch_name = f"prometheus_fix_{uuid.uuid4().hex[:10]}"
repository.create_and_push_branch(
remote_branch_name, f"Fixes #{issue_number}", output_state["edit_patch"]
)

return (
remote_branch_name,
output_state["edit_patch"],
output_state["passed_reproducing_test"],
output_state["passed_build"],
output_state["passed_existing_test"],
output_state["issue_response"],
)
elif output_state["issue_type"] == IssueType.QUESTION:
return (
None,
None,
False,
False,
False,
output_state["issue_response"],
)

raise ValueError(
f"Unknown issue type: {output_state['issue_type']}. Expected BUG or QUESTION."
return (
output_state["edit_patch"],
output_state["passed_reproducing_test"],
output_state["passed_build"],
output_state["passed_existing_test"],
output_state["issue_response"],
output_state["issue_type"],
)
except Exception as e:
logger.error(f"Error in answer_issue: {str(e)}\n{traceback.format_exc()}")
return None, None, False, False, False, None
return None, False, False, False, None, None
finally:
self.repository_service.update_repository_status(repository_id, is_working=False)
logger.removeHandler(file_handler)
file_handler.close()
Loading