Back off token recount selection retries#377
Open
baron wants to merge 1 commit into
Open
Conversation
Comment on lines
+286
to
+293
| shouldUseSelectionConsistencyRetryBackoffForNextSelectionRecount = false | ||
| let debounceNanoseconds = tokenCountUpdateDebounceNanoseconds( | ||
| useSelectionConsistencyRetryBackoff: usesSelectionConsistencyRetryBackoff | ||
| ) | ||
| tokenUpdateDebounceTask?.cancel() | ||
| tokenUpdateDebounceTask = Task { @MainActor [weak self] in | ||
| do { | ||
| try await Task.sleep(nanoseconds: Self.tokenUpdateDebounceNanoseconds) | ||
| try await Task.sleep(nanoseconds: debounceNanoseconds) |
There was a problem hiding this comment.
Bug: The selection consistency retry backoff can be canceled by concurrent non-selection dirty events (e.g., prompt text changes), defeating the purpose of the backoff delay.
Severity: MEDIUM
Suggested Fix
The shouldUseSelectionConsistencyRetryBackoffForNextSelectionRecount flag should not be reset until the backoff-delayed task actually begins execution. Alternatively, when scheduleTokenCountUpdateIfNeeded() is called, it should check if the pending tokenUpdateDebounceTask is a backoff task and avoid canceling it for non-critical dirty events.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.
Location:
Sources/RepoPrompt/Features/Prompt/ViewModels/TokenCountingViewModel.swift#L286-L293
Potential issue: A race condition exists where the selection consistency retry backoff
is defeated. When a retry is scheduled, the
`shouldUseSelectionConsistencyRetryBackoffForNextSelectionRecount` flag is consumed and
a long debounce task is started. If a concurrent non-selection event (e.g., prompt text
change) triggers `markDirty()` before the backoff task executes, the pending backoff
task is canceled and replaced with a standard, shorter debounce task. This undermines
the feature's goal of reducing rapid recounts during periods of instability, leading to
degraded performance.
Did we get this right? 👍 / 👎 to inform future reviews.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Validation
.agents/skills/rpce-contribution-check/scripts/preflight.sh commit✅.agents/skills/rpce-contribution-check/scripts/preflight.sh push✅swiftformat --config .swiftformat --lint Sources/RepoPrompt/Features/Prompt/ViewModels/TokenCountingViewModel.swift Tests/RepoPromptTests/MCP/MCPSelectionReplyFreshnessTests.swift✅swiftlint lint --strict --config .swiftlint.yml Sources/RepoPrompt/Features/Prompt/ViewModels/TokenCountingViewModel.swift Tests/RepoPromptTests/MCP/MCPSelectionReplyFreshnessTests.swift✅Notes:
make dev-lintwas attempted but failed in the full-repo SwiftFormat lint phase with an unrelatedenvironmentEntry rule timed outerror inSources/RepoPrompt/Infrastructure/WorkspaceContext/Models/WorkspaceCodemapLiveOverlayModels.swift.