Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 6 additions & 2 deletions gateway/mirror.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,13 @@ def mirror_to_session(
logger.debug("Mirror: no session found for %s:%s:%s", platform, chat_id, thread_id)
return False

# Use "user" role for mirrored cron/delivery messages to maintain
# proper user/assistant alternation in the conversation history.
# Using "assistant" caused two consecutive assistant messages which
# confuses models and can cause API rejections on strict providers.
mirror_msg = {
"role": "assistant",
"content": message_text,
"role": "user",
"content": f"[Cron delivery from {source_label}]\n{message_text}",
"timestamp": datetime.now().isoformat(),
"mirror": True,
"mirror_source": source_label,
Expand Down
4 changes: 2 additions & 2 deletions tests/gateway/test_mirror.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ def test_successful_mirror(self, tmp_path):
transcript = sessions_dir / "sess_abc.jsonl"
assert transcript.exists()
msg = json.loads(transcript.read_text().strip())
assert msg["content"] == "Hello!"
assert msg["role"] == "assistant"
assert msg["content"] == "[Cron delivery from cli]\nHello!"
assert msg["role"] == "user"
assert msg["mirror"] is True
assert msg["mirror_source"] == "cli"

Expand Down
Loading