Back to the Omitto journey

DecidedStop 1 of 8

Making sure a background scan still matches the text on screen

Omitto scans text in the background. When a scan comes back, the app checks three things before it shows the result. The scan must still be the latest, the text must be unchanged, and the scan must not have been cancelled.

The question

In Omitto the user enters text and the app scans it for secrets. The scan runs Omitto · The appBackground scanTakes a copy of the text and the policy under a new generation number, a count that goes up with each scan. Then it runs RedactionCore as a detached task, a separate job in the background.See it in the Omitto build, so the user may have edited the text by the time it returns. How do I stop an old result from landing on text it was not made from?

What made it hard

Cancelling a scan does not stop it. The scanning is done by RedactionCore through Omitto · RedactionCore · The packageMain callOne call takes text and a policy, does the whole job, then returns the redacted text, the findings and a report.See it in the Omitto build, which runs until the work is finished. Its Omitto · RedactionCore · The packageDetectorsGathers the stretches of text that every detector suggests, and removes repeats.See it in the Omitto build does not check whether the Swift task running it was cancelled. So an out-of-date scan can keep working until it returns.

What I chose

So the app decides what to do when a scan returns. Omitto keeps its Omitto · The appScreen stateHolds the text that goes in and the result that comes out, plus the findings and the review choices. It all lives on the main actor, the part of Swift that runs the screens.See it in the Omitto build in one place, called the view model. It holds the text, the review controls and the output. It lives on the main actor, the part of Swift that runs the app’s screens. Before a scan starts, the view model takes a copy of the text and of the policy the scan will use. It also moves a generation number up by one, so each scan has its own number. A detached task, a separate job in the background, then runs RedactionCore away from the main actor.

When the detached task returns, the app Omitto · The appResult checkShows a result only if the generation number and the text still match, and the scan was not cancelled.See it in the Omitto build on the main actor. The generation number must still be the latest one. The text must still equal the captured text, the copy taken at the start. And the task must not have been cancelled. Only then does the view model accept the result and its review details, together.

Omitto · The appEdit resetAny edit clears the old output, findings and report. It also clears the Keep choices, so the text must be scanned again.See it in the Omitto build also clears what the last scan left behind. That means the old output, the Omitto · RedactionCore · The packageFindingsEach finding says where the match is, what kind it is, and how sure the scan is. It also gives a reason and a preview with the value hidden. It never holds the original value.See it in the Omitto build and the report. It also means the Keep choices made on each finding. They all came from the earlier text. The Copy button stays off during a scan.

What it does not do

These checks keep the result matched to the text on screen. They do not mean the detector found every secret.