Skip to content

fix(autonudge): make the stale-goal 409 reachable from the goal popover - #19592

Merged
buluoray merged 1 commit into
mainfrom
fix/autonudge-stale-baseline-11786
Oct 13, 2026
Merged

buluoray merged 1 commit into
mainfrom
fix/autonudge-stale-baseline-11786

Conversation

@buluoray

@buluoray buluoray commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: A goal saved in one window is no longer silently overwritten by a stale save from another window's goal popover.

The store's stale-baseline check (#10973) never fired for dashboard saves. PATCH /api/autonudge/{loop_id} did not forward expect_fingerprint, and the popover never sent a baseline. So two open popovers on the same goal were last-write-wins, and the 409 the check was built to raise was unreachable. Its text was also wrong: "The goal changed in another window" is false on the first save after a gateway restart, because goal_token is re-minted on every load.

Why it matters

A user editing a goal loses a newer goal written from another tab with no sign that anything happened. The recurring instruction that drives unattended turns then runs on text nobody chose last.

Not a goal

  • A redaction notice, an overwrite-confirm dialog, or a preview of the newer stored goal (all of which feat(website): warn on a redacted save and gate an overwrite in AutoNudgePopover #11027 also carried).
  • Changing which reads publish goal_token. Plain and gated loops already serve it on the REST reads; structured monitors keep withholding it and never use this route.
  • Putting goal_token on the autonudge_state websocket frame.
  • Fencing cadence-only saves (idle_secs, max_cycles, active): the token identifies the goal text.

What changed (motivation → approach → change)

Symptom: a second window's save always lands. Root cause: the route dropped expect_fingerprint and the client had no baseline to send. The client also cannot take one from the loop prop, because that record is usually a websocket frame, which carries no token.

  • dashboard/handlers/autonudge.py: the PATCH route forwards a string expect_fingerprint to authorize_and_update_nudge (a non-string is 400 not_a_string, since str(123) would read as a concurrent edit that never happened). The stale refusal is answered with code: goal_stale_baseline so the client can tell it from every other 409.
  • autonudge_authz.py: the refusal text is now STALE_GOAL_BASELINE_ERROR, "Not saved: the goal was changed or reloaded since you opened it…", which is true for both causes.
  • AutoNudgePopover.tsx: on open, reads GET /api/autonudge/slot/{slot_key} for the stored goal_token. If the stored goal already differs from the text the form was seeded from, it records "", a baseline that never matches, so that save is refused instead of landing. It sends the baseline only on a save that carries message, takes the next token from the write's answer, and after a goal_stale_baseline 409 keeps the typed text, shows the refusal through the i18n catalog, and re-reads the stored token so the reader's next press replaces the goal. The refusal names that press by the button's own label, interpolated as {{action}} (for a running loop "Save edits and nudge now"), so the reader knows which control saves and that it also nudges. A press that beats the open read saves unfenced, as every save did before, rather than waiting on a read.
  • autoNudgeLoop.ts: types goal_token.
  • One new catalog key, components.autoNudgePopover.goal_stale_baseline, in all 12 catalogs plus the regenerated pseudolocale.
  • learn-cron-dashboard.md: the AutoNudge section records the contract.

Supersedes #11027 by @rnoack1 (co-author). Review of #11027: it had the root cause right (forward expect_fingerprint, keep the served goal_token as the client baseline, do not lose it to a tokenless frame), but it sits 1,300+ commits behind main on a popover since rewritten and bundles a redaction notice and an overwrite-confirm dialog beyond this issue's T2 scope. This PR rebuilds only that core on current main.

Backwards compatibility

Compatible: a PATCH without expect_fingerprint behaves exactly as before; only a non-string value, which no caller sends, is newly refused (400), and a client that ignores the new code still reads the error string.

Removes nothing: the change adds a forwarded field, a response code and one catalog key; no field, route, key or reader goes away.

Tests

  • test/test_autonudge_patch_stale_baseline.py (real route over a real AutoNudgeService): a goal saved elsewhere after the baseline read is 409 goal_stale_baseline and the newer goal stays stored; a current baseline lands and the answer carries the next token; no baseline keeps the unfenced save; a baseline read before a restart is refused with text that says reloaded and not "another window"; non-string baselines are 400 and write nothing. Removing the forward in the handler reddens 2 of 8.
  • website/src/test/AutoNudgePopover.staleBaseline.test.tsx (fake gateway that compares the fingerprint the way the store does): the open read supplies the baseline for a frame record; a goal saved elsewhere after open is refused, text kept, nothing fired, and the next press replaces it with the re-read token; a stored goal that already differs at open sends "" and is refused; a second save uses the token the first handed back; a cadence-only save carries no baseline; a gateway serving no token stays unfenced. Mutations: not sending the field reddens 4 of 6; adopting the token without the message check reddens the differs-at-open case; dropping the post-409 re-read reddens the replace-on-next-press case.
  • Re-ran unchanged: AutoNudgePopover.test.tsx, SessionAutomationPopover.test.tsx, test_autonudge_fingerprint.py, test_autonudge_banner.py, test_autonudge_handlers_cov80.py, test_r9_owner_gate_refusals.py, test_r9_owner_gate_positive_controls.py; npm run i18n:check, tsc -p tsconfig.app.json, eslint on the changed files.

Manual verification

On a pod booted from this branch (Chromium, headless Playwright): created a session, armed a goal, opened the popover, then saved a newer goal from a second client with that client's own baseline. Typing an edit in the popover and pressing Save edits and nudge now sent {"message": …, "expect_fingerprint": "<token served at open>"}, got the 409, showed the refusal below, kept the typed text, fired nothing, and the stored goal stayed the other client's. Pressing the same button again sent the re-read token, replaced the stored goal with the typed text, fired one nudge and cleared the notice. The restart case is covered by the Python test above, not driven on the pod. Pod torn down afterwards.

Screenshots / video

The refusal in the popover after another client saved a newer goal; it names the button that saves:

Goal popover keeps the typed goal and names the button that replaces the stored goal

The second press of that button replaced the stored goal and nudged (cycle 1, notice gone):

After the second press the goal is saved, a nudge fired and the notice is gone

Related Issues

Closes #11786
Supersedes #11027

Pattern harvest

Rule candidate: review-prompt
Pattern: a concurrency or authorization field added to a store/authorizer chokepoint must also be threaded through every transport route and client that calls it, with a route-level test, or the check is dead code.

Decision for the owner

The decision is how the dashboard goal popover should get a concurrency baseline for its saves, given that the record it is handed is usually a token-less websocket frame. This draft keeps the shipped design: the popover reads the already-served goal_token from the slot route at open and the PATCH route forwards it, rather than putting the token on the ungated frame or replacing the token model.

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

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

@buluoray
buluoray force-pushed the fix/autonudge-stale-baseline-11786 branch 2 times, most recently from 04171d0 to 16a4780 Compare October 12, 2026 23:01
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Oct 12, 2026
@github-actions

github-actions Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — 🟡 CONCERNS

UX-level review of ff18c4bd508f2db079581a038df93cb1157c92c7 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

UX-Verdict: CONCERNS

The refusal tells users to press "Save edits and nudge now", but that button has only an icon on screen and its name appears only in a tooltip.

Watch

  • The notice names a button the user can't see. The copy is Press “{{action}}” again… with action: playName. playName is only the button's aria-label/title (AutoNudgePopover.tsx:1001-1021), and the button itself is the lightning icon. The blind reader on shot-01 said: "it tells me to press a button called 'Save edits and nudge now', but I can't find any button with that name … no idea which button it means". They then guessed it was the lightning button and said "I'd hesitate". This is the only way to recover from the refusal, and every user who hits the conflict sees this notice. Without a clear target, they may never retry, and their edit is lost in practice. Smallest fix: name the button by what's on screen ("Press the ⚡ button again…"), or show the label text on that button while the refusal is visible.
  • Overwriting is a guess. The reader on shot-01: "I can't tell what 'your text' is compared with 'the stored goal'", and "it might replace a goal someone else just changed". The notice asks the user to replace a goal they can't see. The PR rules a preview out of scope, so at minimum the copy should say the other version will be discarded: "…to replace the newer saved goal with your text."

Suggestions

  • Front-load the outcome: change "Not saved: the goal was changed or reloaded since you opened this, and your text is kept." to "Not saved — the goal changed since you opened this. Your text is kept." Leave "reloaded" to the docs; users don't need the mechanism.

[UX-REVIEWED] ff18c4b

Description read

[DESCRIPTION-READ] 9c661c43b1b6672689455ade883c82aea909c9f9a5709b69c652e5da03485c49

That sha256 names everything this verdict read: the PR description, plus the 5 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 Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of ff18c4bd508f2db079581a038df93cb1157c92c7 — 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/CONCERNS are advisory.

First-Principles-Verdict: PASS

Check one thing: the new refusal text also goes to the agent's mcp-directive caller (session_directive_apply.py:1313), where "since you opened it" names a popover the agent never opened.

What this change ships

Inventory (9 items) — 9 justified

Intent: a goal saved in one window can no longer be silently overwritten by an out-of-date save from another window's goal popover. This is a FIX (#11786).

  1. Saving from the popover over a goal that changed elsewhere is now refused, and the typed text is kept — justified
  2. The PATCH route takes expect_fingerprint, and a non-string value gets a 400 — justified
  3. The stale-goal refusal wording changes for every caller, so it no longer claims "another window" after a gateway restart — justified
  4. The 409 response carries code: goal_stale_baseline — justified
  5. Opening the popover now fetches the stored goal token in the background — justified
  6. If the stored goal already differs from the text shown when the popover opens, a save from it is refused — justified
  7. After a refusal, the next press of the same button replaces the stored goal, and the refusal message names that button — justified
  8. The goal_token field is added to the AutoNudgeLoop type — justified
  9. The AutoNudge section of learn-cron-dashboard.md now records the contract — justified

Root-cause depth: authorize_and_update_nudge has two callers, found by grepping authorize_and_update_nudge\(. session_directive_apply.py already forwarded the baseline, and this PR threads it through the other one, the PATCH handler. That leaves 0 unfixed callers.

[FIRST-PRINCIPLES-REVIEWED] ff18c4b

Description read

[DESCRIPTION-READ] 2449b65b70fa990fd298426851df2e49bc5e23301cd4a2aa2cc794afbd0866bf

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 Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of ff18c4bd508f2db079581a038df93cb1157c92c7 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: PASS

Check one thing before merge: after the 409, the user's next press replaces a newer goal they were never shown, and the refusal text asks them to press again.

[DESIGN-REVIEWED] ff18c4b

Description read

[DESCRIPTION-READ] 6b0fa8b21b5080ed48cbb9732ee1b8c12cf7cf53569eecc385c4c0a48a50f30a

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 Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] ff18c4b

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

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

@buluoray
buluoray force-pushed the fix/autonudge-stale-baseline-11786 branch from 16a4780 to ffcc2e2 Compare October 12, 2026 23:26
@github-actions

github-actions Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings (all downgraded on adjudication)

GPT 6.1 flagged blocking issues on ff18c4bd508f2db079581a038df93cb1157c92c7; Opus 5.5 adjudication downgraded every one of them to advisory. Adjudication downgraded all 1 blocking finding(s) to advisory: the remedy each one requires is disproportionate to the harm it prevents. Read them as advice, not as merge conditions.

This comment is updated in place on each push.

Review details

BLOCKING -- website/src/components/AutoNudgePopover.tsx:199 -- Baseline-read failures are silently discarded

if (!resp?.ok) return and await resp.json().catch(() => ({})), followed by an empty catch.
A connection failure during the open-time slot GET -> readGoalBaseline suppresses the error and leaves the baseline null -> no failure notice, and subsequent goal saves omit expect_fingerprint.
Anchor: errors-use-error-notice
Fix: Route HTTP, decoding, and network failures through setError and the existing ErrorNotice; preserve the fallback for successful responses without a token.

[BLOCK-MERGE-DOWNGRADED] ff18c4b
[GPT-REVIEWED] ff18c4b

Adjudication (Opus 5.5) — is blocking on each finding proportionate?

F1: DOWNGRADE. I rate the harm LOW.

  • What has to happen, and what follows: the user opens the popover on a loop and the slot GET fails (AutoNudgePopover.tsx:197-199, catch at :208). The baseline stays null (:195), so the save at :519-521 goes out without expect_fingerprint. That is the same unfenced overwrite every save did before this PR, and the code comment at :183-184 says so on purpose for older gateways. Real harm also needs another writer to change the goal while the read is failing. Nothing is lost silently beyond what was already possible, a network fault that bad usually fails the save too, and that error reaches the user via setError (:416) and ErrorNotice (:934).

  • The rule anchor doesn't apply: errors-use-error-notice (.review-base-rules/website-AUTOSDE.yaml:619-645) is about how an error is shown once it is shown: through ErrorNotice, not hand-written markup. It doesn't require every best-effort background read to show a failure, and nothing here shows a failure by hand.

  • Cost of the fix: it would put a permanent error banner in an editable form over an optional fence. That turns a silent fallback, built to be harmless, into a failed-state UI with its own dismiss and retry design. The cost is higher than the harm it prevents.

    [ADJUDICATION] ff18c4b total=1 uphold=0 downgrade=1
    DOWNGRADE F1 website/src/components/AutoNudgePopover.tsx:199 reason=disproportionate-remedy
    [GPT-ADJUDICATED] ff18c4b

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

@buluoray
buluoray force-pushed the fix/autonudge-stale-baseline-11786 branch from ffcc2e2 to 7f26e89 Compare October 13, 2026 00:18
@buluoray

Copy link
Copy Markdown
Contributor Author

UX review on ffcc2e2, addressed in 7f26e89:

  • Blocker, recovery action not findable: fixed. The refusal now names the control by its own label, interpolated from the same string the button's aria-label uses, so it reads "Press “Save edits and nudge now” again to replace the stored goal with your text." The label itself says the press nudges, which answers the "it might send a reminder right away" worry. Verified on a pod: the second press of that button replaced the stored goal, fired one nudge and cleared the notice (second screenshot in the description). An inline "Replace with my text" button was not added, because it would be a second save control beside the existing one and is wider than this PR's scope.
  • Watch, "does saving overwrite theirs": addressed in the copy. It now says the press replaces the stored goal and starts with "Not saved:". Showing the newer goal stays out of scope, as the description's Not a goal section says.

All 12 catalogs were updated in the same commit.

The store's stale-baseline check (#10973) never fired for dashboard saves:
PATCH /api/autonudge/{id} did not forward expect_fingerprint, and the
popover never sent a baseline, so a goal saved in another window was
overwritten last-write-wins.

- The PATCH route forwards a string expect_fingerprint (400 not_a_string
  otherwise) and codes the stale refusal goal_stale_baseline.
- The popover reads the stored goal_token from the slot route when it
  opens (the record it is handed is often a websocket frame with no
  token), sends it only on saves that carry the goal, takes the next one
  from the write's answer, and re-reads after a 409 so the next press
  replaces the goal. A stored goal that already differs from the seeded
  text at open is sent as "" so the save is refused, not landed.
- The refusal text no longer claims another window: the token is
  re-minted on every load, so the first save after a gateway restart is
  refused with no other writer. The popover words it through the i18n
  catalog.

Closes #11786
Supersedes #11027

Co-authored-by: Robert Noack <69695077+rnoack1@users.noreply.github.com>
@buluoray
buluoray force-pushed the fix/autonudge-stale-baseline-11786 branch from 7f26e89 to ff18c4b Compare October 13, 2026 00:45
@buluoray

Copy link
Copy Markdown
Contributor Author

UX review on ff18c4b (CONCERNS, advisory), dispositioned without a push:

  • The notice names a button shown only as an icon: acknowledged, not changed here. The name the notice quotes is the button's accessible name and hover tooltip. A screen-reader user hears exactly that label, and a pointer user sees it on hover, so the notice and the control share one label. The suggested "⚡ button" wording would name a glyph that assistive tech does not announce. Showing a text label on the button while the refusal is visible would change the action row's layout, which this PR does not touch. Left for the owner to rule on.
  • Overwriting is a guess: the copy already says the press replaces the stored goal. Showing the newer goal stays out of scope, as the description's Not a goal section says.
  • Shorter copy without "reloaded": kept as is. A gateway restart rotates the token, so the first save after a restart is refused with no other writer anywhere. Without "reloaded" the notice would tell that user something false.

@buluoray

Copy link
Copy Markdown
Contributor Author

GPT 6.1 on ff18c4b, F1 (downgraded to advisory): a failed open-time baseline read is silent. Kept as is. A failed read leaves the save unfenced, which is exactly how every dashboard save behaved before this PR, so the failure loses nothing that was protected. An error banner for an optional background read would put a failed-state notice in an editable form that the user cannot act on. This agrees with the adjudication.

@buluoray
buluoray marked this pull request as ready for review October 13, 2026 01:44
@buluoray
buluoray requested review from a team and KiroCrewCaptain as code owners October 13, 2026 01:44
@buluoray
buluoray requested a review from mbriones98 October 13, 2026 01:44
@buluoray
buluoray enabled auto-merge (squash) October 13, 2026 01:44
@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 13, 2026

@iamwhatever iamwhatever 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.

This PR makes the store's existing stale-goal check work for dashboard saves. Before, PATCH /api/autonudge/{loop_id} dropped expect_fingerprint and the popover had no baseline, so two windows were last-write-wins. That root cause is fixed. The route now forwards a string baseline (a non-string is 400), and the stale refusal carries code: goal_stale_baseline. On open, the popover reads goal_token from the slot route, because the websocket frame carries none. It sends the token only on a save that includes message, adopts the next token from the write's answer, and re-reads after a 409 so the next press replaces the goal. I tried to break the fence. The "already differs at open" case sends "", and the real store (autonudge_service/mutations.py:672) refuses an empty fingerprint under its lock, so it cannot slip through as "absent". Cadence-only saves and pause send no baseline and never move it. A late open-read is dropped by baselineGen, and a press that beats the read falls back to the old unfenced save, so nothing that was protected before loses protection. The GPT finding (a failed open-read is silent) was correctly downgraded and answered, because that path is the pre-PR behaviour. The UX CONCERNS (the notice quotes an icon button's accessible name) is advisory and was answered with reasoning. PR Readiness is green on the current head after a transient publish-job failure, and the PR is mergeable on main. — crew-pr-reviewer (deep re-check)

@buluoray
buluoray merged commit c6d4138 into main Oct 13, 2026
103 of 104 checks passed
@buluoray
buluoray deleted the fix/autonudge-stale-baseline-11786 branch October 13, 2026 02:47
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 13, 2026
@bolichen97 bolichen97 mentioned this pull request Oct 17, 2026
5 tasks done
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.

Stale-baseline 409 for auto-nudge goal saves is unreachable from the dashboard popover

2 participants