-
Notifications
You must be signed in to change notification settings - Fork 0
Fix: anchor state-cache payloads against Git GC #732
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
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
a3058d3
Fix v19 boundary and checkpoint store seam
flyingrobots 9eb0db2
Fix checkpoint store tree blob writes
flyingrobots 01a17d1
Fix checkpoint review findings
flyingrobots 3763485
Fix checkpoint adapter review drift
flyingrobots ce2eaf6
Fix: close v19 serialization and test-law gaps
flyingrobots 68fd04f
Fix: anchor state-cache payloads against Git GC
flyingrobots 9a34c7c
Fix CI portability for v19 closeout
flyingrobots 2b4ba87
Fix state-cache review findings
flyingrobots c2983d1
Merge branch 'v19-closeout-first-five' into v19-closeout-next-five
flyingrobots 7aefb13
Regenerate source-backed API reference
flyingrobots d8ba03f
Ignore build output in Markdown sample lint
flyingrobots 803dee4
Hoist state-cache test patterns
flyingrobots 6799ea5
Fix remaining state-cache review findings
flyingrobots a5b6d61
Refresh source-backed API reference
flyingrobots d86193e
Avoid anti-sludge fallback token
flyingrobots 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,151 @@ | ||
| import type WarpStateCacheRetentionReport from '../../../../src/domain/services/state/WarpStateCacheRetentionReport.ts'; | ||
| import type WarpStateCacheRepairResult from '../../../../src/domain/services/state/WarpStateCacheRepairResult.ts'; | ||
| import type { DoctorFinding, FindingEvidence } from './types.ts'; | ||
| import { CODES } from './codes.ts'; | ||
|
|
||
| type StateCacheInspectionContext = { | ||
| readonly stateCache: { | ||
| inspectRetention(): Promise<WarpStateCacheRetentionReport>; | ||
| } | null; | ||
| }; | ||
|
|
||
| function retentionEvidence(report: WarpStateCacheRetentionReport) { | ||
| return { | ||
| liveSnapshotIds: [...report.liveSnapshotIds], | ||
| anchoredSnapshotIds: [...report.anchoredSnapshotIds], | ||
| unanchoredSnapshotIds: [...report.unanchoredSnapshotIds], | ||
| missingSnapshotIds: [...report.missingSnapshotIds], | ||
| wrongTypeSnapshotIds: [...report.wrongTypeSnapshotIds], | ||
| staleRootNames: [...report.staleRootNames], | ||
| mismatchedRootNames: [...report.mismatchedRootNames], | ||
| rootSetError: report.rootSetError, | ||
| }; | ||
| } | ||
|
|
||
| export async function checkStateCacheRetention( | ||
| ctx: StateCacheInspectionContext, | ||
| ): Promise<DoctorFinding[]> { | ||
| if (ctx.stateCache === null) { return []; } | ||
| const report = await ctx.stateCache.inspectRetention(); | ||
| return retentionFindings(report); | ||
| } | ||
|
|
||
| function retentionFindings(report: WarpStateCacheRetentionReport): DoctorFinding[] { | ||
| const findings: DoctorFinding[] = []; | ||
| const evidence = retentionEvidence(report); | ||
| const candidates = [ | ||
| invalidRootSetFinding(report, evidence), | ||
| missingPayloadFinding(report, evidence), | ||
| wrongTypeFinding(report, evidence), | ||
| unanchoredPayloadFinding(report, evidence), | ||
| staleRootFinding(report, evidence), | ||
| ]; | ||
| for (const candidate of candidates) { | ||
| if (candidate !== null) { findings.push(candidate); } | ||
| } | ||
| if (findings.length === 0) { findings.push(healthyRetentionFinding(report, evidence)); } | ||
| return findings; | ||
| } | ||
|
|
||
| function invalidRootSetFinding( | ||
| report: WarpStateCacheRetentionReport, | ||
| evidence: FindingEvidence, | ||
| ): DoctorFinding | null { | ||
| if (report.rootSetError === null) { return null; } | ||
| return { | ||
| id: 'state-cache-root-set', status: 'fail', code: CODES.STATE_CACHE_ROOT_SET_INVALID, | ||
| impact: 'data_integrity', message: `State-cache RootSet is invalid: ${report.rootSetError}`, | ||
| fix: 'Run `git warp doctor --repair-state-cache` after confirming the state-cache index is authoritative', evidence, | ||
| }; | ||
| } | ||
|
|
||
| function missingPayloadFinding( | ||
| report: WarpStateCacheRetentionReport, | ||
| evidence: FindingEvidence, | ||
| ): DoctorFinding | null { | ||
| if (report.missingSnapshotIds.length === 0) { return null; } | ||
| return { | ||
| id: 'state-cache-missing-payloads', status: 'fail', code: CODES.STATE_CACHE_PAYLOAD_MISSING, | ||
| impact: 'data_integrity', message: `${report.missingSnapshotIds.length} state-cache payload(s) no longer exist in Git`, | ||
| fix: 'Run `git warp doctor --repair-state-cache`; missing payload bytes cannot be recovered', evidence, | ||
| }; | ||
| } | ||
|
|
||
| function wrongTypeFinding( | ||
| report: WarpStateCacheRetentionReport, | ||
| evidence: FindingEvidence, | ||
| ): DoctorFinding | null { | ||
| if (report.wrongTypeSnapshotIds.length === 0) { return null; } | ||
| return { | ||
| id: 'state-cache-wrong-type', status: 'fail', code: CODES.STATE_CACHE_PAYLOAD_WRONG_TYPE, | ||
| impact: 'data_integrity', message: `${report.wrongTypeSnapshotIds.length} state-cache payload ref(s) do not identify Git trees`, | ||
| fix: 'Rebuild the affected state-cache snapshots from authoritative WARP history', evidence, | ||
| }; | ||
| } | ||
|
|
||
| function unanchoredPayloadFinding( | ||
| report: WarpStateCacheRetentionReport, | ||
| evidence: FindingEvidence, | ||
| ): DoctorFinding | null { | ||
| if (report.unanchoredSnapshotIds.length === 0) { return null; } | ||
| return { | ||
| id: 'state-cache-unanchored-payloads', status: 'fail', code: CODES.STATE_CACHE_PAYLOAD_UNANCHORED, | ||
| impact: 'data_integrity', message: `${report.unanchoredSnapshotIds.length} live state-cache payload(s) are not protected from Git GC`, | ||
| fix: 'Run `git warp doctor --repair-state-cache` before any repository cleanup', evidence, | ||
| }; | ||
| } | ||
|
|
||
| function staleRootFinding( | ||
| report: WarpStateCacheRetentionReport, | ||
| evidence: FindingEvidence, | ||
| ): DoctorFinding | null { | ||
| if (report.staleRootNames.length === 0) { return null; } | ||
| return { | ||
| id: 'state-cache-stale-roots', status: 'warn', code: CODES.STATE_CACHE_STALE_ROOTS, | ||
| impact: 'hygiene', message: `${report.staleRootNames.length} stale state-cache RootSet entry or entries retain evicted payloads`, | ||
| fix: 'Run `git warp doctor --repair-state-cache` to release stale roots', evidence, | ||
| }; | ||
| } | ||
|
|
||
| function healthyRetentionFinding( | ||
| report: WarpStateCacheRetentionReport, | ||
| evidence: FindingEvidence, | ||
| ): DoctorFinding { | ||
| return { | ||
| id: 'state-cache-retention', status: 'ok', code: CODES.STATE_CACHE_RETENTION_OK, | ||
| impact: 'data_integrity', | ||
| message: `All ${report.liveSnapshotIds.length} live state-cache payload(s) are Git-anchored`, | ||
| evidence, | ||
| }; | ||
| } | ||
|
|
||
| export function stateCacheRepairFinding(result: WarpStateCacheRepairResult): DoctorFinding { | ||
| const partial = result.unrecoverableSnapshotIds.length > 0; | ||
| return { | ||
| id: 'state-cache-retention-repair', | ||
| status: partial ? 'warn' : 'ok', | ||
| code: partial | ||
| ? CODES.STATE_CACHE_RETENTION_PARTIAL_REPAIR | ||
| : CODES.STATE_CACHE_RETENTION_REPAIRED, | ||
| impact: 'data_integrity', | ||
| message: partial | ||
| ? 'State-cache retention repair anchored every recoverable payload; some payloads were already missing' | ||
| : 'State-cache retention repair anchored the live index and released stale roots', | ||
| evidence: { | ||
| anchoredSnapshotIds: [...result.anchoredSnapshotIds], | ||
| unrecoverableSnapshotIds: [...result.unrecoverableSnapshotIds], | ||
| removedStaleRootNames: [...result.removedStaleRootNames], | ||
| }, | ||
| }; | ||
| } | ||
|
|
||
| export function stateCacheRepairFailureFinding(error: unknown): DoctorFinding { | ||
| return { | ||
| id: 'state-cache-retention-repair', | ||
| status: 'fail', | ||
| code: CODES.CHECK_INTERNAL_ERROR, | ||
| impact: 'data_integrity', | ||
| message: `State-cache retention repair failed: ${error instanceof Error ? error.message : String(error)}`, | ||
| fix: 'Resolve the repository or RootSet error, then rerun `git warp doctor --repair-state-cache`', | ||
| }; | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import type WarpStateCachePort from '../../../../src/ports/WarpStateCachePort.ts'; | ||
| import type WarpStateCacheRetentionPort from '../../../../src/ports/WarpStateCacheRetentionPort.ts'; | ||
| import defaultCodec from '../../../../src/infrastructure/codecs/CborCodec.ts'; | ||
| import type { Persistence } from '../../types.ts'; | ||
| import type { DoctorFinding } from './types.ts'; | ||
| import { | ||
| stateCacheRepairFailureFinding, | ||
| stateCacheRepairFinding, | ||
| } from './checksStateCache.ts'; | ||
|
|
||
| export type DoctorStateCache = WarpStateCachePort & WarpStateCacheRetentionPort; | ||
|
|
||
| export async function resolveStateCache( | ||
| persistence: Persistence, | ||
| graphName: string, | ||
| ): Promise<DoctorStateCache | null> { | ||
| if (typeof persistence.createRuntimeStateCache !== 'function') { return null; } | ||
| return await persistence.createRuntimeStateCache({ graphName, codec: defaultCodec }); | ||
| } | ||
|
|
||
| export async function repairStateCache( | ||
| requested: boolean, | ||
| stateCache: DoctorStateCache | null, | ||
| ): Promise<DoctorFinding | null> { | ||
| if (!requested || stateCache === null) { return null; } | ||
| try { | ||
| return stateCacheRepairFinding(await stateCache.repairRetention()); | ||
| } catch (error) { | ||
| return stateCacheRepairFailureFinding(error); | ||
| } | ||
| } | ||
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.
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.
Uh oh!
There was an error while loading. Please reload this page.