Answer architecture round 1: Failure and the file modules get truthful homes, the interrupt question is a pure function, the judge grounds on what it saw
This commit is contained in:
@@ -1,17 +1,26 @@
|
||||
import dataclasses
|
||||
import sys
|
||||
import typing
|
||||
|
||||
from loop_claude.effects import Effects
|
||||
from file_io.failure import Failure
|
||||
from loop_claude.cycle.limited import Limited
|
||||
from failure import Failure
|
||||
from loop_claude.stop import Stop
|
||||
|
||||
T = typing.TypeVar("T")
|
||||
|
||||
FAILURES_RUNNING = 3
|
||||
PAST_RESET = 120
|
||||
RETRY_DELAY = 60
|
||||
UNKNOWN_RESET_POLL = 600
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class Limited:
|
||||
"""claude hit a usage limit; said is claude's message about it, and resets_at is when the limit resets, in seconds since the epoch, or None when unknown."""
|
||||
resets_at: int | None
|
||||
said: str
|
||||
|
||||
|
||||
def retried(who: str, attempt: typing.Callable[[], T | Failure | Limited], effects: Effects) -> T | Stop:
|
||||
failures = 0
|
||||
while True:
|
||||
@@ -27,10 +36,10 @@ def retried(who: str, attempt: typing.Callable[[], T | Failure | Limited], effec
|
||||
if not isinstance(result, Failure):
|
||||
return result
|
||||
failures += 1
|
||||
if failures == 3:
|
||||
if failures == FAILURES_RUNNING:
|
||||
return Stop(1, f"the {who} failed three times running: {result.reason}")
|
||||
print(f"retrying the {who} in a minute: {result.reason}", file=sys.stderr)
|
||||
effects.sleep(60)
|
||||
effects.sleep(RETRY_DELAY)
|
||||
|
||||
|
||||
def limit_wait(limited: Limited, now: float) -> float:
|
||||
|
||||
Reference in New Issue
Block a user