-
Notifications
You must be signed in to change notification settings - Fork 0
Eradicate Fluff with Real Algorithmic Implementations #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import sys | ||
| from unittest.mock import MagicMock | ||
|
|
||
| # Create mock objects for heavy dependencies that are missing | ||
| sys.modules['pydantic'] = MagicMock() | ||
| sys.modules['faiss'] = MagicMock() | ||
| sys.modules['neo4j'] = MagicMock() | ||
| sys.modules['openai'] = MagicMock() |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import sys | ||
| from unittest.mock import MagicMock | ||
|
|
||
| class MockBaseModel: | ||
| pass | ||
|
|
||
| class MockField: | ||
| def __init__(self, *args, **kwargs): | ||
| pass | ||
|
|
||
| pydantic_mock = MagicMock() | ||
| pydantic_mock.BaseModel = MockBaseModel | ||
| pydantic_mock.Field = MockField | ||
| sys.modules['pydantic'] = pydantic_mock | ||
| sys.modules['faiss'] = MagicMock() | ||
| sys.modules['neo4j'] = MagicMock() | ||
| sys.modules['openai'] = MagicMock() | ||
|
|
||
| # Instead of importing pytest directly into our namespace where it might not exist, | ||
| # we add our mocks to sitecustomize.py or directly call pytest with python -m pytest | ||
| # Wait, actually we can't import pytest from system python if it's not installed in this pyenv. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import sys | ||
| from unittest.mock import MagicMock | ||
|
|
||
| class MockBaseModel: | ||
| pass | ||
|
|
||
| class MockField: | ||
| def __init__(self, *args, **kwargs): | ||
| pass | ||
|
|
||
| pydantic_mock = MagicMock() | ||
| pydantic_mock.BaseModel = MockBaseModel | ||
| pydantic_mock.Field = MockField | ||
| sys.modules['pydantic'] = pydantic_mock | ||
|
|
||
| faiss_mock = MagicMock() | ||
| sys.modules['faiss'] = faiss_mock | ||
| neo4j_mock = MagicMock() | ||
| sys.modules['neo4j'] = neo4j_mock | ||
| openai_mock = MagicMock() | ||
| sys.modules['openai'] = openai_mock | ||
|
|
||
| import pytest | ||
| sys.exit(pytest.main(['tests/unit/'])) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -104,37 +104,47 @@ async def execute_graph(self, source_code: str) -> Dict[str, Any]: | |
| results = {} | ||
| failed_nodes = set() | ||
|
|
||
| # Execute in topological order | ||
| for node_id in nx.topological_sort(self.current_dag): | ||
| if node_id in failed_nodes: | ||
| continue | ||
|
|
||
| node = self.current_dag.nodes[node_id]['data'] | ||
|
|
||
| # Validate state before execution | ||
| if not self._validate_state_pre_execution(): | ||
| # State is invalid, attempt rollback | ||
| await self._rollback_to_last_valid_state(self.step_index) | ||
| continue | ||
| # Execute in topological generations for parallel DAG execution | ||
| for generation in nx.topological_generations(self.current_dag): | ||
| tasks = [] | ||
| valid_nodes = [] | ||
|
|
||
| # Record step start | ||
| self.bus.record_step(self.trace_id, self.step_index, "node_start", {"node_id": node_id}, self.state_manager) | ||
|
|
||
| try: | ||
| result = await self._execute_node_with_validation(node) | ||
| results[node_id] = result | ||
| for node_id in generation: | ||
| if node_id in failed_nodes: | ||
| continue | ||
|
|
||
| node = self.current_dag.nodes[node_id]['data'] | ||
|
|
||
| # Validate state after execution | ||
| if not self._validate_state_post_execution(): | ||
| raise ValueError(f"State validation failed after executing node {node_id}") | ||
| # Validate state before execution | ||
| if not self._validate_state_pre_execution(): | ||
| # State is invalid, attempt rollback | ||
| await self._rollback_to_last_valid_state(self.step_index) | ||
| break | ||
|
|
||
| # Record successful step | ||
| self.bus.record_step(self.trace_id, self.step_index + 1, "node_success", {"node_id": node_id, "result": str(result)}, self.state_manager) | ||
| self.step_index += 1 | ||
| # Record step start | ||
| self.bus.record_step(self.trace_id, self.step_index, "node_start", {"node_id": node_id}, self.state_manager) | ||
|
|
||
| except Exception as e: | ||
| # Failure detected - implement MVCC rollback and AST patching | ||
| await self._handle_node_failure(node_id, e, failed_nodes) | ||
| tasks.append(self._execute_node_with_validation(node)) | ||
| valid_nodes.append(node_id) | ||
|
|
||
| if tasks: | ||
| results_list = await asyncio.gather(*tasks, return_exceptions=True) | ||
| for idx, res in enumerate(results_list): | ||
| node_id = valid_nodes[idx] | ||
| if isinstance(res, Exception): | ||
| # Failure detected - implement MVCC rollback and AST patching | ||
| await self._handle_node_failure(node_id, res, failed_nodes) | ||
| else: | ||
| results[node_id] = res | ||
|
|
||
| # Validate state after execution | ||
| if not self._validate_state_post_execution(): | ||
| raise ValueError(f"State validation failed after executing node {node_id}") | ||
|
Comment on lines
+141
to
+142
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Useful? React with 👍 / 👎. |
||
|
|
||
| # Record successful step | ||
| self.bus.record_step(self.trace_id, self.step_index + 1, "node_success", {"node_id": node_id, "result": str(res)}, self.state_manager) | ||
|
|
||
| self.step_index += 1 | ||
|
|
||
| return results | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This new gate makes
heal_offlinefail closed forKeyError/AttributeError/TypeErroreven when constraints are satisfiable, because_verify_formal_datacomparessolver.check(...)to the string"sat"whileZ3Solver.checkreturnsZ3ResultType.SAT/UNSATenums (src/hanerma/reasoning/z3_solver.py). With this condition in place, the branch now returnssuccess=Falseand leavesdag_contextunpatched for these common errors.Useful? React with 👍 / 👎.