From c669f12cce2befdfc177ee4925c8ba1a367d9985 Mon Sep 17 00:00:00 2001 From: Ramesh Padmanabhaiah <22363102+codeforester@users.noreply.github.com> Date: Wed, 2 Sep 2026 23:45:24 +0530 Subject: [PATCH] fix(runtime): preserve inherited run bundle ownership --- cli/bash/commands/basectl/basectl.sh | 5 +++++ cli/bash/commands/basectl/tests/runtime-dispatch.bats | 6 +++--- docs/observability.md | 4 +++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/cli/bash/commands/basectl/basectl.sh b/cli/bash/commands/basectl/basectl.sh index c1bfd3e4..802bc638 100644 --- a/cli/bash/commands/basectl/basectl.sh +++ b/cli/bash/commands/basectl/basectl.sh @@ -718,6 +718,11 @@ basectl_finalize_run_bundle() { base_std_log_warn "Skipping finalization for an invalid Base run context." return 1 fi + # Only the invocation that created the bundle owns its finalization. + # Inherited Base children reuse the parent bundle for logs and history but + # must not close it while the parent command is still running. + [[ "${_basectl_run_bundle_created:-0}" == 1 ]] || return 0 + tmp_file="$(mktemp "$run_root/.run.json.XXXXXX")" || return 1 printf '{"run_id":"%s","owner":"base","status":"%s","exit_code":%s,"started_at":"%s","ended_at":"%s"}\n' \ "${BASE_CLI_RUN_ID:-$(basename -- "$run_root")}" \ diff --git a/cli/bash/commands/basectl/tests/runtime-dispatch.bats b/cli/bash/commands/basectl/tests/runtime-dispatch.bats index 038215f8..756d13d8 100644 --- a/cli/bash/commands/basectl/tests/runtime-dispatch.bats +++ b/cli/bash/commands/basectl/tests/runtime-dispatch.bats @@ -206,7 +206,7 @@ load ./basectl_helpers.bash } -@test "basectl reuses a validated internal run bundle" { +@test "basectl reuses a validated internal run bundle without finalizing it" { local cache_root="$TEST_TMPDIR/cache" local inherited_root="$cache_root/base/runs/parent-run__setup" @@ -235,8 +235,8 @@ load ./basectl_helpers.bash [ "$status" -eq 0 ] [[ "$output" != *"Ignoring invalid inherited Base run context"* ]] grep -Fq '"run_id":"parent-run"' "$inherited_root/run.json" - grep -Fq '"status":"ok"' "$inherited_root/run.json" - [ ! -e "$inherited_root/tmp" ] + grep -Fq '"status":"running"' "$inherited_root/run.json" + [ -f "$inherited_root/tmp/private/proof.txt" ] [ "$(find "$cache_root/base/runs" -mindepth 1 -maxdepth 1 -type d | wc -l)" -eq 1 ] } diff --git a/docs/observability.md b/docs/observability.md index e6ff7a22..c5f01eb5 100644 --- a/docs/observability.md +++ b/docs/observability.md @@ -131,7 +131,9 @@ An inherited run bundle is reused only when its physical path is a non-symlink direct child of the active Base cache owner root and its owner, run ID, parent ID, primary log, and running metadata agree. Invalid inherited state is scrubbed without echoing its values, and the invocation receives a fresh local bundle. -The same boundary is checked again before finalization. +The same boundary is checked again before finalization. Only the invocation that +created a bundle finalizes its metadata and removes its temporary directory; +inherited Base children reuse the parent bundle without closing it. Fields should be omitted when unknown instead of guessed.