SUBTASK #44: Close scan session (2.2.1.4)

Chiusa
#46 0 commenti 0 reazioni 1 assegnatario Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@PavlockBlaine03 ci sta già lavorando.

Dal 27/10/2026.

Valutazione

Questa issue non è ancora stata valutata.

Descrizione

backend High Priority subtask

What to do

The last step of every scan: record when it ended, how it ended (its outcome) and any errors, and mark the session as no longer running so the next scan can start. Also closes "stale" scans left marked as running after the server stopped mid-scan, which Open Scan Session (subtask 1) calls before opening a new one.

Background

  • Spec: FR-13 (scan status and errors), OUT-06 (errors such as an empty ARP cache or an unreachable subnet), CM-15, SEC-14
  • System design 2.2.1.4: "Record end time, outcome, and errors." Section 8.4: the Scan Manager decides the outcome; this module only records it.
  • OOD: Scan.complete() / Scan.fail(message); scan sequence step 11
  • ScanOutcome in backend/records/enums.py: success, partial, failed
  • Rules are in #44.

Steps

  • Add close(scan_id, outcome, errors) to ScanSessionController (from subtask 1):
    • Sets status = completed, ended_at = now, outcome, and error_message (the errors, one per line; empty when there are none)
    • Saves through 3.1 (#15)
    • Clears "the scan running in this process", so the next open() is allowed
    • Clears that state even if saving fails (for example, the database is down): otherwise one failed save would block every future scan until the server restarts. The save error is still raised to the caller.
    • Closing a scan that is already closed changes nothing
  • The outcome is passed in, not worked out here. Deciding between success, partial and failed is the Scan Manager's job (subtask 4); this module just records it (design 8.4).
  • Optional: Scan.finish(outcome, errors, ended_at) on the entity in backend/records/scan.py, matching the OOD's complete() / fail(), so the rule "a finished scan has an end time and an outcome" lives with the scan
  • close_stale_scans(): every scan still running in the database except the one this process is running is closed as failed with "the server stopped during this scan". Called by open() (subtask 1).
  • Long error lists are cut to a sensible length (for example, the first 50 lines plus "and N more") so one bad scan can't store megabytes of text
  • Not audited separately, like the rest of the scan history (design open item 6)
  • Unit tests with fakes:
    • Close records the end time, outcome and errors, and the next open() succeeds
    • Closing twice changes nothing
    • A save that fails still clears the running state (and raises the error)
    • A stale running row is closed as failed; the scan this process is running is left alone
    • A very long error list is shortened

Where

backend/services/scan/scan_session.py (the same class as subtask 1)

Done when

  • All unit tests pass without a database
  • Against the test database, an opened scan closed as partial shows its end time, outcome and error message, and a new scan can then be opened

Depends on

  • Subtask 1, Open Scan Session (#45): same class
  • #15 Network Data (3.1: updating the scan)
Lingua principale
Python
Stelle
1
Fork
1
Merge medio
9h 31m
PR unite (30g)
36

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di Bearkat-Professionals/Software-Engineering-Project

Tutte le issue di Bearkat-Professionals/Software-Engineering-Project

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.