From 8ccbd0b14671240b1bd32556f33fc95d31d3b3dd Mon Sep 17 00:00:00 2001 From: Ramesh Padmanabhaiah <22363102+codeforester@users.noreply.github.com> Date: Thu, 3 Sep 2026 14:32:54 +0530 Subject: [PATCH] fix(runtime): keep inherited history parent-owned --- cli/bash/commands/basectl/basectl.sh | 8 +++++++- cli/bash/commands/basectl/tests/runtime-dispatch.bats | 6 ++++-- docs/observability.md | 6 ++++-- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/cli/bash/commands/basectl/basectl.sh b/cli/bash/commands/basectl/basectl.sh index 802bc638..52aa683e 100644 --- a/cli/bash/commands/basectl/basectl.sh +++ b/cli/bash/commands/basectl/basectl.sh @@ -952,7 +952,13 @@ basectl_main() { } else if basectl_finalize_run_bundle "$command_status"; then - basectl_history_record "$command" "$command_status" "$history_scope" "${history_args[@]}" + # Only the invocation that owns the bundle writes its + # completion record. Inherited Base children share the + # parent's log and lifecycle; recording them with the parent + # bundle would mark it complete before the parent returns. + if [[ "${_basectl_run_bundle_created:-0}" == 1 ]]; then + basectl_history_record "$command" "$command_status" "$history_scope" "${history_args[@]}" + fi else basectl_scrub_inherited_run_context fi diff --git a/cli/bash/commands/basectl/tests/runtime-dispatch.bats b/cli/bash/commands/basectl/tests/runtime-dispatch.bats index 756d13d8..96cf91bf 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 without finalizing it" { +@test "basectl reuses a validated internal run bundle without finalizing or recording it" { local cache_root="$TEST_TMPDIR/cache" local inherited_root="$cache_root/base/runs/parent-run__setup" @@ -224,11 +224,12 @@ load ./basectl_helpers.bash BASE_BASH_LIBS_PRIMARY_LOG="$inherited_root/logs/primary.log" \ BASE_CLI_HISTORY_PARENT_RUN_ID=parent-run \ BASE_CLI_HISTORY_SCOPE=internal \ + BASE_TEST_STATE_DIR="$TEST_STATE_DIR" \ bash -c ' source "$BASE_HOME/cli/bash/commands/basectl/basectl.sh" base_std_log_debug() { :; } basectl_do_setup() { return 0; } - basectl_history_record() { :; } + basectl_history_record() { touch "$BASE_TEST_STATE_DIR/history-recorded"; } basectl_main setup ' @@ -237,6 +238,7 @@ load ./basectl_helpers.bash grep -Fq '"run_id":"parent-run"' "$inherited_root/run.json" grep -Fq '"status":"running"' "$inherited_root/run.json" [ -f "$inherited_root/tmp/private/proof.txt" ] + [ ! -e "$TEST_STATE_DIR/history-recorded" ] [ "$(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 c5f01eb5..48e37122 100644 --- a/docs/observability.md +++ b/docs/observability.md @@ -124,8 +124,10 @@ A history record should include: ``` Primary records use `scope: "primary"` and represent the command the user -invoked. Delegated records use `scope: "internal"` and carry that invocation's -`run_id` in `parent_run_id`. +invoked. Inherited Base children do not write separate completion records; +their delegated output remains in the parent's primary log and their lifecycle +remains owned by the parent invocation. Legacy `scope: "internal"` records may +still exist in older history indexes and are ignored by public history views. 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