|
2 | 2 |
|
3 | 3 | from datetime import UTC, datetime |
4 | 4 | from pathlib import Path |
5 | | -from time import sleep |
| 5 | +from time import monotonic, sleep |
6 | 6 |
|
7 | 7 | from dory_core.active_memory import ActiveMemoryEngine |
8 | 8 | from dory_core.retrieval_planner import ActiveMemoryComposition, ActiveMemoryPlanningContext, ActiveMemoryRetrievalPlan |
@@ -153,6 +153,7 @@ def test_active_memory_builds_memory_block_for_state_question(tmp_path: Path) -> |
153 | 153 | prompt="what are we working on today", |
154 | 154 | agent="claude", |
155 | 155 | cwd=str(tmp_path), |
| 156 | + timeout_ms=7000, |
156 | 157 | ) |
157 | 158 | ) |
158 | 159 |
|
@@ -358,6 +359,7 @@ def search(self, req: SearchReq): # pragma: no cover - test stub |
358 | 359 | prompt="Before answering a coding question about Dory agent integrations, retrieve only the memory that matters.", |
359 | 360 | agent="codex", |
360 | 361 | include_wake=True, |
| 362 | + timeout_ms=7000, |
361 | 363 | ) |
362 | 364 | ) |
363 | 365 |
|
@@ -554,8 +556,8 @@ def search(self, req: SearchReq): # pragma: no cover - test stub |
554 | 556 | prompt="debug Dory Docker MCP setup", |
555 | 557 | agent="codex", |
556 | 558 | include_wake=False, |
557 | | - timeout_ms=5000, |
558 | | - ).model_copy(update={"timeout_ms": 7000}) |
| 559 | + timeout_ms=7000, |
| 560 | + ) |
559 | 561 | ) |
560 | 562 |
|
561 | 563 | assert "Docker MCP setup fails when the daemon URL is stale." in result.block |
@@ -845,8 +847,8 @@ def test_active_memory_uses_planner_queries_and_llm_composition_when_budget_allo |
845 | 847 | prompt="what are we working on today", |
846 | 848 | agent="claude", |
847 | 849 | cwd=str(tmp_path), |
848 | | - timeout_ms=5000, |
849 | | - ).model_copy(update={"timeout_ms": 7000}) |
| 850 | + timeout_ms=7000, |
| 851 | + ) |
850 | 852 | ) |
851 | 853 |
|
852 | 854 | assert result.summary == "Rooster remains the active focus." |
@@ -916,8 +918,8 @@ def compose_active_memory( |
916 | 918 | prompt="what are we working on today", |
917 | 919 | agent="claude", |
918 | 920 | include_wake=False, |
919 | | - timeout_ms=5000, |
920 | | - ).model_copy(update={"timeout_ms": 7000}) |
| 921 | + timeout_ms=7000, |
| 922 | + ) |
921 | 923 | ) |
922 | 924 |
|
923 | 925 | assert result.summary.startswith("Rooster is the active focus this week.") |
@@ -1095,3 +1097,61 @@ def search(self, req: SearchReq): |
1095 | 1097 |
|
1096 | 1098 | assert 1 <= len(search_engine.requests) < 4 |
1097 | 1099 | assert result.kind == "memory" |
| 1100 | + |
| 1101 | + |
| 1102 | +def test_active_memory_disables_rerank_when_total_timeout_cannot_absorb_it(tmp_path: Path) -> None: |
| 1103 | + class ManyQueryPlanner: |
| 1104 | + def plan_active_memory( |
| 1105 | + self, |
| 1106 | + *, |
| 1107 | + prompt: str, |
| 1108 | + context: ActiveMemoryPlanningContext, |
| 1109 | + ) -> ActiveMemoryRetrievalPlan: |
| 1110 | + del prompt, context |
| 1111 | + return ActiveMemoryRetrievalPlan( |
| 1112 | + durable_queries=("one", "two", "three"), |
| 1113 | + session_queries=(), |
| 1114 | + include_sessions=False, |
| 1115 | + durable_limit=8, |
| 1116 | + session_limit=0, |
| 1117 | + ) |
| 1118 | + |
| 1119 | + class RerankSensitiveSearchEngine(_StubSearchEngine): |
| 1120 | + def search(self, req: SearchReq): |
| 1121 | + self.requests.append(req) |
| 1122 | + if req.rerank != "false": |
| 1123 | + sleep(0.08) |
| 1124 | + return super().search(req) |
| 1125 | + |
| 1126 | + search_engine = RerankSensitiveSearchEngine() |
| 1127 | + engine = ActiveMemoryEngine( |
| 1128 | + wake_builder=WakeBuilder(root=tmp_path), |
| 1129 | + search_engine=search_engine, |
| 1130 | + planner=ManyQueryPlanner(), |
| 1131 | + ) |
| 1132 | + |
| 1133 | + started = monotonic() |
| 1134 | + result = engine.build( |
| 1135 | + ActiveMemoryReq( |
| 1136 | + prompt="what are we working on today", |
| 1137 | + agent="claude", |
| 1138 | + include_wake=False, |
| 1139 | + timeout_ms=5000, |
| 1140 | + ) |
| 1141 | + ) |
| 1142 | + elapsed = monotonic() - started |
| 1143 | + |
| 1144 | + assert result.kind == "memory" |
| 1145 | + assert search_engine.requests |
| 1146 | + assert {req.rerank for req in search_engine.requests} == {"false"} |
| 1147 | + assert elapsed < 0.08 |
| 1148 | + |
| 1149 | + |
| 1150 | +def test_active_memory_request_accepts_larger_timeout_for_slow_local_models() -> None: |
| 1151 | + req = ActiveMemoryReq( |
| 1152 | + prompt="what are we working on today", |
| 1153 | + agent="claude", |
| 1154 | + timeout_ms=12000, |
| 1155 | + ) |
| 1156 | + |
| 1157 | + assert req.timeout_ms == 12000 |
0 commit comments