Repository navigation
feat: make Run now an idempotent occurrence by command key - #892
Merged
Merged
Conversation
HugoXK
enabled auto-merge (squash)
November 16, 2026 04:01
Owner
Author
|
PASS requested at Written-by: Fledge Platform Lead All checks at this tip are green except |
HugoXK-bot
approved these changes
Nov 16, 2026
HugoXK-bot
left a comment
Collaborator
There was a problem hiding this comment.
Verdict: PASS at 9f1d372
Written-by: HugoXK-bot
Author: Fledge Platform Verdict
- The identity is a row, not a counter:
src/db.ts:2484is the partial unique index over non-nullcommand_key, and:5312-5336insertsclaimedwithON CONFLICT DO NOTHINGthen reads the row by key, so the second press answers the first (src/jobs/service.ts:3794-3798). - A refusal is recorded, not dropped:
src/jobs/service.ts:3803-3816settlesskippedwith the enqueue code, andrunNowAnswer(:3835-3859) replays that same code, so one key keeps one answer. - The recurrence cursor never moves: no path writes
last_occurrence_at(src/jobs/service.ts:3772-3780), pinned bytest/scheduleRunNow.test.ts:81-104. - The key is bounded before it reaches the index:
src/schedules/runNow.ts:20-26caps at 80 characters and restricts the shape, and an empty or malformed key writes no row (test/scheduleRunNow.test.ts:130-147). - The button exists only when a schedule is readable, carries the rendered key and csrf (
src/views/pages.ts:4677-4679), and the route is maintainer-only and already classified expensive (src/app.ts:1781-1799,src/lib/routeClasses.ts:80).
Ran:
npm run checkin a fresh tree of9f1d3727— exit 0, 2321/2321 pass (lint vs baseline, typecheck, test, build)npx tsx --test test/scheduleRunNow.test.ts— 5/5 at the tip- red half:
src/app.ts,src/db.ts,src/jobs/service.ts,src/lib/routeClasses.ts,src/views/pages.tsrestored to base410f16b2andsrc/schedules/runNow.tsremoved, same two test files — 6 of 13 fail (the schema-column assertion and all five run-now tests) node scripts/risk-gate.mjs --base <base tree> --head <head tree>—risk-tier: T3; basis: src/db.ts; it reports 12 files because the branch's merge-base predates base410f16b2fordocs/security.mdandtest/secretsDoc.test.ts, which this PR does not touch (GitHub's merge-base diff is the 10 files above)GITHUB_TOKEN=… node scripts/pr-lint.mjs --pr 892—pr-lint: ok (#892, T3, 10 files; tracks #544)
Not run: no live console was clicked against a real deployment — the route was exercised through app.inject in the test only.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Written-by: Fledge Platform Dev-3
Bot: Fledge Platform Dev-3
Part of #544 — this slice adds the run-now path only; the card stays open.
What changed
A schedule console "Run now" had no way to say "this is the same request". A double click, a retry or a replayed form produced a second run, and nothing recorded that the request was refused.
src/schedules/runNow.ts(new): a bounded command-key shape, so the key rendered into the page is the only thing that identifies one request.src/db.ts:schedule_occurrences.command_keywith a partialUNIQUE(schedule_id, command_key)— the tick's rows keep a null key and are unaffected — plus store methods to create, settle and look up an occurrence by key.Jobs.runScheduleNow: the same key returns the same occurrence and the same job (a double click is one run), a new key is a distinct instance, and a refused dispatch settles the rowskippedwith the refusal so a replay answers the same thing instead of dispatching again.POST /repos/:id/schedule/run-nowis classified expensive inrouteClasses.ts; the schedule console renders the Run now form with a freshly rendered key.last_occurrence_atis never touched by this path.Verification
Red first, both halves recorded: with the code stashed
test/scheduleRunNow.test.tsis 0 pass / 5 fail (the method, the column and the route do not exist); with the slice it is 5/5.Ran:
npm run checkat the tip — exit 0, 2321/2321 (lint 11 warnings = baseline, typecheck and build clean)npm run test:coverageat the tip — exit 0; changed-lines gateok — 130/137 changed lines covered (94.9%, floor 80%)node scripts/risk-gate.mjs --base 1be10453—risk-tier: T3; basis: src/db.tsNot run: no live GitHub call, no browser screenshot.
Risk and rollback
T3,
src/db.tsplus one route. The migration adds a nullable column and a partial index, so existing rows are untouched and a revert leaves the column unused. No data move, no config change.Docs
docs/architecture.mdgains the "Run now is an occurrence" section. Changelog:changelog.d/544-run-now.added.md.maintainer_can_modify: true