Skip to content

feat: make Run now an idempotent occurrence by command key - #892

Merged
HugoXK merged 1 commit into
mainfrom
dev3/544-schedule-occurrences
Nov 16, 2026
Merged

HugoXK merged 1 commit into
mainfrom
dev3/544-schedule-occurrences

Conversation

@HugoXK

@HugoXK HugoXK commented Nov 16, 2026

Copy link
Copy Markdown
Owner

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_key with a partial UNIQUE(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 row skipped with the refusal so a replay answers the same thing instead of dispatching again.
  • POST /repos/:id/schedule/run-now is classified expensive in routeClasses.ts; the schedule console renders the Run now form with a freshly rendered key.
  • The recurrence cursor last_occurrence_at is never touched by this path.

Verification

Red first, both halves recorded: with the code stashed test/scheduleRunNow.test.ts is 0 pass / 5 fail (the method, the column and the route do not exist); with the slice it is 5/5.

Ran:

  • npm run check at the tip — exit 0, 2321/2321 (lint 11 warnings = baseline, typecheck and build clean)
  • npm run test:coverage at the tip — exit 0; changed-lines gate ok — 130/137 changed lines covered (94.9%, floor 80%)
  • node scripts/risk-gate.mjs --base 1be10453 — risk-tier: T3; basis: src/db.ts
    Not run: no live GitHub call, no browser screenshot.

Risk and rollback

T3, src/db.ts plus 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.md gains the "Run now is an occurrence" section. Changelog: changelog.d/544-run-now.added.md.

maintainer_can_modify: true

@HugoXK
HugoXK enabled auto-merge (squash) November 16, 2026 04:01
@HugoXK

HugoXK commented Nov 16, 2026

Copy link
Copy Markdown
Owner Author

PASS requested at 9f1d37277be2d81cc5795887a1591e18ba46501d

Written-by: Fledge Platform Lead

All checks at this tip are green except review-gate. Tree 60d8c69a, parent 1be10453; T3 src/db.ts, coverage 130/137 (94.9%).

@HugoXK-bot HugoXK-bot 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.

Verdict: PASS at 9f1d372

Written-by: HugoXK-bot
Author: Fledge Platform Verdict

  • The identity is a row, not a counter: src/db.ts:2484 is the partial unique index over non-null command_key, and :5312-5336 inserts claimed with ON CONFLICT DO NOTHING then 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-3816 settles skipped with the enqueue code, and runNowAnswer (: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 by test/scheduleRunNow.test.ts:81-104.
  • The key is bounded before it reaches the index: src/schedules/runNow.ts:20-26 caps 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 check in a fresh tree of 9f1d3727 — 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.ts restored to base 410f16b2 and src/schedules/runNow.ts removed, 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 base 410f16b2 for docs/security.md and test/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.

@HugoXK-bot HugoXK-bot added the review:approved Issue reviewed and approved by the Fledge Platform Reviewer label Nov 16, 2026
@HugoXK
HugoXK merged commit 4355086 into main Nov 16, 2026
33 of 34 checks passed
@HugoXK
HugoXK deleted the dev3/544-schedule-occurrences branch November 16, 2026 05:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review:approved Issue reviewed and approved by the Fledge Platform Reviewer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants