-
Notifications
You must be signed in to change notification settings - Fork 52.7k
fix(gateway): suppress hidden-only incomplete Codex turns #51657
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
Closed
LeonSGP43
wants to merge
1
commit into
NousResearch:main
from
LeonSGP43:fix/51628-gateway-incomplete-turn-safety
+196
−2
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,159 @@ | ||
| """Regression tests for hidden-reasoning-only incomplete gateway turns.""" | ||
|
|
||
| import asyncio | ||
| from datetime import datetime | ||
| from types import SimpleNamespace | ||
| from unittest.mock import AsyncMock, MagicMock | ||
|
|
||
| import pytest | ||
|
|
||
| import gateway.run as gateway_run | ||
| from gateway.config import GatewayConfig, Platform, PlatformConfig | ||
| from gateway.platforms.base import BasePlatformAdapter, MessageEvent, ProcessingOutcome, SendResult | ||
| from gateway.session import SessionEntry, SessionSource, build_session_key | ||
|
|
||
|
|
||
| class CaptureSlackAdapter(BasePlatformAdapter): | ||
| def __init__(self): | ||
| super().__init__(PlatformConfig(enabled=True, token="fake-token"), Platform.SLACK) | ||
| self.sent = [] | ||
| self.processing_hooks = [] | ||
|
|
||
| async def connect(self) -> bool: | ||
| return True | ||
|
|
||
| async def disconnect(self) -> None: | ||
| return None | ||
|
|
||
| async def send(self, chat_id, content, reply_to=None, metadata=None) -> SendResult: | ||
| self.sent.append( | ||
| { | ||
| "chat_id": chat_id, | ||
| "content": content, | ||
| "reply_to": reply_to, | ||
| "metadata": metadata, | ||
| } | ||
| ) | ||
| return SendResult(success=True, message_id="slack-1") | ||
|
|
||
| async def send_typing(self, chat_id: str, metadata=None) -> None: | ||
| return None | ||
|
|
||
| async def get_chat_info(self, chat_id: str): | ||
| return {"id": chat_id} | ||
|
|
||
| async def on_processing_start(self, event: MessageEvent) -> None: | ||
| self.processing_hooks.append(("start", event.message_id)) | ||
|
|
||
| async def on_processing_complete(self, event: MessageEvent, outcome: ProcessingOutcome) -> None: | ||
| self.processing_hooks.append(("complete", event.message_id, outcome)) | ||
|
|
||
|
|
||
| def _make_incomplete_result() -> dict: | ||
| return { | ||
| "final_response": None, | ||
| "messages": [ | ||
| {"role": "user", "content": "hello"}, | ||
| {"role": "assistant", "content": ""}, | ||
| ], | ||
| "tools": [], | ||
| "history_offset": 0, | ||
| "api_calls": 3, | ||
| "partial": True, | ||
| "completed": False, | ||
| "interrupted": False, | ||
| "error": "Codex response remained incomplete after 3 continuation attempts", | ||
| "last_prompt_tokens": 0, | ||
| } | ||
|
|
||
|
|
||
| def _make_runner(adapter: CaptureSlackAdapter) -> gateway_run.GatewayRunner: | ||
| runner = object.__new__(gateway_run.GatewayRunner) | ||
| runner.config = GatewayConfig( | ||
| platforms={Platform.SLACK: PlatformConfig(enabled=True, token="fake-token")} | ||
| ) | ||
| runner.adapters = {Platform.SLACK: adapter} | ||
| runner._voice_mode = {} | ||
| runner.hooks = SimpleNamespace(emit=AsyncMock(), loaded_hooks=False) | ||
| runner.session_store = MagicMock() | ||
| runner.session_store.get_or_create_session.return_value = SessionEntry( | ||
| session_key="agent:main:slack:channel:C123:171717", | ||
| session_id="sess-1", | ||
| created_at=datetime.now(), | ||
| updated_at=datetime.now(), | ||
| platform=Platform.SLACK, | ||
| chat_type="channel", | ||
| ) | ||
| runner.session_store.load_transcript.return_value = [] | ||
| runner.session_store.has_any_sessions.return_value = True | ||
| runner.session_store.rewrite_transcript = MagicMock() | ||
| runner.session_store.append_to_transcript = MagicMock() | ||
| runner.session_store.update_session = MagicMock() | ||
| runner._running_agents = {} | ||
| runner._pending_messages = {} | ||
| runner._pending_approvals = {} | ||
| runner._session_db = None | ||
| runner._is_user_authorized = lambda _source: True | ||
| runner._set_session_env = lambda _context: None | ||
| runner._run_agent = AsyncMock(return_value=_make_incomplete_result()) | ||
| return runner | ||
|
|
||
|
|
||
| def _make_event() -> MessageEvent: | ||
| return MessageEvent( | ||
| text="hello", | ||
| source=SessionSource( | ||
| platform=Platform.SLACK, | ||
| chat_id="C123", | ||
| chat_type="channel", | ||
| thread_id="171717", | ||
| user_id="U123", | ||
| ), | ||
| message_id="m-1", | ||
| ) | ||
|
|
||
|
|
||
| def test_incomplete_codex_warning_is_not_surfaced_as_chat_text(): | ||
| agent_result = _make_incomplete_result() | ||
|
|
||
| response = gateway_run._normalize_empty_agent_response( | ||
| agent_result, | ||
| agent_result.get("final_response") or "", | ||
| history_len=4, | ||
| ) | ||
|
|
||
| assert response == "" | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_incomplete_codex_turn_stays_out_of_slack_transcript(monkeypatch, tmp_path): | ||
| adapter = CaptureSlackAdapter() | ||
| runner = _make_runner(adapter) | ||
|
|
||
| monkeypatch.setattr(gateway_run, "_hermes_home", tmp_path) | ||
| monkeypatch.setattr(gateway_run, "_resolve_runtime_agent_kwargs", lambda: {"api_key": "fake"}) | ||
| monkeypatch.setattr( | ||
| "agent.model_metadata.get_model_context_length", | ||
| lambda *_args, **_kwargs: 100, | ||
| ) | ||
| monkeypatch.setenv("SLACK_HOME_CHANNEL", "C123") | ||
|
|
||
| adapter.set_message_handler(runner._handle_message) | ||
| adapter._keep_typing = lambda *_args, **_kwargs: asyncio.Event().wait() | ||
|
|
||
| event = _make_event() | ||
| await adapter._process_message_background(event, build_session_key(event.source)) | ||
|
|
||
| assert adapter.sent == [] | ||
| assert runner.session_store.update_session.called | ||
|
|
||
| transcript_roles = [ | ||
| call.args[1]["role"] | ||
| for call in runner.session_store.append_to_transcript.call_args_list | ||
| ] | ||
| assert transcript_roles == ["session_meta", "user"] | ||
| assert runner.session_store.append_to_transcript.call_args_list[1].args[1]["content"] == "hello" | ||
| assert adapter.processing_hooks == [ | ||
| ("start", "m-1"), | ||
| ("complete", "m-1", ProcessingOutcome.SUCCESS), | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 predicate cannot match the current retry-exhaustion result:
agent/conversation_loop.py:4436sets this same diagnostic as a non-emptyfinal_response, while the helper rejects non-emptyfinal_responseand the normalizer returns non-emptyresponseatgateway/run.py:2604before reaching this code. Please classify the structured incomplete/no-visible-output state before that early return and test the real result shape.