Skip to content

sc-281: accept recommended target changes after a failed selection - #341

Open
gazdagergo wants to merge 8 commits into
mainfrom
281-recommended-target-button
Open

gazdagergo wants to merge 8 commits into
mainfrom
281-recommended-target-button

Conversation

@gazdagergo

@gazdagergo gazdagergo commented Oct 8, 2026 •

Copy link
Copy Markdown
Collaborator

sc-281: accept recommended target changes after a failed selection

The problem

When an initial or test selection fails, the algorithm suggests min/max changes that would make the targets work, but the failure view gives no way to apply them. You had to open the Targets tab and type the numbers in by hand.

What this does

  • Adjust targets from the failed run. The failed-run modal (db_selection_progress_modal.html) offers Adjust targets for both initial and test selections. It opens the targets check in edit mode (targets/check?from=selection&run_id=…&edit=1), with the check already run and each suggestion shown under the target it applies to. A failed test selection adds test=1.
  • One-click accept, editable comment. Each suggestion row has a pre-filled comment (e.g. "Accepted algorithm suggestion — minimum 8 → 7") that you can edit before clicking Accept. Accept fills in both the new number and the comment, and has Undo. Accept all suggestions does every row at once. Nothing is saved until Save. Two suggestions on the same target join their comments with "; " instead of overwriting.
  • Re-run, gated on where you came from. Only when you arrived from a failed run do you get Save & re-run selection and Accept all & re-run selection. A failed test selection gets …re-run test selection and re-runs as a test selection, never as the real one (start_db_select_task(test_selection=…)). A direct visit to the targets page shows the suggestions but no re-run.
  • Read-only view too. Outside edit mode, Accept posts to the new POST /targets/accept-suggestions. That route works the suggestion out again on the server with check_targets_detailed() and saves it through the existing update_target_value().
  • Reusable suggestion row. backoffice/components/suggestion_row.html (and the suggestionRow Alpine component) has three modes: message only, save on accept, and fill in on accept. It's documented on the showcase page.

Tests

  • tests/component/test_target_suggestions.py: the accept route, edit-mode entry, save & re-run, initial vs test re-run, and the modal links.
  • src/js/components/suggestion-row.test.js: accept, combining comments, and undo.
  • Checked by hand in the browser on a dev assembly with infeasible quotas.

Notes

  • Hungarian translations for the new strings are still empty; the catalogue has been regenerated.
  • backend/docs/agent/sc-281-* (plan + mockup) are still in the PR. They can be dropped before merge if we don't want to keep them.
  • Related: sc-447 (replacement accept UX, done), sc-695 (lock targets).

🤖 Generated with Claude Code

https://claude.ai/code/session_012x8xa4i725xyzCWtWJkziJ

@codecov

codecov Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!


function suggestions() { var o=[]; model.forEach(function(c){ c.values.forEach(function(v){ if(v.sug) o.push({c:c,v:v}); }); }); return o; }
function pendingList() { var o=[]; model.forEach(function(c){ c.values.forEach(function(v){ if(v.pending) o.push({c:c,v:v}); }); }); return o; }
function esc(s){ return CSS.escape(s); }
@gazdagergo gazdagergo changed the title sc-281: implement recommended target changes button (plan + mockup) sc-281: accept recommended target changes after a failed selection Oct 20, 2026
gazdagergo and others added 7 commits October 20, 2026 12:48
…utton

sc-281 adds Accept / Accept all / Accept all & re-run-selection buttons to
the targets Check page, so an organiser can apply the algorithm's
recommended min/max relaxations in one click instead of retyping them.

The plan maps the change onto the existing feasibility and target-save
services (reusing check_targets_detailed and update_target_value), and the
standalone HTML mockup gives Hamish a clickable before/after prototype plus
user-flow and data-flow diagrams for review.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X12D2pPnMTbVGriEVMRcJL
Reworks the plan and mockup after Hamish's review. The journey now starts
where the problem actually surfaces — a failed initial selection — with an
"Adjust targets" link into the targets check rather than assuming the
organiser is already on the targets page.

Adds the audit comment recorded on accept (the mockup demonstrates both
candidate behaviours, auto-written and review-before-save, via a toggle),
and gates the "Accept all & re-run selection" button on having arrived from
a selection run.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X12D2pPnMTbVGriEVMRcJL
A failed initial selection used to be a dead end: the run showed which
minimums and maximums to relax, but applying them meant retyping each one in
the Targets editor from a second tab.

The failed-run modal now offers "Adjust targets", which opens the targets
check with the suggestions showing. Each suggestion has an Accept button that
reveals a pre-filled, editable comment and, on save, applies just that value;
"Accept all" applies them together, and "Accept all & re-run selection" also
starts a fresh run — the latter only when the organiser arrived from a run.

The new accept-suggestions route re-derives the suggestions itself rather than
trusting the posted numbers, and applies them through the existing
update_target_value, so the manual-override and validation rules are unchanged.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X12D2pPnMTbVGriEVMRcJL
A full-width table row that offers one suggested change to the row above it.
The comment saved with the change is pre-filled and editable from the start,
so accepting is a single click rather than an Accept that opens an editor and
a Save that applies it.

Accept does one of two things, chosen by what the caller passes:

- action: the row is a form, and Accept posts the comment and hidden fields,
  for views that save each change as it is made;
- apply: a map of input id to value, which Accept writes into the page's
  inputs, firing input on each so totals and the leave guard hear of it.
  Nothing is saved until the page's own Save; Undo puts back whatever has not
  been typed over, and a suggestions-accept-all window event accepts every
  row at once.

With neither, the row just shows the suggestion. All three appear in the
component showcase.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012x8xa4i725xyzCWtWJkziJ
…uggestion

"Adjust targets" on a failed initial selection now opens the targets page in
edit mode, with each of the algorithm's suggestions as a suggestion row under
the value it would change. Accept writes the suggested min or max and the
pre-filled, editable comment into that row in one click; "Accept all
suggestions" does every row. The edits are saved with the form like any other.

When the organiser came from a run, the save bar also offers "Save & re-run
selection", which saves and starts a fresh initial selection. A plain save
keeps the from/run_id provenance, so the check it lands on can still offer
the re-run, and discarding returns to that check rather than to a page
without the suggestions.

The read-only view uses the same row: there Accept saves the one change
through accept-suggestions straight away, replacing the Accept-then-Save
editor. Suggestions are now tinted as warnings, matching their badge, and
accepting keeps the scroll position.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012x8xa4i725xyzCWtWJkziJ
A failed test selection now offers "Adjust targets" as well. The link
carries test=1, and the targets page passes it through its forms and
redirects, so "Save & re-run" and "Accept all & re-run" start a test
selection again rather than the real one.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012x8xa4i725xyzCWtWJkziJ
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012x8xa4i725xyzCWtWJkziJ
@gazdagergo
gazdagergo force-pushed the 281-recommended-target-button branch from e0455ab to 1ccfe43 Compare October 20, 2026 10:55
@gazdagergo
gazdagergo requested a review from foobacca October 20, 2026 13:27
@gazdagergo
gazdagergo marked this pull request as ready for review October 20, 2026 13:27
…are not as expected

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012x8xa4i725xyzCWtWJkziJ
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.

1 participant