[067ce5d1] fix(runtime): detect session-limit 429 in Claude transcript for provider parking

The SDK server writes runtime output to /tmp/sdk-server.log inside the agent
container, so the session-limit markers never appeared in docker logs. Read
the newest durable Claude transcript from ~/.claude/projects as a fallback so
the provider gets parked and auto-revived instead of crash-retrying.

- Add _transcript_tail_text to read the agent's transcript tail
- Use it in _provider_rate_limit_park_target alongside docker logs
- Add regression test for transcript-only detection
This commit is contained in:
Renn F
2026-06-25 03:28:03 +02:00
parent 60c64c70e8
commit 75788f519c
2 changed files with 57 additions and 3 deletions
@@ -46,8 +46,13 @@ def _instance(provider_type: str | None = "anthropic") -> AgentInstance:
@pytest.fixture
def orch() -> AgentOrchestrator:
return AgentOrchestrator.__new__(AgentOrchestrator)
def orch(monkeypatch: pytest.MonkeyPatch) -> AgentOrchestrator:
orch = AgentOrchestrator.__new__(AgentOrchestrator)
# Tests for parking detection control docker logs directly; keep the durable
# transcript fallback empty by default so dev environments with stray
# transcripts do not make the tests flaky.
monkeypatch.setattr(orch, "_transcript_tail_text", lambda _a, _lines=80: "")
return orch
class _FakeTracker:
@@ -225,6 +230,22 @@ async def test_detects_session_limit_marker_for_anthropic(
)
@pytest.mark.asyncio
async def test_detects_session_limit_marker_in_transcript(
orch: AgentOrchestrator, monkeypatch: pytest.MonkeyPatch
) -> None:
"""Docker logs miss the SDK-server log; the durable transcript still has it."""
monkeypatch.setattr(settings, "overload_break_enabled", True)
monkeypatch.setattr(orch, "_tail_container_logs", AsyncMock(return_value=""))
monkeypatch.setattr(
orch, "_transcript_tail_text", lambda _a, _lines=80: _SESSION_LIMIT_LOG
)
assert (
await orch._provider_rate_limit_park_target("be-dev-1", _instance())
== "anthropic"
)
@pytest.mark.asyncio
async def test_clean_output_is_not_a_session_limit(
orch: AgentOrchestrator, monkeypatch: pytest.MonkeyPatch