Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

fix(tasks): persist resolved run targets

cyh332d941199da
diff --git a/core/scheduled_tasks.py b/core/scheduled_tasks.py
index 0bbeecc51..541c51bd6 100644
--- a/core/scheduled_tasks.py
+++ b/core/scheduled_tasks.py
@@ -592,6 +592,9 @@ class TaskExecutionStore:
error=error,
completed_at=_utc_now_iso(),
updated_at=_utc_now_iso(),
+ task_id=task_id if task_id is not None else request.task_id,
+ session_key=session_key if session_key is not None else request.session_key,
+ session_id=session_id if session_id is not None else request.session_id,
metadata={"ok": ok},
)
return
diff --git a/storage/background.py b/storage/background.py
index b307e45b5..3325e3a87 100644
--- a/storage/background.py
+++ b/storage/background.py
@@ -164,6 +164,9 @@ class SQLiteBackgroundTaskStore:
stdout: Optional[str] = None,
stderr: Optional[str] = None,
pid: Optional[int] = None,
+ task_id: Optional[str] = None,
+ session_key: Optional[str] = None,
+ session_id: Optional[str] = None,
metadata: Optional[dict[str, Any]] = None,
) -> None:
values: dict[str, Any] = {
@@ -184,6 +187,12 @@ class SQLiteBackgroundTaskStore:
values["stderr"] = stderr
if pid is not None:
values["pid"] = pid
+ if task_id is not None:
+ values["task_id"] = task_id
+ if session_key is not None:
+ values["legacy_session_key"] = session_key
+ if session_id is not None:
+ values["session_id"] = session_id
if metadata is not None:
values["metadata_json"] = _json_dumps(metadata)
with self.engine.begin() as conn:
diff --git a/tests/test_cli_watch_command.py b/tests/test_cli_watch_command.py
index 87ce60f60..65d4c27f9 100644
--- a/tests/test_cli_watch_command.py
+++ b/tests/test_cli_watch_command.py
@@ -99,6 +99,14 @@ def test_watch_add_parser_keeps_top_level_command_name() -> None:
assert args.waiter_command == ["--", "python3", "wait.py"]
+def test_watch_update_parser_accepts_argv_command_replacement() -> None:
+ args = _parse_watch_update(["watch-1", "--", "python3", "wait.py", "--flag", "value"])
+
+ assert args.command == "watch"
+ assert args.watch_command == "update"
+ assert args.waiter_command == ["--", "python3", "wait.py", "--flag", "value"]
+
+
def test_watch_add_missing_command_is_structured_json() -> None:
args = _parse_watch_add(["--session-key", "slack::channel::C123"])
@@ -590,6 +598,39 @@ def test_watch_update_session_key_clears_previous_session_id(tmp_path: Path, cap
assert payload["watch"]["session_key"] == "slack::channel::C456"
+def test_watch_update_replaces_argv_command(tmp_path: Path, capsys) -> None:
+ store = ManagedWatchStore(tmp_path / "watches.json")
+ runtime_store = WatchRuntimeStateStore(tmp_path / "watch_runtime.json")
+ watch = store.add_watch(
+ name="Watch CI",
+ session_key="slack::channel::C123",
+ command=["python3", "wait.py"],
+ shell_command=None,
+ prefix=None,
+ cwd=None,
+ mode="once",
+ timeout_seconds=600,
+ lifetime_timeout_seconds=0,
+ retry_exit_codes=[75],
+ retry_delay_seconds=30,
+ post_to=None,
+ deliver_key=None,
+ )
+ args = _parse_watch_update([watch.id, "--", "python3", "wait_deploy.py", "--flag", "value"])
+
+ with (
+ patch("vibe.cli._ensure_config", return_value=_configured_v2({"slack"})),
+ patch("vibe.cli._watch_store", return_value=store),
+ patch("vibe.cli._watch_runtime_store", return_value=runtime_store),
+ ):
+ result = cli.cmd_watch_update(args)
+
+ assert result == 0
+ payload = json.loads(capsys.readouterr().out)
+ assert payload["watch"]["command"] == ["python3", "wait_deploy.py", "--flag", "value"]
+ assert payload["watch"]["shell_command"] is None
+
+
def test_watch_update_no_changes_returns_structured_error(tmp_path: Path) -> None:
store = ManagedWatchStore(tmp_path / "watches.json")
watch = store.add_watch(
diff --git a/tests/test_scheduled_tasks.py b/tests/test_scheduled_tasks.py
index f867dd4d7..902aefc54 100644
--- a/tests/test_scheduled_tasks.py
+++ b/tests/test_scheduled_tasks.py
@@ -169,6 +169,35 @@ def test_task_execution_store_uses_sqlite_runs_when_root_is_default(tmp_path: Pa
assert not (tmp_path / "state" / "task_requests").exists()
assert saved["status"] == "completed"
assert saved["session_id"] == "sesk8m4q2p7x"
+ assert saved["session_key"] == "slack::channel::C123"
+
+
+def test_sqlite_complete_persists_resolved_run_target(tmp_path: Path) -> None:
+ sqlite = SQLiteBackgroundTaskStore(tmp_path / "state" / "vibe.sqlite")
+ store = TaskExecutionStore(tmp_path / "task_requests")
+ store._sqlite = sqlite
+ request = store.enqueue_hook_send(
+ session_key="slack::channel::C123",
+ session_id=None,
+ prompt="hello",
+ )
+
+ claimed = store.claim(request.id)
+ assert claimed is not None
+ store.complete(
+ claimed,
+ ok=True,
+ task_id="task-1",
+ session_key="slack::channel::C456",
+ session_id="sesk8m4q2p7x",
+ )
+
+ saved = sqlite.get_run(request.id)
+ assert saved is not None
+ assert saved["status"] == "completed"
+ assert saved["task_id"] == "task-1"
+ assert saved["session_key"] == "slack::channel::C456"
+ assert saved["session_id"] == "sesk8m4q2p7x"
def test_store_round_trip_persists_task(tmp_path: Path) -> None:
diff --git a/vibe/cli.py b/vibe/cli.py
index 14248b16a..57ec82568 100644
--- a/vibe/cli.py
+++ b/vibe/cli.py
@@ -60,6 +60,23 @@ class VibeArgumentParser(argparse.ArgumentParser):
self.error_hint = kwargs.pop("error_hint", None)
super().__init__(*args, **kwargs)
+ def parse_args(self, args=None, namespace=None):
+ parsed_args = list(sys.argv[1:] if args is None else args)
+ watch_update_waiter_command = None
+ if self.prog == "vibe" and len(parsed_args) >= 4 and parsed_args[:2] == ["watch", "update"]:
+ try:
+ separator_index = parsed_args.index("--", 3)
+ except ValueError:
+ separator_index = -1
+ if separator_index >= 0:
+ watch_update_waiter_command = ["--", *parsed_args[separator_index + 1 :]]
+ parsed_args = [*parsed_args[:separator_index]]
+
+ parsed = super().parse_args(parsed_args, namespace)
+ if watch_update_waiter_command is not None:
+ setattr(parsed, "waiter_command", watch_update_waiter_command)
+ return parsed
+
def error(self, message):
payload = {
"ok": False,
@@ -3095,6 +3112,7 @@ def build_parser():
)
watch_update_parser.add_argument("--retry-delay", type=float, help="Set retry delay in seconds")
watch_update_parser.add_argument("--shell", help="Replace waiter with a shell command")
+ watch_update_parser.set_defaults(waiter_command=None)
watch_list_parser = watch_subparsers.add_parser(
"list",