Skip to content

refactor(dashboard): unchain the warm brief list-field ternary - #23377

Merged
bolichen97 merged 1 commit into
mainfrom
refactor/simplify-dashboard
Oct 23, 2026
Merged

bolichen97 merged 1 commit into
mainfrom
refactor/simplify-dashboard

Conversation

@bolichen97

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: Make the warm-welcome brief's list-field reader in src/kiro_crew/dashboard/warm_task_brief.py read as plain if/elif/else, and pin the two inputs no test sends it (a field sent as one string, and a field sent as an object), with no change in what a brief shows.

On origin/main the sweep's detector reports one actionable chained conditional expression in dashboard/ (it excludes two others: one in a keystone file, one a test pins as text). It is _clean_items, which picks a brief's raw needs_you / next items with a if c1 else b if c2 else d, so the reader has to unpack precedence to see which branch wins.

Why it matters

Nothing is broken today. _clean_items decides which of a model's needs_you / next items reach _clean, the redaction and capping step for the warm-welcome card, so a reader checking that path should see its three cases at a glance. Two of those inputs are unguarded: no existing test sends a list field as one string or as an object, so a later edit could silently drop a model's single-string needs_you, or start turning an object's keys or values into items, and no test would fail.

Not a goal

  • Any change to what a brief accepts, cleans, redacts, caps or shows.
  • Any other code in warm_task_brief.py or elsewhere in dashboard/.
  • Splitting test/test_warm_task_brief.py, which is already over the 1,600-line working target; the one test added here pins an existing function and is not a new responsibility.

What changed (motivation → approach → change)

A warm-welcome brief comes out exactly as before. _clean_items now spells its three cases as statements, in the same order: a string becomes a one-item list, a list is used as is, anything else gives no items. The list[object] annotation on the first branch says what the items can be (a model's JSON list may hold numbers or null; _clean turns those into empty strings, which _clean_items then drops), so mypy does not infer list[str] from that branch alone.

One test sends the two inputs no test sent: a field as one string, and a field as an object.

Backwards compatibility

Compatible: same branches, same order, same results for every input; no signature or return type changes.

Removes nothing: the rewrite keeps every branch and every result, and the test file only gains a test.

Tests

  • Added test_a_list_field_sent_as_one_string_is_one_item_and_an_object_gives_no_items in test/test_warm_task_brief.py: a needs_you sent as one string becomes one item, and a next sent as an object with a string value gives no items (neither its key nor its value becomes one). It passes on origin/main's _clean_items.
  • Mutation check. Against the existing tests, emptying the list branch fails 5 tests, while emptying the string branch, or making the last branch read a dict's keys or its values, fails none. The new test fails each of those three.
  • Determinism. 20 runs at -n0, 10 at -n 4 --dist loadgroup --max-worker-restart=2 beside test/test_slot_running_readers.py, and one shuffled order of both files' 198 ids (seed 14078): all green.
  • Related tests. scripts/run_scoped_tests.py selects test/test_warm_task_brief.py and test/test_slot_running_readers.py: 198 passed (Python 3.12).
  • Static gates (Python 3.12). All exit 0 on the commit: flake8, isort, mypy, the black, subprocess-encoding, comment-history, brand, harness-parity, feature-map and line-cap checks, the docs lint (scripts/docs_lint.py --test, scripts/docs-lint.sh), the per-file coverage self-test, the --test self-tests, the flake-pattern ratchet and the vendor manifest.
  • Not run locally. scripts/scrub-lint.sh is absent from the checkout (CI's internal-content-scan covers it), semgrep is not installed on this host (CI's SAST job runs semgrep/), and the frontend did not run, as nothing under website/, .github/ or scripts/ changed.
  • Pre-PR review. Seven read-only reviewers (repo rules, behaviour, imports, security and boot path, claim accuracy, and local mirrors of the Opus and GPT lanes, the GPT one on a Claude model) found no defect in _clean_items. The behaviour reviewer ran base and head _clean_items over 50,000 fuzzed and 48 chosen inputs with identical results, and the same calls in the same order on the 48; the security reviewer found _clean_items is not a control (anything it does not pick is dropped, never shown) and the file not keystone. Their other findings were the test's object needing a string value so a values mutant fails, and overclaims in this description and the commit message; two independent adjudicators upheld every one, and the diff and this text carry each fix, so none was dropped.

Manual verification

N/A — unit coverage sufficient: a pure function whose three branches are each pinned by a test.

Screenshots / video

Why no screenshot: backend-only refactor; the card renders the same fields from the same values.

Related Issues

Part of #16523

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

Contribution License Agreement

Contributed under the project's Apache-2.0 license; see the Licensing section of CONTRIBUTING.md.

`_clean_items` picked the raw items of a brief's `needs_you` / `next`
field with a chained conditional expression: one string becomes a
one-item list, a list is used as is, anything else gives no items. It
reads as if/elif/else now, with the same three branches in the same
order. The `list[object]` annotation says what the items can be: a
model's JSON list may hold numbers or null, which `_clean` turns into
empty strings that `_clean_items` then drops.

No existing test sends a list field as one string or as an object, so
emptying the string branch, or letting the last branch read an
object's keys or values, fails no existing test. One new test sends
both.
@bolichen97
bolichen97 requested review from a team and KiroCrewCaptain as code owners October 23, 2026 08:10
@github-actions

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision b48caf67860311d18f0dd2d7512bdfca6294a7f8 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 added the readiness: checking Automated validation is still running label Oct 23, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

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

Design-Verdict: PASS

Nothing blocks: it rewrites one ternary into if/elif/else with the same branches and results, and adds one test that pins the two inputs no test covered before.

[DESIGN-REVIEWED] b48caf6

Description read

[DESCRIPTION-READ] 0e284d19225ff0a6f867740d465bae3b57f5cbf9389118597325913229d4e871

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

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of b48caf67860311d18f0dd2d7512bdfca6294a7f8 — 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

This refactor doesn't change what a brief shows, and the added test pins two inputs that had no test before.

What this change ships

Inventory (2 items) — 2 justified

Intent: make the code that picks a brief's needs_you / next items easy to read, and lock in how it handles the two inputs no test sent. ADDITION (refactor plus a test pin).

  1. _clean_items is now plain if/elif/else instead of a chained ternary; same branches, same order, same result for every input — justified
  2. New test: a list field sent as one string becomes one item, and one sent as an object gives no items — justified

[FIRST-PRINCIPLES-REVIEWED] b48caf6

Description read

[DESCRIPTION-READ] 84add4f21821dd38829d74b1b6bae8373fbf39a284958aa7059becd244c5a3fa

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

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

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

Review details

Behaviour-equivalent refactor.

No findings.

[OPUS-REVIEWED] b48caf6

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

False positive or not applicable? A repository writer can comment:
/ai-review override fable b48caf67860311d18f0dd2d7512bdfca6294a7f8: <one-sentence reason>

@github-actions

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

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

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] b48caf6

False positive or not applicable? A repository writer can comment:
/ai-review override gpt b48caf67860311d18f0dd2d7512bdfca6294a7f8: <one-sentence reason>

@bolichen97
bolichen97 enabled auto-merge (squash) October 23, 2026 08:35
@bolichen97

Copy link
Copy Markdown
Contributor Author

green_age.py reports this head's green is older than origin/main: 4 commits (5cc82ba2 -> d2417a48) touch src/kiro_crew/dashboard/handlers/portability.py and test/test_apple_speech.py, which it links to this PR as an import overlap. Neither file names warm_task_brief; the two commits are #23244 (stream SQLite into the portability export) and #22743 (signal waits in a test).

Instead of a push that restarts CI on a base that keeps moving, I proved the tree a merge would produce: this commit cherry-picked cleanly onto d2417a48c1, and there test/test_warm_task_brief.py, test/test_slot_running_readers.py, test/test_apple_speech.py and the four test files that import dashboard/handlers/portability.py gave 531 passed, 4 skipped, 0 failed (Python 3.12, -n 4 --dist loadgroup). flake8 and mypy on the changed source are clean there too. No push.

@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 Oct 23, 2026
@bolichen97

Copy link
Copy Markdown
Contributor Author

Disposition: rebutted (no change needed): the PASS punchline raises no ask, so nothing follows from it.

The punchline restates the PR's own claim: _clean_items keeps its three branches in the same order, and the diff adds one test.
Pre-PR, base and head _clean_items gave identical results over 50,000 fuzzed and 48 chosen inputs, with the same calls in the same order on the 48.

@bolichen97

Copy link
Copy Markdown
Contributor Author

Disposition: rebutted (no change needed): "This refactor doesn't change what a brief shows" and both inventory items judged justified raise no ask, so nothing follows from it.

The inventory matches the diff: one chained conditional expression rewritten as if/elif/else, and one test for a list field sent as one string or as an object.
The test fails when the string branch is emptied or the last branch reads an object's keys or values, and passes on origin/main's _clean_items.

@KiroCrewCaptain KiroCrewCaptain left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Tier 1 auto-approve: refactor (2 files). Criteria: no conflict, no requested changes, security path denylist clean, design-doc gate clean, security checklist all-NO, no reviewer-lane findings, readiness signal fresh for this head SHA, declared category matches the diff. Category: a nested conditional expression becomes an if/elif chain with the same three outcomes, plus a test that pins them.

@bolichen97
bolichen97 merged commit a93a2bf into main Oct 23, 2026
106 checks passed
@bolichen97
bolichen97 deleted the refactor/simplify-dashboard branch October 23, 2026 10:07
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 23, 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.

2 participants