[codex] fix mcp helper stability and session loading regressions#26
[codex] fix mcp helper stability and session loading regressions#26
Conversation
Summary of ChangesHello @Hmbown, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses critical stability and regression issues within the MCP (Multi-Context Programming) server, specifically focusing on session management and the robustness of core helper tools. The changes ensure that sessions can be reliably loaded from various memory pack formats, prevent user code from inadvertently breaking essential MCP functionalities, and standardize line number reporting for improved user experience. These fixes enhance the overall reliability and predictability of the Aleph system. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request effectively addresses several robustness and stability regressions related to session loading, helper function stability, and line number indexing. The fixes are well-implemented and accompanied by a comprehensive suite of regression tests, which is excellent for long-term maintainability. The overall code quality is high. I have one suggestion to further improve the atomicity of the session loading logic, ensuring that partially configured sessions are not added to the active session map in case of an error during configuration.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR addresses MCP local-server robustness regressions around session pack loading compatibility, REPL helper stability (when user code rebinds helper names), and consistent line-index semantics between search_context and peek_context(unit="lines"), and bumps the package version to 0.8.3.
Changes:
- Add stable helper resolution via
REPLEnvironment.get_helper()and use it in MCP query tools to avoid breakage after helper-name rebinding. - Make
load_sessionacceptid/context_id/session_idpayload identifiers and report skipped/invalid entries. - Normalize
peek_context(unit="lines")indices to align withline_number_base, with backward compatibility for legacy 0-based callers, and add regression tests + version bumps.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
aleph/mcp/local_server.py |
Adds helper-resolution + session-id compatibility helpers, improves load_session reporting, and normalizes line indexing for peek_context. |
aleph/repl/sandbox.py |
Preserves stable helper references and exposes get_helper() for tool-side resolution. |
tests/test_mcp_local_server_regressions.py |
New end-to-end regression tests covering the reported regressions. |
tests/test_mcp_local_server.py |
Adds unit tests for new helper functions used by the local server. |
tests/test_sandbox.py |
Adds REPL-level test ensuring get_helper() remains stable after name rebinding. |
pyproject.toml |
Bumps project version to 0.8.3. |
aleph/__init__.py |
Bumps __version__ to 0.8.3. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| loaded = [] | ||
| skipped: list[dict[str, str]] = [] | ||
| for sp in payload.get("sessions", []): |
There was a problem hiding this comment.
load_session() iterates over payload.get("sessions", []) without validating that sessions is a list. If a malformed pack has sessions as a dict/string, this will iterate keys/characters and produce a misleading “success + many skipped” result instead of a clear schema error. Consider validating sessions is a list (and each entry is a dict) and returning an explicit "Invalid memory pack" error when it isn’t.
| loaded = [] | |
| skipped: list[dict[str, str]] = [] | |
| for sp in payload.get("sessions", []): | |
| sessions = payload.get("sessions") | |
| if sessions is None: | |
| sessions = [] | |
| if not isinstance(sessions, list) or any(not isinstance(sp, dict) for sp in sessions): | |
| return _format_error("Invalid memory pack", output=output) | |
| loaded = [] | |
| skipped: list[dict[str, str]] = [] | |
| for sp in sessions: |
| try: | ||
| session = _session_from_payload(sp, sid, self.sandbox_config, asyncio.get_running_loop()) | ||
| self._configure_session(session, sid, loop=asyncio.get_running_loop()) | ||
| self._sessions[sid] = session |
There was a problem hiding this comment.
Inside the load_session() loop, asyncio.get_running_loop() is called twice per session payload. Since the loop is constant within this coroutine, it would be clearer and slightly more efficient to grab it once before iterating and reuse the same variable for _session_from_payload(...) and _configure_session(...).
| self._namespace.update(helpers_ns) | ||
| # Preserve stable helper references so MCP tools can resolve helpers | ||
| # even if user code rebinds names in the REPL namespace. | ||
| self._helpers: dict[str, object] = dict(helpers_ns) |
There was a problem hiding this comment.
REPLEnvironment already imports the helpers module as _helpers, and this change adds an instance attribute named self._helpers. The name collision is easy to misread/typo (module vs dict) and can lead to maintenance bugs later. Consider renaming the attribute to something unambiguous like self._stable_helpers (and updating get_helper() accordingly).
| self._helpers: dict[str, object] = dict(helpers_ns) | |
| self._stable_helpers: dict[str, object] = dict(helpers_ns) |
Summary
This PR fixes three MCP robustness regressions discovered while exercising Aleph end-to-end, and publishes a patch version bump to
0.8.3.User-facing impact
Users could hit confusing or broken behavior in real workflows:
load_sessioncould silently report success but restore zero sessions from valid memory packs generated bysave_session.exec_python, rebinding helper names likelines,search, orsemantic_searchcould break core MCP tools (peek_context,search_context,semantic_search) for that session.search_contextline numbers andpeek_context(unit="lines")indexing were not aligned, making search hits harder to navigate directly.Root cause
save_sessionemitted per-session identifiers assession_id/context_id, whileload_sessiononly looked forid.repl.get_variable(...)), which user code can overwrite.line_number_base.Fixes
load_sessionnow acceptsid,context_id, orsession_id.skippedreporting instead of silently swallowing invalid entries.REPLEnvironmentnow stores immutable helper references and exposesget_helper(name)._get_repl_helper(...).peek_context(unit="lines"):_to_internal_line_index(...)conversion from external base to internal 0-based helper indices.start=0on 1-based sessions.0.8.2to0.8.3in:pyproject.tomlaleph/__init__.pyTests and validation
tests/test_mcp_local_server_regressions.pytests/test_sandbox.pytests/test_mcp_local_server.pyruff check aleph/ tests/✅pytest tests/ -q✅ (307 passed)