Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions docs/preview2-package-pin.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,14 +253,28 @@ The published-host suite runs with `MCSL_PUBLISHED_DAEMON` pointing at a
published daemon and `MCSL_PLUGIN_PACKAGE_SOURCE` pointing at the three
nupkgs above.

### Known coverage gap carried into MCP-6

The published-host suite still exercises only plugin load, RPC/event serving,
and shutdown behaviour. It does not yet drive `mcsl.backup.*` or poll a real
long-running operation against a live daemon. Both need a daemon-side fake
operation fixture and are tracked as the remaining SDK-9b/MCP-6 item; they do
not block the internal pin because every one of those paths is covered by the
in-process protocol suite.
### Coverage gap closed in MCP-6

The published-host suite no longer stops at plugin load, RPC/event serving,
and shutdown behaviour. It now runs and polls a real long operation against a
live daemon. Covered, exactly:

- `mcsl.backup.create` against a stopped instance, polled through a running
snapshot to `succeeded`.
- `mcsl.backup.list`, cross-checked against the operation's result reference.
- `mcsl.backup.restore.plan` → `.confirm` → `.execute`, cancelled during the
extraction stage, asserting the outcome is `cancelled` and the instance
working directory was not swapped.
- A second restore of the same archive, run to `succeeded`.

Not covered: `mcsl.backup.prune`, and `Maintenance: true` backup of a running
instance. No daemon-side fake operation fixture was needed; the archived
payload is sized so extraction is genuinely long enough to cancel within.

The cancelled-means-no-swap assertion holds because the coordinator honours
the spec section 7 commit point: an executor that has committed its side
effects keeps its own terminal status instead of being downgraded to
cancelled.

Distribution is internal-only. Public distribution requires explicitly
reopening the package gate.
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,11 @@ private async Task<Result<string, DaemonError>> RunRestoreAsync(
return Result.Err<string, DaemonError>(extractError!);

context.SetStage(OperationStage.Installing);
// Last cooperative observation point. Past the mark the working directory is replaced
// and the original tree deleted, so a cancellation arriving later must not report
// "cancelled" over a restore that actually happened.
cancellationToken.ThrowIfCancellationRequested();
((IOperationCommitPoint)context).MarkCommitted();
MoveDirectoryWithRetry(workingDirectory, retiredDirectory);
try
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@

namespace MCServerLauncher.Daemon.ApplicationCore.Operations;

/// <summary>
/// Marks the point past which an executor's side effects are real. Spec section 7: once side
/// effects are committed, the executor's terminal status wins and a late cancellation must not
/// downgrade it to cancelled. Deliberately internal — the seam belongs to the daemon, not to the
/// packaged plugin surface.
/// </summary>
internal interface IOperationCommitPoint
{
void MarkCommitted();
}

/// <summary>
/// Daemon-owned long-running operation coordinator.
/// Progress is coalesced in memory; index persistence is rate-limited for progress and
Expand Down Expand Up @@ -332,7 +343,7 @@ private async Task RunOperationAsync(
{
var context = new CoordinatorOperationContext(runtime, this);
var result = await executor(scope.ServiceProvider, context, linked.Token).ConfigureAwait(false);
if (linked.IsCancellationRequested || runtime.CancellationRequested)
if ((linked.IsCancellationRequested || runtime.CancellationRequested) && !runtime.Committed)
{
completion = OperationCompletion.Cancelled();
}
Expand Down Expand Up @@ -951,6 +962,7 @@ internal sealed class OperationRuntime : IDisposable
private readonly bool _recoverOnly;
private bool _cancellationRequested;
private bool _completionPrepared;
private bool _committed;
private int _disposed;

public OperationRuntime(OperationSnapshot snapshot, bool recoverOnly = false)
Expand Down Expand Up @@ -984,6 +996,21 @@ public bool CancellationRequested
}
}

public bool Committed
{
get
{
lock (_gate)
return _committed;
}
}

public void MarkCommitted()
{
lock (_gate)
_committed = true;
}

public bool TryCreateCancellationSnapshot(DateTimeOffset now, out OperationSnapshot candidate)
{
lock (_gate)
Expand Down Expand Up @@ -1094,7 +1121,9 @@ public bool TryPrepareCompletion(
if (_completionPrepared || IsTerminal(_snapshot.Status))
return false;

if (_cancellationRequested && completion.Status is not OperationStatus.Interrupted)
// A committed executor keeps its own outcome (spec section 7); only an interrupted
// one is exempt from the downgrade regardless.
if (_cancellationRequested && !_committed && completion.Status is not OperationStatus.Interrupted)
prepared = OperationCompletion.Cancelled();

// Freeze the effective outcome before invoking the domain commit. Late cancellation
Expand Down Expand Up @@ -1249,7 +1278,7 @@ internal static OperationCompletion Interrupted(string? message = null) =>
null);
}

private sealed class CoordinatorOperationContext : IOperationContext
private sealed class CoordinatorOperationContext : IOperationContext, IOperationCommitPoint
{
private readonly OperationRuntime _runtime;
private readonly OperationCoordinator _coordinator;
Expand All @@ -1263,6 +1292,8 @@ public CoordinatorOperationContext(OperationRuntime runtime, OperationCoordinato

public Guid OperationId => _runtime.Snapshot.OperationId;

public void MarkCommitted() => _runtime.MarkCommitted();

public void SetStage(OperationStage stage) =>
_coordinator.ReportProgress(_runtime, stage, progress: null);

Expand Down
Loading
Loading