diff --git a/scripts/lib/storage.sh b/scripts/lib/storage.sh index 8b629182c..104cc632f 100644 --- a/scripts/lib/storage.sh +++ b/scripts/lib/storage.sh @@ -346,7 +346,12 @@ agmsg_runtime_lock_acquire() { resource="$1"; owner_pid="$2"; expected_owner="${3:-}" case "$owner_pid:$expected_owner" in *[!0-9:]*) return 1 ;; esac db="$(_agmsg_runtime_db_path)" - _agmsg_runtime_db_exists "$db" || return 1 + if ! _agmsg_runtime_db_exists "$db"; then + # Leave a diagnostic (#424). The status stays 1. Keep the words busy and + # locked out of this line: actas-lock.sh retries stderr that matches them. + printf 'agmsg_runtime_lock_acquire: runtime db missing: %s\n' "$db" >&2 + return 1 + fi resource_sql="$(_agmsg_runtime_lock_resource_sql "$resource")" sql=".bail on BEGIN IMMEDIATE; diff --git a/tests/test_storage.bats b/tests/test_storage.bats index 1ad921813..1d1c347f9 100644 --- a/tests/test_storage.bats +++ b/tests/test_storage.bats @@ -213,6 +213,36 @@ SH [ ! -e "$AGMSG_STORAGE_PATH/messages.db" ] } +@test "storage: runtime lock acquire on an absent store says why on stderr and keeps status 1" { + # #424: the refusal used to be silent. + export AGMSG_STORAGE_PATH="$BATS_TEST_TMPDIR/silent-lock-store" + source "$SCRIPTS/lib/storage.sh" + local err="$BATS_TEST_TMPDIR/lock-acquire.stderr" out rc=0 db + db="$(_agmsg_runtime_db_path)" + + out="$(agmsg_runtime_lock_acquire codex-dispatcher:test 111 2>"$err")" || rc=$? + + [ "$rc" -eq 1 ] + [ -z "$out" ] + [ "$(wc -l < "$err" | tr -d ' ')" -eq 1 ] + [ "$(cat "$err")" = "agmsg_runtime_lock_acquire: runtime db missing: $db" ] + [ ! -e "$db" ] +} + +@test "storage: runtime lock acquire on a present store writes nothing to stderr" { + # Negative control for #424: the diagnostic belongs to the absent-store path only. + export AGMSG_STORAGE_PATH="$BATS_TEST_TMPDIR/present-lock-store" + source "$SCRIPTS/lib/storage.sh" + agmsg_storage_ensure_initialized + local err="$BATS_TEST_TMPDIR/lock-acquire-present.stderr" out rc=0 + + out="$(agmsg_runtime_lock_acquire codex-dispatcher:test 111 2>"$err")" || rc=$? + + [ "$rc" -eq 0 ] + [ "$out" = 111 ] + [ ! -s "$err" ] +} + @test "storage: every runtime lock entrypoint refuses an absent store" { export AGMSG_STORAGE_PATH="$BATS_TEST_TMPDIR/absent-lock-store" source "$SCRIPTS/lib/storage.sh"