Skip to content
Merged
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
12 changes: 6 additions & 6 deletions lifecycle/importance_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,15 @@ async def run_once(self) -> dict[str, int]:
async def _rescore_user(self, user_id: str, conn, stats: dict) -> None:
rows = await (
await conn.execute(
"""SELECT id, "key", value, importance, memory_kind
"""SELECT entry_id, "key", value, importance, memory_kind

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Scheduler fixtures retain old schema

When the scheduler tests run, this query selects entry_id from a fixture that still defines core_memory.id, causing sqlite3.OperationalError: no such column: entry_id; the retrieval-signal fixture likewise writes to audit_trail while the changed code reads audit_log.

Prompt To Fix With AI
This is a comment left during a code review.
Path: lifecycle/importance_scheduler.py
Line: 99

Comment:
**Scheduler fixtures retain old schema**

When the scheduler tests run, this query selects `entry_id` from a fixture that still defines `core_memory.id`, causing `sqlite3.OperationalError: no such column: entry_id`; the retrieval-signal fixture likewise writes to `audit_trail` while the changed code reads `audit_log`.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Fix in Codex

FROM core_memory
WHERE user_id=? AND updated_at > ?""",
(user_id, time.time() - self.cfg.only_recent_days * 86400),
)
).fetchall()

for r in rows:
rc = await self._lookup_retrieval_count(conn, "core_memory", int(r["id"]))
rc = await self._lookup_retrieval_count(conn, "core_memory", int(r["entry_id"]))
signals = self.scorer.score(
text=r["value"] or "",
kind=r["memory_kind"] or "fact",
Expand All @@ -117,8 +117,8 @@ async def _rescore_user(self, user_id: str, conn, stats: dict) -> None:
continue
now = time.time()
await conn.execute(
"UPDATE core_memory SET importance=?, updated_at=? WHERE id=?",
(new_score, now, int(r["id"])),
"UPDATE core_memory SET importance=?, updated_at=? WHERE entry_id=?",
(new_score, now, int(r["entry_id"])),
)
await conn.execute(
"""INSERT INTO importance_audit
Expand All @@ -127,7 +127,7 @@ async def _rescore_user(self, user_id: str, conn, stats: dict) -> None:
VALUES (?, ?, ?, ?, ?, ?, ?, ?)""",
(
user_id,
int(r["id"]),
int(r["entry_id"]),
"core_memory",
old_score,
new_score,
Expand All @@ -150,7 +150,7 @@ async def _rescore_user(self, user_id: str, conn, stats: dict) -> None:
async def _lookup_retrieval_count(conn, source: str, source_id: int) -> int:
row = await (
await conn.execute(
"""SELECT COUNT(*) c FROM audit_trail
"""SELECT COUNT(*) c FROM audit_log
WHERE action='recall_useful' AND layer=? AND target_id=?""",
(source, str(source_id)),
)
Expand Down
16 changes: 14 additions & 2 deletions mcp_server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,14 @@ async def lifespan(server: FastMCP):
await asyncio.to_thread(read_only_replica.sync)

ctx = AppContext()
backup_cron.start()
importance_scheduler.start()
async def _delayed_start():
await asyncio.sleep(5)
backup_cron.start()
importance_scheduler.start()
logging.getLogger(__name__).info("Background tasks started after delay")
asyncio.create_task(_delayed_start())

# Disabled for startup speed debug

# Periodic maintenance tasks
async def _periodic_tasks():
Expand Down Expand Up @@ -177,6 +183,12 @@ def _run_with_dashboard(host: str, port: int):
from shared.metrics import metrics as m

ctx = AppContext()
async def _delayed_start():
await asyncio.sleep(5)
backup_cron.start()
importance_scheduler.start()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Dashboard task lacks event loop

When dashboard mode starts through the synchronous entrypoint, asyncio.create_task() executes before uvicorn.run() creates an event loop, causing RuntimeError: no running event loop and preventing the server from starting.

Prompt To Fix With AI
This is a comment left during a code review.
Path: mcp_server/server.py
Line: 189

Comment:
**Dashboard task lacks event loop**

When dashboard mode starts through the synchronous entrypoint, `asyncio.create_task()` executes before `uvicorn.run()` creates an event loop, causing `RuntimeError: no running event loop` and preventing the server from starting.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Fix in Codex

logging.getLogger(__name__).info("Background tasks started after delay")
asyncio.create_task(_delayed_start())
dashboard = Dashboard(mm=ctx.mm)
api_rate_limiter = RateLimiter()
ws_limiter = ConnectionLimiter()
Expand Down
Loading