Repository navigation
fix(#1462): a stranded Compiling claim is re-driven by the sweep that already runs
#1593
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
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,81 @@ | ||
| using System; | ||
| using MeshWeaver.Graph.Configuration; | ||
| using MeshWeaver.Mesh.Services; | ||
| using Xunit; | ||
|
|
||
| namespace MeshWeaver.Hosting.Test; | ||
|
|
||
| /// <summary> | ||
| /// Issue #1462 — <c>Compiling</c> is a NON-TERMINAL state that nothing reconciles. | ||
| /// | ||
| /// <para>The flip to <c>Compiling</c> is durable; the terminal write is not guaranteed. A process | ||
| /// death mid-compile therefore leaves the row there permanently, and the prewarmer's | ||
| /// "don't clobber an in-flight compile" guard then declines to touch it on every subsequent sweep. | ||
| /// The type never reaches a terminal state: neither <c>Ok</c> (usable) nor <c>Error</c> | ||
| /// (classifiable), it holds portal readiness, and it parks every instance hub for the full | ||
| /// activation budget. One row on <c>public.mesh_nodes</c> sat at <c>Compiling</c> for TEN WEEKS — | ||
| /// harmless only because it was an orphan the prewarmer never enumerates.</para> | ||
| /// | ||
| /// <para>🚨 What the fix is NOT: a timer, a poller, or a background sweep for stale rows — the issue | ||
| /// rules those out explicitly, and so does AGENTS.md. The recovery rides the enumeration that | ||
| /// ALREADY runs, and only ever reinterprets a claim that has provably expired. These cases pin that | ||
| /// distinction, which is the whole substance of the change.</para> | ||
| /// </summary> | ||
| public class StrandedCompileClaimTest | ||
| { | ||
| private static readonly TimeSpan Budget = TimeSpan.FromMinutes(5); | ||
|
|
||
| private static NodeTypeDefinition Def(CompilationStatus status, DateTimeOffset? startedAt = null) => | ||
| new() { Configuration = "config => config", CompilationStatus = status, LastCompileStartedAt = startedAt }; | ||
|
|
||
| [Fact] | ||
| public void APendingClaimIsAlwaysHonoured() | ||
| { | ||
| // Pending is what the prewarmer itself writes to ASK for a compile, and a driver picks it up | ||
| // promptly — re-driving it would fight our own request. | ||
| DynamicTypePreWarmer.IsLiveCompileClaim(Def(CompilationStatus.Pending), Budget) | ||
| .Should().BeTrue("Pending is this prewarmer's own request, not a stranded claim"); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void ACompilingClaimInsideTheBudgetIsHonoured() | ||
| { | ||
| var justStarted = Def(CompilationStatus.Compiling, DateTimeOffset.UtcNow.AddSeconds(-5)); | ||
|
|
||
| DynamicTypePreWarmer.IsLiveCompileClaim(justStarted, Budget) | ||
| .Should().BeTrue("a compile that started 5 s ago can still be in flight — clobbering it " | ||
| + "would restart work that is about to finish"); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void ACompilingClaimOlderThanTheBudgetIsStranded() | ||
| { | ||
| var stale = Def(CompilationStatus.Compiling, DateTimeOffset.UtcNow - Budget - TimeSpan.FromMinutes(1)); | ||
|
|
||
| DynamicTypePreWarmer.IsLiveCompileClaim(stale, Budget) | ||
| .Should().BeFalse("past the budget no driver is still working on it — it either finished " | ||
| + "(and would have written a terminal state) or it died, and deferring " | ||
| + "to it forever is what made this permanent"); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void ACompilingClaimWithNoStartTimestampIsStranded() | ||
| { | ||
| // A live compile always stamps LastCompileStartedAt. An unstamped Compiling is exactly the | ||
| // shape a row left over from an older write carries — the ten-week row's shape. | ||
| DynamicTypePreWarmer.IsLiveCompileClaim(Def(CompilationStatus.Compiling), Budget) | ||
| .Should().BeFalse("an unstamped Compiling cannot be shown to be in flight, and honouring " | ||
| + "it forever is precisely the defect"); | ||
| } | ||
|
|
||
| [Theory] | ||
| [InlineData(CompilationStatus.Ok)] | ||
| [InlineData(CompilationStatus.Error)] | ||
| [InlineData(CompilationStatus.Unavailable)] | ||
| [InlineData(CompilationStatus.Unknown)] | ||
| public void ATerminalOrUnclaimedStatusIsNotAClaim(CompilationStatus status) | ||
| { | ||
| DynamicTypePreWarmer.IsLiveCompileClaim(Def(status), Budget) | ||
| .Should().BeFalse("only Pending and a fresh Compiling are claims to defer to"); | ||
| } | ||
| } | ||
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.