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
1 change: 1 addition & 0 deletions changes/413.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**Pausing a task stops planning and ignores in-flight watch checks.** Pausing a task while it is being planned now stops before the next model call and leaves a note to resume, resuming picks up planning where it left off. A running watch check that finishes while its task is paused no longer starts an unexpected run.
13 changes: 9 additions & 4 deletions sentient/tasks/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ async def update_task(self, task_id: str, fields: dict) -> None:
sets = ", ".join(f"{k} = ?" for k in data)
await self.store.execute(f"UPDATE tasks SET {sets} WHERE id = ?", (*data.values(), task_id))

async def update_task_if_status(self, task_id: str, statuses: set[str] | list[str], fields: dict) -> bool:
async def update_task_if_status(
self, task_id: str, statuses: set[str] | list[str], fields: dict, *, enabled: bool | None = None
) -> bool:
"""Update only while the task is still in one of ``statuses`` (guards background jobs
against user actions that happened meanwhile). Returns True when a row changed."""
data = {k: v for k, v in fields.items() if k in TASK_COLUMNS}
Expand All @@ -135,9 +137,12 @@ async def update_task_if_status(self, task_id: str, statuses: set[str] | list[st
wanted = list(statuses)
sets = ", ".join(f"{k} = ?" for k in data)
marks = ", ".join("?" for _ in wanted)
cur = await self.store.execute(
f"UPDATE tasks SET {sets} WHERE id = ? AND status IN ({marks})", (*data.values(), task_id, *wanted)
)
where = f"WHERE id = ? AND status IN ({marks})"
params = [*data.values(), task_id, *wanted]
if enabled is not None:
where += " AND enabled = ?"
params.append(1 if enabled else 0)
cur = await self.store.execute(f"UPDATE tasks SET {sets} {where}", tuple(params))
return bool(getattr(cur, "rowcount", 1))

async def delete_task(self, task_id: str) -> None:
Expand Down
Loading
Loading