Skip to content

fix(terminal): withdraw the readiness hook from a PROMPT_COMMAND array - #37697

Merged
bolichen97 merged 1 commit into
mainfrom
fix/terminal-ready-hook-array-withdraw
Nov 15, 2026
Merged

bolichen97 merged 1 commit into
mainfrom
fix/terminal-ready-hook-array-withdraw

Conversation

@iamwhatever

@iamwhatever iamwhatever commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: On systemd hosts, the dashboard terminal's one-shot readiness hook removes itself from PROMPT_COMMAND after the first prompt, as it already does elsewhere.

systemd's /etc/profile.d/80-systemd-osc-context.sh appends __systemd_osc_context_precmdline to PROMPT_COMMAND as an array on every login Bash (Ubuntu 26.04 ships it). The hook then sees a second element and skips its withdrawal. Its text stays in PROMPT_COMMAND[0] for the whole session, and an inherited PROMPT_COMMAND is never restored as its own value. The ubuntu-26.04 CI runner shows it: Backend Tests (3.12, 7) fails test_ws_bash_keeps_a_profile_appended_prompt_command and test_ws_bash_restores_an_inherited_prompt_command, which blocks PRs that land on that runner (#37626, #37627).

Why it matters

Every Bash tab on a systemd host carries Kiro Crew's hook and its KIROCREW_TERMINAL_READY_* names forever, and the operator's own exported PROMPT_COMMAND stays glued behind it. CI on the ubuntu-26.04 image is red for every PR until this lands.

Not a goal

  • No change to the readiness barrier, the marker, or the fail-closed path when a profile ASSIGNS PROMPT_COMMAND.
  • No change to the scalar-append case (PROMPT_COMMAND="$PROMPT_COMMAND; ..."), where the hook still stays by design.
  • No test isolation from /etc/profile.d: these tests run the real login chain on purpose.

What changed (motivation → approach → change)

Symptom: hook text left in PROMPT_COMMAND[0] on systemd hosts. Cause: withdrawal required PROMPT_COMMAND[1] to be unset, so any array (systemd's, or a profile's +=(...)) kept the hook. Change: while element zero is still the exported hook, it drops only element zero. With an inherited command it puts that command back in element zero; with none and more elements it shifts the rest down, which is the array the profile chain builds with no hook; a lone scalar is still unset. The docstring and the terminal readiness spec paragraph say the same.

Backwards compatibility

Compatible: only the hook's own element changes; every profile-added element keeps running in order.

Removes nothing: the only thing taken out of PROMPT_COMMAND is Kiro Crew's own one-shot hook, which the spec already says must withdraw.

Tests

  • test_ws_bash_keeps_a_profile_appended_prompt_command: profile now appends two elements (: then true), the shape systemd makes, so every runner exercises it. Probe reads the LAST element (systemd adds one in front) and also prints the whole array, asserting the hook text is gone.
  • test_ready_hook_is_a_single_shot_self_removing_prompt_command: pins the new array branch.
  • test_ws_bash_restores_an_inherited_prompt_command: unchanged; it is the second red on the ubuntu-26.04 runner and passes with the fix.

Proof: PROVEN test/test_terminal_handler_pty_integration.py::TestTerminalWsIntegration::test_ws_bash_keeps_a_profile_appended_prompt_command, test/test_terminal_handler_session_state.py::TestBashShellReadiness::test_ready_hook_is_a_single_shot_self_removing_prompt_command (head d3d8a29)

Determinism: the changed tests passed 3 of 3 repeats; all 513 tests in test/test_terminal_handler*.py pass.

Manual verification

Drove a real Bash 5.2 with the exported hook env for 8 shapes (systemd+user array, user array, none, scalar append; each with and without an inherited PROMPT_COMMAND) and read declare -p PROMPT_COMMAND after the first prompt. On main the hook stayed in element zero for all 4 array shapes. With this change those 4 end as [0]="sysd" [1]="true", [0]="true", [0]="builtin printf PREV" [1]="sysd" [2]="true" and [0]="builtin printf PREV" [1]="true"; the scalar shapes are unchanged.

Related Issues

Closes #37693

Sibling sweep

Swept: git grep -n "PROMPT_COMMAND" -- src
Siblings: none -- the readiness hook in src/kiro_crew/dashboard/handlers/terminal.py is the only code that edits a shell PROMPT_COMMAND; the other hits are the unrelated ACP prompt-command allowlist.

Pattern harvest

Not generalizable: a one-off assumption that an exported scalar stays a scalar through the login profile chain.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

@iamwhatever
iamwhatever requested review from a team and KiroCrewCaptain as code owners November 15, 2026 21:08
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Nov 15, 2026
@github-actions

github-actions Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision d3d8a294133a7bf5da13b8b6e87b721095ad7cf1 touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Does not block merge.

@github-actions

github-actions Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of d3d8a294133a7bf5da13b8b6e87b721095ad7cf1 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks: the fix removes only the hook's own element zero, keeps every element a profile added, and still parses on Bash 3.2.

[DESIGN-REVIEWED] d3d8a29

Description read

[DESCRIPTION-READ] 7b679fd32ac01c85a196915ab3170ad5cb877202e4fe693aad8623371c8d711e

That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of d3d8a294133a7bf5da13b8b6e87b721095ad7cf1 — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

First-Principles-Verdict: PASS

Nothing blocks. This is a fix with a linked issue (#37693) and two CI tests that fail on the ubuntu-26.04 runner. It targets the mechanism that caused them: the withdrawal check that refused to act on any array.

What this change ships

Inventory (4 items) — 4 justified

Intent: on systemd hosts, the terminal readiness hook should remove itself after the first prompt and give back the operator's inherited PROMPT_COMMAND. FIX.

  1. When a profile has appended array elements to PROMPT_COMMAND, the hook now drops only its own element zero and the profile's elements keep running. — justified
  2. When the operator exported a PROMPT_COMMAND of their own, it is put back in element zero on array-shaped hosts. — justified
  3. The integration test's profile now appends two elements, the shape systemd builds, and asserts the hook text is gone. — justified
  4. The spec paragraph and docstring now describe the withdrawal from element zero. — justified

The old pin's stated reason was "unsetting there would take the user's own element with it". The change keeps that reason intact, so this is not a reversed decision. A grep for PROMPT_COMMAND across src found 7 files. The only one that edits the shell variable is dashboard/handlers/terminal.py, so there are no unfixed siblings.

[FIRST-PRINCIPLES-REVIEWED] d3d8a29

Description read

[DESCRIPTION-READ] c7e7f92b05353785f28fe6129df8681b3e8106c06d78dc27da917dc8660d3807

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

github-actions Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed d3d8a294133a7bf5da13b8b6e87b721095ad7cf1 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] d3d8a29

Verdict parsed from the review's SHA-scoped output markers for commit d3d8a294133a7bf5da13b8b6e87b721095ad7cf1.

False positive or not applicable? A repository writer can comment:
/ai-review override fable d3d8a294133a7bf5da13b8b6e87b721095ad7cf1 false-positive: <reason, 20 to 500 characters>

@github-actions

github-actions Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of d3d8a294133a7bf5da13b8b6e87b721095ad7cf1 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] d3d8a29

False positive or not applicable? A repository writer can comment:
/ai-review override gpt d3d8a294133a7bf5da13b8b6e87b721095ad7cf1 false-positive: <reason, 20 to 500 characters>

systemd's /etc/profile.d OSC-context script appends to PROMPT_COMMAND as
an array on every login Bash. The readiness hook then saw a second
element and skipped its withdrawal, so its text stayed in element zero
for the whole session and an inherited PROMPT_COMMAND was never
restored. The hook now drops only element zero: replaced by the
inherited command when there is one, else removed with the rest shifted
down.

Closes #37693
@iamwhatever
iamwhatever force-pushed the fix/terminal-ready-hook-array-withdraw branch from 1a0706b to d3d8a29 Compare November 15, 2026 21:21
@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Nov 15, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor Author

#37699 fixes the same red (the ubuntu-26.04 runner's systemd /etc/profile.d appends to PROMPT_COMMAND as an array, so the readiness hook never withdraws). Both PRs change the same hook branch in the same way and differ in one case only: with no inherited command, #37699 sets element zero to "" and keeps the indices, while this PR removes element zero and shifts the rest down. Maintainer: please keep one and close the other.

@KiroCrewCaptain

Copy link
Copy Markdown
Collaborator

Code change approver recommendation: Approve

Why: the decider estimates an 8% chance that this change introduces a defect, within the 12% limit for approving on its own, and every check passes.

The PR changes the one-shot Bash readiness hook so it also withdraws itself when a profile has turned PROMPT_COMMAND into an array, which systemd's profile.d script does on every login shell. While element zero is still the exported hook: with an inherited command, only element zero is overwritten with it; with none and a single element, the variable is unset as before; otherwise element zero is dropped and the rest move down. Bash runs prompt-command elements from a copy taken before running any of them, so every element still runs on the first prompt. systemd's empty first element is kept, which gives exactly the layout it would build with no hook. The syntax parses on Bash 3.2, and the macOS suites passed. The scalar-append and assignment cases behave as on main. The integration test now builds a two-element array and asserts the hook text is gone; that check fails on main on any runner. A unit test pins the new branch. The spec and docstring were updated to match. All CI checks are green.

An automated recommendation, not a review: a maintainer still decides. It approves on its own only when the estimated chance of a defect is at most 12% and the change has at most 400 changed lines. Decider v3c (217fe607) · commit d3d8a29413 · 63 changed lines. If this recommendation is wrong, reply here: replies are how the approver is evaluated.

@KiroCrewCaptain

Copy link
Copy Markdown
Collaborator

The review found no code defect on this head. It cannot be approved yet because #37699 makes the same fix, and a maintainer has to keep one of the two.

Decision needed: duplicate of #37699 (src/kiro_crew/dashboard/handlers/terminal.py:443). Both PRs start from the same main commit and change the same four files: terminal.py, learn-cron-dashboard.md, test_terminal_handler_pty_integration.py and test_terminal_handler_session_state.py. Both drop the PROMPT_COMMAND[1]+x guard from the same if in _bash_ready_env and add a new branch at the same spot. Both rewrite the same docstring and spec paragraph. Whichever PR merges first makes the other conflict, and its fix is then already on main. The only behaviour difference is the array case with no inherited command. This PR shifts the remaining elements down. #37699 leaves an empty element zero. Both withdraw the hook. Keep one PR and close the other with a pointer. Also close #37693 as a duplicate of #37647, or the reverse. Which PR stays is a maintainer's call. If this one stays, consider carrying over the test from #37699 in the note below.

Optional:

  • test_ws_bash_restores_an_inherited_prompt_command only sets up a scalar profile, so no real shell test covers the path that writes an inherited command back into element zero of an array. A change that drops the profile's array tail on that path still passes every test. fix(terminal): restore PROMPT_COMMAND when a system profile appends to it #37699 adds a PROMPT_COMMAND+=(true) parametrized case that covers it on any Bash 5.1+ host.

@bolichen97 bolichen97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving this head and keeping this one over #37699, which makes the same fix (this one was opened first). I'm closing #37699 with a pointer here.

  • The hook now withdraws element zero only: it is replaced by the inherited command when there is one, otherwise dropped with the rest of the array shifted down. Profile-appended elements (systemd's __systemd_osc_context_precmdline on ubuntu-26.04) survive in every shape.
  • ${PROMPT_COMMAND[1]+x} and ${PROMPT_COMMAND[@]:1} both parse on macOS's Bash 3.2.
  • Ran the readiness and prompt_command tests in test_terminal_handler_session_state.py and test_terminal_handler_pty_integration.py locally: 11 passed. CI on this head: 87 passed, 0 failed, none pending.

Once this merges I'll close #37647 by hand: its three parts are #37653 (Playwright), #37677 (Codex sandbox probe) and this PR.

AI-assisted, sent by Bolin Review bot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Terminal readiness hook stays in PROMPT_COMMAND on systemd hosts

3 participants