Skip to content

Add custom cleanup instructions and semantic retractions - #52

Open
amalshaji wants to merge 5 commits into
mainfrom
custom-cleanup-instructions
Open

Add custom cleanup instructions and semantic retractions#52
amalshaji wants to merge 5 commits into
mainfrom
custom-cleanup-instructions

Conversation

@amalshaji

Copy link
Copy Markdown
Owner

Summary

  • add bounded custom instructions to transcription cleanup, including settings UI and provider plumbing
  • apply custom cleanup instructions after selected styles so explicit user guidance takes precedence
  • have cleanup models semantically mark explicitly withdrawn speech without hard-coded cue phrases
  • relax local deletion safeguards only when the model reports an applied transcription retraction

Why

Dictation can serve as a scratchpad. A speaker may explore alternatives, withdraw earlier thoughts, and end with one intended sentence. Cleanup should preserve ordinary ideation while removing only content the speaker explicitly retracted.

Impact

  • adds a custom cleanup instruction setting capped at 500 characters
  • extends the cleanup JSON contract with retractionApplied
  • preserves strict length and protected-token checks unless a semantic retraction was applied
  • keeps transformation validation unchanged

Validation

  • xcodebuild -project Dictator.xcodeproj -scheme Dictator -configuration Debug -destination platform=macOS -derivedDataPath /tmp/dictator-retraction-derived CODE_SIGNING_ALLOWED=NO -only-testing:DictatorCoreTests/CleanupProcessingTests test — 17 tests passed
  • xcodebuild -project Dictator.xcodeproj -scheme Dictator -configuration Debug -destination platform=macOS -derivedDataPath /tmp/dictator-retraction-derived CODE_SIGNING_ALLOWED=NO test — succeeded with one intentional live-audio skip
  • git diff --check

@amalshaji
amalshaji marked this pull request as ready for review August 13, 2026 05:14

@tasuku-app tasuku-app Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tasuku review

High risk: a model-controlled retraction flag bypasses protections against silent mutation or loss of dictated URLs, email addresses, numbers, and vocabulary.

Findings

All 1 finding(s) are posted as inline review comments.

Review confidence

98% · HIGH risk

Review coverage

Category Status
Correctness Pass
Production safety Pass
Architecture conventions Pass
Maintainability Pass
Security Findings
Reliability Pass
Performance Pass
Testing Pass
Compatibility Pass
Dependencies Not applicable
Ux accessibility Not applicable
Operability Not applicable
Documentation Not applicable

Important files

  • Sources/DictatorCore/CleanupSafetyValidator.swift
  • Sources/DictatorCore/LLM/CleanupResponseDecoder.swift
  • Sources/DictatorCore/ProviderProtocols.swift
  • Tests/DictatorCoreTests/CleanupProcessingTests.swift

Validation

Validation Evidence
Passed
Source inspection
git diff --name-status; git diff --stat; path-scoped git diff and targeted rg/git show inspection
Inspected all four changed files plus every production decoder caller and relevant existing tests; no generated or minified artifacts were involved.
Not run
Test
Not run
Builds, tests, linters, formatters, type checkers, and package commands were prohibited by the review scope.

Context used

  • ae5d6f1 — Primary pull request head reviewed.
  • 62ea218 — Primary pull request base used for comparison.

throw ProviderError.cleanupRejected("unexpected length change")
}

guard !retractionApplied else { return }

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Do not let the model bypass all protected-token validation

The validator returns before protected-token and vocabulary checks whenever the model reports any transcription retraction. A legitimate unrelated retraction—or an erroneous or malicious provider response—can therefore delete an email or number or substitute a URL while still being accepted. Replace the global bypass with validated withdrawn spans or another deterministic check that exempts only values proven to belong to withdrawn speech.

Evidence

At head line 26, guard !retractionApplied else { return } executes before both the protected-pattern and vocabulary loops; CleanupResponseDecoder derives this flag solely from the same untrusted model payload.

Validation

Validation Evidence
Passed
Source inspection
git diff --unified=60 62ea218e6944f4c0cefefe584ba66c6561761f1f ae5d6f16335dd0d93d7b2087f7cb5476c5119083 -- Sources/DictatorCore/CleanupSafetyValidator.swift Sources/DictatorCore/LLM/CleanupResponseDecoder.swift Tests/DictatorCoreTests/CleanupProcessingTests.swift
Confirmed that any true model-supplied retraction flag skips every protected-token and vocabulary check, including tokens unrelated to a retraction.
Not run
Test
Not run
The review scope explicitly prohibited executing tests.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tasuku-app Fix it

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Plan consolidated here: view plan

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 1008291: Replaced the model-controlled global bypass with deterministically verified withdrawn-source ranges; unrelated protected tokens and vocabulary remain mandatory.

Agent-reported verification

  • PASS: git diff --check completed successfully.
  • PASS: Confirmed production code contains no retractionApplied bypass and changes are limited to four approved cleanup files.
  • BLOCKED: xcodebuild -project Dictator.xcodeproj -scheme Dictator -configuration Debug -destination 'platform=macOS' -only-testing:DictatorCoreTests/CleanupProcessingTests test/bin/bash: xcodebuild: command not found in this Linux container.
  • BLOCKED: xcodebuild -project Dictator.xcodeproj -scheme Dictator -configuration Debug -destination 'platform=macOS' test/bin/bash: xcodebuild: command not found in this Linux container.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still open on 1008291: The new commits scope exemptions to source-matched spans, but line 23 accepts cue phrases through only a word boundary; ordinary dictated text such as Scratch that disk and reboot therefore authorizes removal of the preceding span and its protected tokens. Require the cue to end at punctuation or end-of-input, or validate the complete following clause before granting the exemption.

Validation

Validation Evidence
Passed
Source inspection
git diff --name-status ae5d6f16335dd0d93d7b2087f7cb5476c5119083 10082916c796acbc95669dc67f8f4d4c8aebf18d
Inspected all four changed files through path-scoped diffs, then traced validator callers, prompt behavior, models, and fallback handling with targeted searches and reads.
Not run
Test
Not run
Builds, tests, linters, formatters, type checkers, and other executable validation were prohibited by the review scope.

@tasuku-app

tasuku-app Bot commented Aug 13, 2026

Copy link
Copy Markdown

Plan · Scope cleanup validation exemptions to verified retractions

Replace the provider-controlled global validation bypass with exact withdrawn-source spans that are deterministically validated. Protected tokens and vocabulary outside those spans will remain mandatory.

Approach

  • Change the cleanup response contract and decoder to carry exact withdrawn spans for transcription responses instead of trusting a blanket retractionApplied flag.
  • Validate each claimed span against the raw transcript, require non-overlapping exact matches associated with explicit withdrawal language, and reject malformed or unverified claims.
  • Build a retained-source baseline by excluding only verified withdrawn ranges, then run length, protected-token occurrence, and enabled-vocabulary checks against that baseline.
  • Add regression tests proving a valid retraction may remove protected values within its verified span, while unrelated emails, URLs, numbers, code, and vocabulary still cannot be removed or substituted.

Risks

  • A deliberately conservative span validator may reject ambiguous but legitimate semantic retractions; cleanup should fail safely rather than weaken token protection.
  • Repeated identical text requires range-aware matching so the validator exempts only the claimed occurrence.

Verification

  • Run DictatorCore cleanup-processing tests.
  • Run the full macOS test suite if the local Xcode environment is available.

Reply with @tasuku-app implement to approve and start this change.

@amalshaji

Copy link
Copy Markdown
Owner Author

@tasuku-app implement

@tasuku-app

tasuku-app Bot commented Aug 13, 2026

Copy link
Copy Markdown

Implementation complete

Replaced the global retraction bypass with exact UTF-16 withdrawn spans. Claims now require matching source text, valid non-overlapping ranges, source boundaries, and explicit adjacent withdrawal language. Length, protected-token occurrences, and enabled vocabulary are validated against only the retained transcript. Added regressions for malformed claims, repeated values, legacy bypass attempts, and unrelated emails, URLs, numbers, code, and vocabulary.

Agent-reported verification

  • PASS: git diff --check completed successfully.
  • PASS: Confirmed production code contains no retractionApplied bypass and changes are limited to four approved cleanup files.
  • BLOCKED: xcodebuild -project Dictator.xcodeproj -scheme Dictator -configuration Debug -destination 'platform=macOS' -only-testing:DictatorCoreTests/CleanupProcessingTests test/bin/bash: xcodebuild: command not found in this Linux container.
  • BLOCKED: xcodebuild -project Dictator.xcodeproj -scheme Dictator -configuration Debug -destination 'platform=macOS' test/bin/bash: xcodebuild: command not found in this Linux container.

Result

#52

@tasuku-app tasuku-app Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tasuku review

High risk: verified retractions remain bypassable through partial cue matches, and valid cleanup can fall back to the raw transcript in two newly introduced cases.

Findings

All 2 finding(s) are posted as inline review comments.

Review confidence

97% · HIGH risk

Review coverage

Category Status
Correctness Findings
Production safety Pass
Architecture conventions Pass
Maintainability Pass
Security Pass
Reliability Pass
Performance Pass
Testing Pass
Compatibility Pass
Dependencies Not applicable
Ux accessibility Not applicable
Operability Not applicable
Documentation Not applicable

Important files

  • Sources/DictatorCore/CleanupSafetyValidator.swift
  • Sources/DictatorCore/LLM/CleanupResponseDecoder.swift
  • Sources/DictatorCore/ProviderProtocols.swift
  • Tests/DictatorCoreTests/CleanupProcessingTests.swift

Validation

Validation Evidence
Passed
Source inspection
git diff --name-status ae5d6f16335dd0d93d7b2087f7cb5476c5119083 10082916c796acbc95669dc67f8f4d4c8aebf18d
Inspected all four changed files through path-scoped diffs, then traced validator callers, prompt behavior, models, and fallback handling with targeted searches and reads.
Not run
Test
Not run
Builds, tests, linters, formatters, type checkers, and other executable validation were prohibited by the review scope.

Context used

  • 1008291 — Primary pull-request head inspected for implementation, tests, callers, and exact changed lines.
  • ae5d6f1 — Pull-request base used to identify incremental behavior and reconcile the prior finding.

let ratio = Double(trimmed.count) / Double(max(raw.count, 1))
let baseline = try retainedBaseline(raw: raw, withdrawnSpans: withdrawnSpans)
let ratio = Double(trimmed.count) / Double(max(baseline.count, 1))
guard (0.45...1.65).contains(ratio) else {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Do not apply the lower length bound to retained withdrawal cues

The ratio includes the withdrawal cue, so withdrawing the first sentence from Email old@example.com. Scratch that. Hi. incorrectly rejects the valid output Hi.. The coordinator then falls back to the full raw transcript, re-inserting explicitly withdrawn text. Exclude verified cue text from the ratio baseline, or waive only the lower bound after span verification while retaining the protected-token checks.

Evidence

Line 39 applies the 0.45 lower bound even when baseline still contains Scratch that; CleanupCoordinator.cleanOrFallback converts this rejection into the original transcription fallback.

Validation

Validation Evidence
Passed
Source inspection
git diff --unified=40 ae5d6f16335dd0d93d7b2087f7cb5476c5119083 10082916c796acbc95669dc67f8f4d4c8aebf18d -- Sources/DictatorCore/CleanupSafetyValidator.swift
Confirmed that withdrawn source spans are removed from the baseline but their immediately following withdrawal cues remain subject to the lower length ratio.
Not run
Test
Not run
The review scope explicitly prohibited executing tests.

for term in vocabulary.filter(\.isEnabled).map(\.value) {
let baselineCount = caseInsensitiveOccurrenceCount(of: term, in: baseline)
let cleanedCount = caseInsensitiveOccurrenceCount(of: term, in: trimmed)
guard cleanedCount >= baselineCount else {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Permit cleanup of repeated vocabulary terms

Requiring every vocabulary occurrence to remain rejects Dictator Dictator becoming Dictator, despite the prompt directing the model to remove accidental repetition. The rejection falls back to the uncleaned repeated transcript. Restore existence-based vocabulary preservation or distinguish accidental repetition from separate intended uses before comparing counts.

Evidence

The changed guard at line 54 compares cleaned and baseline occurrence counts, whereas the base implementation required only that a vocabulary term present in the source remain present in the output.

Validation

Validation Evidence
Passed
Source inspection
git show ae5d6f16335dd0d93d7b2087f7cb5476c5119083:Sources/DictatorCore/CleanupSafetyValidator.swift
Confirmed that the base required at least one retained occurrence, while the new head requires the complete baseline count.
Not run
Test
Not run
The review scope explicitly prohibited executing tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants