fix(scan): a person's scan gets the next slot and shows as queued (t84) #940

Merged
sharang merged 3 commits from fix/t84-scan-followup into main 2026-11-09 07:52:25 +00:00
Owner

A scan a person asked for waited behind every scheduled scan of every tenant. The scan gate's slots were one FIFO semaphore, and a click on a target whose scheduled scan was still waiting became a follow-up behind it. On stage, a manual scan clicked at 12:51 started at about 15:47 with nothing shown meanwhile (t84).

Order (scan_gate.rs)

  • There are two queues for the SCAN_CONCURRENCY slots. Manual and support scans go first; scheduled, webhook, new-content and PR-review work go second. Each queue is FIFO.
  • After 3 person scans in a row, the next slot goes to a background scan that is waiting (PERSON_GRANTS_IN_A_ROW), so clicks never starve the scheduler.
  • A person's request takes over a waiting scan that was not a person's, in place and at person priority. If that target's scan is already running, the request becomes the follow-up and waits for that scan only, then queues at person priority.
  • The slot passes through a oneshot. If a waiter gave up, its slot goes to the next one.

Queued runs

  • Every request is recorded at once as a run with the new status queued. The dashboard shows it as "Wartet auf einen Platz", with when it was requested and a hint. Follow-ups are recorded the same way.
  • When a queued scan gets its slot, it runs on that same run, and started_at becomes the real start (queued_at keeps the request time).
  • A request that will not run has its queued run removed: it is covered by a waiting scan, or a person's request replaced it. A scan that fails before it starts, such as an unknown target, closes its run as failed.
  • A restart closes queued runs as interrupted and resumes the target, the same as running ones.
    • A queued run doesn't count toward the restart-loop guard.
    • If a target had both a running and a queued run, the resume uses the person's trigger.
  • Evidence and the platform's last_scan_at ignore queued runs. The targets list shows them.

Metering (t72), with the takeover rule decided by the user:

  • A person's request that takes over a scheduled, webhook or new-content scan still waiting for a slot produces one merged run. That run gets the person's priority and keeps the attribution request, so the history shows a person asked. It is charged as the original trigger: it would have run anyway; the customer only gets it sooner.
    • Change detection decides as it would for that trigger. On an included target the run is not counted (chargeable=false). On an extra target with a change, it counts, as the original scan would have.
    • The run records the trigger it is charged as in charged_as.
  • A person's request on a target whose scan is running is a follow-up, a new run after that scan. It is charged as the person's request, as today.
  • Otherwise unchanged: a counted Prüfung is checked against the plan and charged when it runs; our failures are not charged.

Behaviour changes to be aware of

  • A request that arrives while a scan of the same class still waits for its slot (not yet running) is now dropped. It used to become a follow-up. The waiting scan reads the latest code when it starts.
  • After a restart, a target is resumed even if its scan was only queued.
  • The targets page keeps polling while any target is queued, which after a scheduler tick can be a while.
  • API-key and MCP readers of scan_runs can now see status: "queued".

Tests

  • Gate, order: a person's scan goes before queued scheduled scans; it takes over a waiting scheduled scan; a follow-up waits only for the running scan.
  • Gate, fairness: 10 clicks don't starve a scheduled scan; a given-up waiter passes its slot on.
  • Charging: a taken-over waiting scan carries charged_as; a follow-up after a running scan does not.
  • tests/scan_queue.rs against Mongo:
    • On an included target, a takeover run is request, charged_as: webhook, not chargeable; a person's own scan is chargeable.
    • The run shows queued while it waits.
    • A person's request replaces the webhook run, and a second push leaves no run.
    • The scan runs on the queued run.
  • Lifecycle: queued runs are closed at startup, and the resume picks the person's trigger with a single counted interruption.
  • Dashboard: the queued badge text, and a queued run is followed to its end.

Locally: fmt, clippy with -D warnings (core, agent, dashboard server and web, mcp), the lib and dashboard tests, and all agent integration tests against Mongo (97 passed).

🤖 Generated with Claude Code

A scan a person asked for waited behind every scheduled scan of every tenant. The scan gate's slots were one FIFO semaphore, and a click on a target whose scheduled scan was still waiting became a follow-up behind it. On stage, a manual scan clicked at 12:51 started at about 15:47 with nothing shown meanwhile (t84). **Order (scan_gate.rs)** - There are two queues for the `SCAN_CONCURRENCY` slots. Manual and support scans go first; scheduled, webhook, new-content and PR-review work go second. Each queue is FIFO. - After 3 person scans in a row, the next slot goes to a background scan that is waiting (`PERSON_GRANTS_IN_A_ROW`), so clicks never starve the scheduler. - A person's request takes over a waiting scan that was not a person's, in place and at person priority. If that target's scan is already running, the request becomes the follow-up and waits for that scan only, then queues at person priority. - The slot passes through a oneshot. If a waiter gave up, its slot goes to the next one. **Queued runs** - Every request is recorded at once as a run with the new status `queued`. The dashboard shows it as "Wartet auf einen Platz", with when it was requested and a hint. Follow-ups are recorded the same way. - When a queued scan gets its slot, it runs on that same run, and `started_at` becomes the real start (`queued_at` keeps the request time). - A request that will not run has its queued run removed: it is covered by a waiting scan, or a person's request replaced it. A scan that fails before it starts, such as an unknown target, closes its run as failed. - A restart closes queued runs as `interrupted` and resumes the target, the same as running ones. - A queued run doesn't count toward the restart-loop guard. - If a target had both a running and a queued run, the resume uses the person's trigger. - Evidence and the platform's `last_scan_at` ignore queued runs. The targets list shows them. **Metering (t72), with the takeover rule decided by the user:** - A person's request that takes over a scheduled, webhook or new-content scan still waiting for a slot produces one merged run. That run gets the person's priority and keeps the attribution `request`, so the history shows a person asked. **It is charged as the original trigger:** it would have run anyway; the customer only gets it sooner. - Change detection decides as it would for that trigger. On an included target the run is not counted (`chargeable=false`). On an extra target with a change, it counts, as the original scan would have. - The run records the trigger it is charged as in `charged_as`. - A person's request on a target whose scan is **running** is a follow-up, a new run after that scan. It is charged as the person's request, as today. - Otherwise unchanged: a counted Prüfung is checked against the plan and charged when it runs; our failures are not charged. **Behaviour changes to be aware of** - A request that arrives while a scan of the same class still waits for its slot (not yet running) is now dropped. It used to become a follow-up. The waiting scan reads the latest code when it starts. - After a restart, a target is resumed even if its scan was only queued. - The targets page keeps polling while any target is queued, which after a scheduler tick can be a while. - API-key and MCP readers of `scan_runs` can now see `status: "queued"`. **Tests** - Gate, order: a person's scan goes before queued scheduled scans; it takes over a waiting scheduled scan; a follow-up waits only for the running scan. - Gate, fairness: 10 clicks don't starve a scheduled scan; a given-up waiter passes its slot on. - Charging: a taken-over waiting scan carries `charged_as`; a follow-up after a running scan does not. - `tests/scan_queue.rs` against Mongo: - On an included target, a takeover run is `request`, `charged_as: webhook`, not chargeable; a person's own scan is chargeable. - The run shows `queued` while it waits. - A person's request replaces the webhook run, and a second push leaves no run. - The scan runs on the queued run. - Lifecycle: queued runs are closed at startup, and the resume picks the person's trigger with a single counted interruption. - Dashboard: the queued badge text, and a queued run is followed to its end. Locally: fmt, clippy with `-D warnings` (core, agent, dashboard server and web, mcp), the lib and dashboard tests, and all agent integration tests against Mongo (97 passed). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
sharang added 3 commits 2026-11-08 02:31:13 +00:00
Reproduces t84: a scan requested while the target's scheduled scan still
waits for a slot is coalesced as its follow-up, but the follow-up only
queues for a slot after that scan finished, behind every other scheduled
scan of the tick. Fails until person-started scans go first.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A scan a person asked for waited behind every scheduled scan of every
tenant: the scan gate's slots were one FIFO semaphore, and a request for
a target whose scheduled scan still waited became a follow-up behind it.
On stage a click waited about 3 hours with nothing to show for it.

- Scan gate: two queues for the slots. Manual and support scans go
  first, FIFO within each class; after 3 person scans in a row a waiting
  background scan gets the slot, so clicks never starve the scheduler.
- A person's request takes over a waiting scan that was not a person's,
  at person priority; on a running target it is the follow-up and
  re-queues at person priority once the running scan ends.
- Each request is recorded at once as a run with status `queued`
  ("Wartet auf einen Platz"), follow-ups included; the scan starts on
  that run. Requests that will not run have theirs removed; one whose
  scan ends before it starts is closed as failed.
- A restart closes queued runs as interrupted and resumes the target;
  a queued run does not count toward the restart-loop guard, and a
  person's trigger wins.
- Evidence and the platform's last_scan_at ignore queued runs.

Metering is unchanged: a counted Prüfung is admitted and charged when
it runs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
fix(scan): a taken-over waiting scan is charged as the scan it replaces (t84)
CI / Check (push) Skipped
CI / Detect Changes (pull_request) Skipped
CI / Deploy Agent (pull_request) Skipped
CI / Deploy Dashboard (pull_request) Skipped
CI / Deploy Docs (pull_request) Skipped
CI / Deploy MCP (pull_request) Skipped
CI / Agent integration (pull_request) Successful in 5m58s
CI / Check (pull_request) Successful in 19m58s
9d79bac004
When a person's request takes over a scheduled, webhook or new-content
scan that still waits for a slot, the run keeps the person's priority
and attribution (the history shows that a person asked), but it counts
only as the scan it replaced would have: that scan would have run
anyway, the customer only gets it sooner. Change detection decides, as
for that trigger, so on an included target it is not charged.

A person's follow-up after a running scan is a new run and is charged
as their request, as before. The run records the trigger it is charged
as in `charged_as`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
sharang merged commit d3c8eee393 into main 2026-11-09 07:52:25 +00:00
Sign in to join this conversation.