Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 7, 2025

Addresses feedback from PR #24: nested functions _collect_statistics and _clear_sync capture self from enclosing scope, creating potential issues when moved to threads via asyncio.to_thread().

Changes

  • Convert _collect_statistics() and _clear_sync() from nested functions to private instance methods
  • Update call sites to use self._collect_statistics and self._clear_sync

Before:

async def get_statistics(self) -> Dict[str, Any]:
    def _collect_statistics() -> Dict[str, Any]:
        # Accesses self from closure
        return {"initialized": self._initialized, ...}
    
    return await asyncio.to_thread(_collect_statistics)

After:

def _collect_statistics(self) -> Dict[str, Any]:
    """Collect statistics from the knowledge base in a synchronous manner."""
    return {"initialized": self._initialized, ...}

async def get_statistics(self) -> Dict[str, Any]:
    return await asyncio.to_thread(self._collect_statistics)

No functional changes—methods execute identically in thread pool.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@royisme royisme marked this pull request as ready for review November 7, 2025 05:43
Convert _collect_statistics and _clear_sync from nested functions to
regular instance methods to avoid closure-related issues when used with
asyncio.to_thread. This improves code clarity and follows best practices
for thread-safe async operations.

Co-authored-by: royisme <350731+royisme@users.noreply.github.com>
Base automatically changed from codex/refactor-neo4jknowledgeservice-to-querypipeline to main November 7, 2025 05:45
Co-authored-by: royisme <350731+royisme@users.noreply.github.com>
Copilot AI changed the title [WIP] WIP Address feedback on Neo4j knowledge query pipeline refactor Refactor nested functions to instance methods in Neo4j service Nov 7, 2025
Copilot AI requested a review from royisme November 7, 2025 05:50
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.

2 participants