Skip to content

fix(terminal): restore PROMPT_COMMAND when a system profile appends to it - #37699

Closed
bolichen97 wants to merge 1 commit into
mainfrom
crew/CommunityCrew/ci-ubuntu2604-backend
Closed

bolichen97 wants to merge 1 commit into
mainfrom
crew/CommunityCrew/ci-ubuntu2604-backend

Conversation

@bolichen97

@bolichen97 bolichen97 commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: Fork PRs on the ubuntu-26.04 runner pass Backend Tests again, and a Kiro Crew terminal on a systemd-snippet distro gets its inherited PROMPT_COMMAND back.

On the kirocrew-linux-4-core fork runner (now ubuntu-26.04, bash 5.3.9), Backend Tests (3.12, 7) fails on every fork PR (example: run 43724230771, job 132874134510, on #37626):

  • test_ws_bash_keeps_a_profile_appended_prompt_command: the profile's own PROMPT_COMMAND element did not survive the readiness hook's self-withdrawal
  • test_ws_bash_restores_an_inherited_prompt_command: the gateway's exported PROMPT_COMMAND was not restored after the readiness hook withdrew

Why it matters

Every fork PR is red on a lane it did not touch. It is also a real product bug on any distribution that ships systemd's OSC 3008 profile snippet (Ubuntu 26.04 among them): the readiness hook never withdraws from PROMPT_COMMAND, and an operator's exported PROMPT_COMMAND (for example history -a) is never restored as element zero.

Not a goal

  • Moving fork jobs to the credentialed codebuild runner, or changing the main-SHA checkout or credential boundary.
  • The codex sandbox lane and the Playwright install on 26.04 (already fixed on main).
  • Any other ubuntu-26.04 difference.

What changed (motivation → approach → change)

Symptom → cause: on 26.04, /etc/profile.d/80-systemd-osc-context.sh runs in every login Bash and appends __systemd_osc_context_precmdline to PROMPT_COMMAND. The readiness hook in src/kiro_crew/dashboard/handlers/terminal.py only withdrew when there was no element one. So it stayed in element zero, and the inherited command was never put back.

Change: when later elements exist, the hook now rewrites element zero alone, to the inherited command or to an empty element (the same placeholder systemd uses). With no later element it unsets the variable, as before. Every element a profile added is kept. The profile-append PTY test now reads the last element, because the system profile may add its own element first. The spec paragraph on terminal input readiness in docs/system-specs/modules/learn-cron-dashboard.md is updated to match.

Backwards compatibility

Compatible: the hook only changes what it does with its own element zero. Every other element is kept, and the hook-alone case still unsets the variable.

Removes nothing: no key, path or check is removed; the hook text it leaves behind was inert.

Tests

  • test_ws_bash_restores_an_inherited_prompt_command is parametrized with a profile that appends an array element. That case is red on main on any Bash host, and green here.
  • test_ws_bash_keeps_a_profile_appended_prompt_command checks the last element instead of index one.
  • The hook-string unit test asserts the new withdrawal shape.

Proof: PROVEN test/test_terminal_handler_pty_integration.py::TestTerminalWsIntegration::test_ws_bash_restores_an_inherited_prompt_command[PROMPT_COMMAND+=(true)\n], test/test_terminal_handler_session_state.py::TestBashShellReadiness::test_ready_hook_is_a_single_shot_self_removing_prompt_command (head aea85eb)

Determinism: the changed test files passed 5 times in a row with -n 4, and once serially in a shuffled order.

Manual verification

In an ubuntu:26.04 container (bash 5.3.9) with systemd's 80-systemd-osc-context.sh linked into /etc/profile.d, the terminal PTY tests on origin/main fail the same two ways CI does (2 failed, 2 passed). On this branch all 5 pass. Non-fork PRs run on codebuild, so this PR's own CI does not run on the 26.04 runner; the next fork PR after merge does.

Related Issues

Fixes #37647

Sibling sweep

Swept: git grep -n "PROMPT_COMMAND" -- src/
Sibling: src/kiro_crew/acp/client_turn.py -- not affected -- ACP prompt-command allowlist, not the shell variable

Pattern harvest

Not generalizable: the hook assumed no system profile adds a PROMPT_COMMAND element; that is specific to this one shell hook.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title
  • 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

@bolichen97

Copy link
Copy Markdown
Contributor Author

@iamwhatever could you review this one? Our push means our own approval does not count here.

It fixes the last ubuntu-26.04 fork-runner red from #37647 (Backend Tests, bash readiness hook). The codex sandbox part already landed in #37677 and the Playwright part in #37653. Root cause and the 26.04 container repro are in the description.

AI-assisted, sent by Bolin Review bot

@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 aea85eb50d34a467637f51e5447a0b29137748d2 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 aea85eb50d34a467637f51e5447a0b29137748d2 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks. Rewriting only element zero keeps every element a profile appends, so the old [1] pin's purpose still holds.

[DESIGN-REVIEWED] aea85eb

Description read

[DESCRIPTION-READ] 8e76c3c5408daf79cf2638bc108c098e7d807756eab6a74a0a221b33a4d4b0f6

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.

@bolichen97
bolichen97 enabled auto-merge (squash) November 15, 2026 21:12
@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 aea85eb50d34a467637f51e5447a0b29137748d2 — 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 to check. The fix targets the cause: the withdrawal test assumed no profile adds a later PROMPT_COMMAND element. The deleted -z "${PROMPT_COMMAND[1]+x}" pin's purpose, keeping the profile's own element, still holds.

What this change ships

Inventory (5 items) — 5 justified

Intent: A terminal on a distro whose system profile appends to PROMPT_COMMAND gets its exported command back, and fork CI goes green again. FIX.

  1. When a profile has appended elements, the readiness hook now restores the gateway's exported PROMPT_COMMAND (e.g. history -a) in element zero. It used to leave itself there and lose that command. — justified
  2. With no inherited command and later elements present, element zero becomes empty instead of keeping the inert hook. — justified
  3. The profile-append PTY test checks the last element instead of index one. — justified
  4. The inherited-command test gains an array-append case that fails on base. — justified
  5. The terminal-readiness paragraph in the learn-cron-dashboard spec is reworded to match. — justified

[FIRST-PRINCIPLES-REVIEWED] aea85eb

Description read

[DESCRIPTION-READ] 240343be96ab7b064d3157d83313ae2640d660dc384ce3d630151151eb901bd0

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 aea85eb50d34a467637f51e5447a0b29137748d2 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] aea85eb

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

False positive or not applicable? A repository writer can comment:
/ai-review override fable aea85eb50d34a467637f51e5447a0b29137748d2 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 aea85eb50d34a467637f51e5447a0b29137748d2 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] aea85eb

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

…o it

On the ubuntu-26.04 fork runner two Backend Tests failed.

The bash readiness hook withdrew itself only while PROMPT_COMMAND had no
element one. systemd's /etc/profile.d OSC 3008 snippet, which every login
Bash on 26.04 runs, appends one, so the hook stayed in element zero and an
inherited PROMPT_COMMAND was never restored. The withdrawal now rewrites
element zero alone when later elements exist. The profile-append PTY test
probes the last element, since the system profile can add its own first.
@bolichen97
bolichen97 force-pushed the crew/CommunityCrew/ci-ubuntu2604-backend branch from e99100c to aea85eb Compare November 15, 2026 21:37
@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
@KiroCrewCaptain

Copy link
Copy Markdown
Collaborator

Code change approver recommendation: Approve

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

Small, correct fix to the Bash readiness hook. When element zero of PROMPT_COMMAND still equals the exported hook, the hook now restores the inherited command into element zero even if a profile (or systemd's OSC 3008 snippet) added later elements, and sets element zero to empty when there is no inherited command. When the hook is the only element, it still unsets the variable as before. A plain assignment to an array name writes only element zero, so appended elements are kept, and the Bash 3.2-safe syntax is preserved. Tests: the inherited-command PTY test gains an array-append case that fails on main, the append test now reads the last element, and the unit test checking the hook's text is updated. The spec and docstring match the code. CI is 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 aea85eb50d · 66 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 #37697 makes the same fix, and a maintainer has to keep one of the two.

What the review checked on aea85eb:

  • The generated hook was run under Bash 5.2 for every profile shape: unchanged scalar, scalar append, array append, prepend, and outright assignment, each with and without an inherited command. In every case the later elements survive and the mirror and PREV variables are unset. The fail-closed outcomes are the same as on main.
  • TestBashShellReadiness passed (8 tests) and the PTY -k prompt_command tests passed (4 tests). The new parametrized PROMPT_COMMAND+=(true) case fails without the fix on any Bash host.
  • The spec paragraph in learn-cron-dashboard.md matches the code.

Done well: the fix removes one guard and adds one elif. It relies on a bare assignment to an array name writing only element zero, so it needs no Bash 5.1 syntax.

Decision needed: #37697 changes the same _bash_ready_env branch in the same four files. The only difference is the case where nothing was inherited and later elements exist. This PR leaves element zero empty, so the indices stay the same. #37697 drops element zero and moves the rest down. Both cannot land, because whichever merges second conflicts on the same hunk. A maintainer should keep one and close the other with a pointer. If #37697 is kept, #37647 also needs a manual close, because #37697 closes #37693 only.

Optional:

  • The Goal says the shell "gets its inherited PROMPT_COMMAND back". On main the inherited command still ran in the array case, because element zero was <hook>; <inherited>. The visible change is a clean value and a green test.
  • When nothing was inherited, emptying element zero is pinned only by a substring assert. Echoing element zero in test_ws_bash_keeps_a_profile_appended_prompt_command and asserting it is empty would pin it by behaviour.

@bolichen97

Copy link
Copy Markdown
Contributor Author

Closing in favour of #37697, which makes the same fix in the same four files, was opened first, and has merged. The ubuntu-26.04 PROMPT_COMMAND failure is fixed on main by that PR.

AI-assisted, sent by Bolin Review bot

@bolichen97 bolichen97 closed this Nov 15, 2026
auto-merge was automatically disabled November 15, 2026 23:37

Pull request was closed

@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Nov 15, 2026
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.

CI: fork PR jobs fail on the kirocrew-linux-4-core runner's new ubuntu-26.04 image (Playwright install, codex sandbox tests)

2 participants