fix(linear): keep idle compaction from reactivating completed sessions

This commit is contained in:
chengyongru authored and chengyongru committed 2026-09-19 01:24:27 +08:00
1 parent 3c7ebd6cd8
commit 81f84015f2
2 files changed
+26

No files matched your search

+4
View File
@@ -92,6 +92,10 @@ class LinearChannel(BaseChannel):
async def send(self, msg: OutboundMessage) -> None:
event = msg.event
if isinstance(event, ContextCompactionEvent):
# Idle notifications have no originating Linear turn. Sending a thought
# through the cached route would reactivate an already completed session.
if _linear_route(msg.metadata) is None:
return
await self._create_activity(
msg.chat_id,
msg.metadata,
@@ -17,6 +17,7 @@ from urllib.parse import parse_qs, urlparse
import httpx
import pytest
from nanobot.agent.turn_delivery import TurnDeliveryFactory
from nanobot.bus.events import OutboundMessage
from nanobot.bus.outbound_events import (
ContextCompactionEvent,
@@ -623,6 +624,27 @@ async def test_compaction_uses_temporary_progress_and_a_persistent_outcome(
assert len({activity["activity_id"] for activity in client.activities}) == len(client.activities)
async def test_idle_compaction_does_not_reactivate_a_completed_agent_session(tmp_path: Path) -> None:
channel, client = _runtime(tmp_path)
await channel._process_webhook("delivery-1", _agent_webhook()) # pyright: ignore[reportPrivateUsage]
inbound = await channel.bus.consume_inbound()
factory = TurnDeliveryFactory(channel.bus)
session_metadata: dict[str, Any] = {}
factory.create(inbound, inbound.session_key).remember_session_route(session_metadata)
await channel.send(OutboundMessage(
channel="linear", chat_id=inbound.chat_id, content="Done", metadata=inbound.metadata,
))
activity_count = len(client.activities)
idle_events = factory.session_events(inbound.session_key, session_metadata)
for phase in ("started", "succeeded"):
await idle_events.emit(ContextCompactionEvent(compaction_id="idle-1", phase=phase))
await channel.send(await channel.bus.consume_outbound())
assert len(client.activities) == activity_count
assert client.activities[-1]["content"] == {"type": "response", "body": "Done"}
def test_revocation_removes_workspace_installation(tmp_path: Path) -> None:
channel, _ = _runtime(tmp_path)
channel._process_lifecycle_event( # pyright: ignore[reportPrivateUsage]