-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix: preserve fork accuracy during bounded Codex cost catch-up #2525
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
steipete
merged 7 commits into
steipete:main
from
xx205:fix/codex-fork-baseline-resolution
Aug 2, 2026
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
2341fdf
Fix resumable Codex fork accounting
xx205 44daada
Expose Codex cost catch-up progress
xx205 274f6af
Add adaptive Codex cost catch-up controls
xx205 ab34bd0
Preserve Codex cost history during cache rebuilds
xx205 ebf02b4
Bind dashboard catch-up to account caches
xx205 7fe0534
fix: quiesce missing Codex fork parents
a0d9d52
chore: merge main into Codex fork accounting
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| import Foundation | ||
| import IOKit.ps | ||
|
|
||
| enum CodexCostCatchUpMode: String, Sendable { | ||
| case automatic | ||
| case accelerated | ||
| } | ||
|
|
||
| enum CodexCostCatchUpPowerSource: String, Sendable { | ||
| case ac | ||
| case battery | ||
| case unknown | ||
|
|
||
| static func current() -> Self { | ||
| guard let info = IOPSCopyPowerSourcesInfo()?.takeRetainedValue(), | ||
| let source = IOPSGetProvidingPowerSourceType(info)?.takeUnretainedValue() as String? | ||
| else { | ||
| return .unknown | ||
| } | ||
| if source == kIOPSACPowerValue as String { | ||
| return .ac | ||
| } | ||
| if source == kIOPSBatteryPowerValue as String { | ||
| return .battery | ||
| } | ||
| return .unknown | ||
| } | ||
| } | ||
|
|
||
| enum CodexCostCatchUpPauseReason: Sendable, Equatable { | ||
| case lowPower | ||
| case thermal | ||
| case user | ||
| case noProgress | ||
| case error(String) | ||
| } | ||
|
|
||
| struct CodexCostCatchUpActivity: Sendable, Equatable { | ||
| enum Phase: Sendable, Equatable { | ||
| case indexing | ||
| case paused | ||
| case complete | ||
| } | ||
|
|
||
| let phase: Phase | ||
| let mode: CodexCostCatchUpMode | ||
| let processedBytes: Int64 | ||
| let totalBytes: Int64 | ||
| let completedFiles: Int | ||
| let totalFiles: Int | ||
| let pauseReason: CodexCostCatchUpPauseReason? | ||
| let staleSnapshotUpdatedAt: Date? | ||
|
|
||
| var fractionCompleted: Double? { | ||
| guard self.totalBytes > 0 else { | ||
| guard self.totalFiles > 0 else { return nil } | ||
| return min(1, max(0, Double(self.completedFiles) / Double(self.totalFiles))) | ||
| } | ||
| return min(1, max(0, Double(self.processedBytes) / Double(self.totalBytes))) | ||
| } | ||
| } | ||
|
|
||
| struct CodexCostCatchUpPolicy: Sendable { | ||
| struct Input: Sendable { | ||
| let mode: CodexCostCatchUpMode | ||
| let previousActiveDuration: TimeInterval? | ||
| let powerSource: CodexCostCatchUpPowerSource | ||
| let lowPowerModeEnabled: Bool | ||
| let thermalState: ProcessInfo.ThermalState | ||
| } | ||
|
|
||
| struct Decision: Sendable, Equatable { | ||
| enum Action: Sendable, Equatable { | ||
| case runAfter(TimeInterval) | ||
| case pause(TimeInterval, CodexCostCatchUpPauseReason) | ||
| } | ||
|
|
||
| let action: Action | ||
| let targetDutyCycle: Double? | ||
| } | ||
|
|
||
| static let automaticBurstDuration: TimeInterval = 2 | ||
| static let constrainedRetryDelay: TimeInterval = 60 | ||
|
|
||
| func decision(for input: Input) -> Decision { | ||
| if input.thermalState == .critical { | ||
| return Decision( | ||
| action: .pause(Self.constrainedRetryDelay, .thermal), | ||
| targetDutyCycle: nil) | ||
| } | ||
| if input.mode == .automatic { | ||
| if input.lowPowerModeEnabled { | ||
| return Decision( | ||
| action: .pause(Self.constrainedRetryDelay, .lowPower), | ||
| targetDutyCycle: nil) | ||
| } | ||
| if input.thermalState == .serious { | ||
| return Decision( | ||
| action: .pause(Self.constrainedRetryDelay, .thermal), | ||
| targetDutyCycle: nil) | ||
| } | ||
| } | ||
| if input.mode == .accelerated { | ||
| return Decision(action: .runAfter(0), targetDutyCycle: 1) | ||
| } | ||
|
|
||
| let dutyCycle = switch input.powerSource { | ||
| case .ac: 0.20 | ||
| case .battery: 0.05 | ||
| case .unknown: 0.15 | ||
| } | ||
| let activeDuration = max(0, input.previousActiveDuration ?? Self.automaticBurstDuration) | ||
| let delay = activeDuration * (1 - dutyCycle) / dutyCycle | ||
| return Decision(action: .runAfter(delay), targetDutyCycle: dutyCycle) | ||
| } | ||
| } |
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
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
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
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
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
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
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
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
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
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
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When an account-scoped dashboard scan remains pending—for example, a Codex archive exceeding the 512 MiB per-refresh limit—this panel reports and controls
UsageStore.codexCostCatchUpActivity, but dashboard rows are loaded from separate caches underaccounts/<cacheIdentity>inSpendDashboardSource.load(SpendDashboardController.swift:273-283). The buttons therefore advance the store's default selected-account cache rather than the cache supplying the displayed row, and completing that task does not invalidate Codex dashboard data because Codex is excluded fromsourceRevisions; users can click “Finish now” yet keep seeing the stale/partial dashboard result. Track catch-up per dashboard account cache or avoid presenting these controls as dashboard progress.Useful? React with 👍 / 👎.