fix(launcher): Campaign LA LA3 review fixes — contract paths omission, probe composition, graceful stop, hygiene

Opus review of LA3 returned FIX FIRST; this addresses every finding in
scope (F1-F5, F7-F12; F6 CI-lane addition excluded per instructions):

- F1 (CRITICAL): SessionProcessSettings.Paths is now nullable and left
  null by SessionConfigComposer unless a caller supplies overrides, so
  the JSON key is entirely absent instead of "paths":{} — the App-side
  loader's strict UnmappedMemberHandling.Disallow would otherwise reject
  every gui/guiSelect session-config document at load.
- F2: added SessionConfigComposer.ComposeProbe and a nullable
  SessionDescriptor.Mode field ("probe", omitted for normal play) per
  the pinned contract — no character/policy/plugins/loginCommands.
- F3: LauncherProcessSupervisor.Stop now tries
  ILauncherChildProcess.TryRequestGracefulStop (Linux: libc SIGINT via
  LibraryImport, K4-proven graceful headless logout) before
  CloseMainWindow. Windows has no reliable no-window-console equivalent
  today; filed docs/ISSUES.md #397 with the CREATE_NEW_PROCESS_GROUP +
  CTRL_BREAK fix direction. Stop()'s blocking-timeout contract is now
  documented for LA4.
- F4: LauncherProfileStore.Save chmods the Linux temp file to 0600
  immediately after creation, before any credential is serialized;
  failure paths and Load() clean up a stale .tmp.
- F5: added LauncherCoreDependencyBoundaryTests asserting Launcher.Core
  references exactly AcDream.Platform and no packages.
- F7: StatusEventParser.Parse no longer throws on a whitespace/null
  line; StatusFileTailer.ReadNewEvents swallows the File.Exists/open
  TOCTOU window (FileNotFoundException/DirectoryNotFoundException/
  IOException) instead of throwing.
- F8: Start() now kills (entire process tree) and disposes a child that
  started successfully but failed while being fed its stdin password,
  instead of orphaning it.
- F9: SetState is monotonic — once Exited, no later transition applies
  or fires StateChanged, closing a Start()-path race where a
  synchronously-exiting child could be "resurrected" to Running.
- F10: CharacterIdFormat.TryParse now requires the "0x" prefix (an
  unprefixed hand-typed decimal id is also valid hex and was silently
  misread); a parsed id of 0 is treated as unusable and falls back to
  the name selector; LauncherProfileStore.MergeRoster normalizes both
  sides through TryParse/ToHexString instead of raw string equality, so
  a legacy unprefixed-hex row self-heals via name match instead of
  duplicating.
- F11: StatusCharacterEntry.SecondsGreyedOut is now uint, matching
  CharacterRosterEntry and the host writer.
- F12: added MalformedStatusEvent, returned for a recognized `e` whose
  payload doesn't match its shape, distinguished from UnknownStatusEvent
  (an unrecognized `e`).

AllowUnsafeBlocks was added to AcDream.Launcher.Core.csproj — required
by the LibraryImport source generator's function-pointer marshalling
stub for F3's Linux SIGINT P/Invoke.

Verification: dotnet build AcDream.slnx -c Release green (0 errors);
dotnet test tests/AcDream.Launcher.Core.Tests -c Release green at 94/94
on native Windows and under WSL (Ubuntu, verified across multiple runs
for the timing-sensitive SIGINT/sharing-violation tests, no flakes
observed).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Erik 2026-08-14 16:29:39 +02:00
parent 37d74e4402
commit 26feba8186
19 changed files with 1101 additions and 105 deletions

View file

@ -1,4 +1,5 @@
using System.Diagnostics;
using System.Runtime.InteropServices;
namespace AcDream.Launcher.Core.Launching;
@ -28,6 +29,26 @@ public interface ILauncherChildProcess : IDisposable
void Start();
/// <summary>
/// Attempts a graceful stop signal appropriate to the platform,
/// tried BEFORE <see cref="CloseMainWindow"/> (Campaign LA plan §LA3
/// review finding F3): a no-window console host (e.g.
/// <c>AcDream.Headless</c>) never has a main window for
/// <see cref="CloseMainWindow"/> to close, so without this step
/// <see cref="LauncherProcessSupervisor.Stop"/> always degraded
/// straight to a timeout + hard <see cref="Kill"/> — and a hard kill
/// leaves the ACE account session stuck for several minutes (a
/// documented project landmine; see CLAUDE.md
/// "Logout-before-reconnect"). On Linux this sends SIGINT (K4 proved
/// the headless host's SIGINT handler produces an ACE-confirmed
/// graceful logout). On Windows there is no reliable cross-console
/// mechanism for an arbitrary no-window child process today — see
/// <c>docs/ISSUES.md</c> for the tracked gap and fix direction; this
/// returns false there. Returns true only when the signal was
/// actually delivered; never throws.
/// </summary>
bool TryRequestGracefulStop();
/// <summary>Mirrors <see cref="Process.CloseMainWindow"/> — requests
/// a graceful close via WM_CLOSE. Returns false for a console/no-
/// window process (never throws), matching the real API.</summary>
@ -54,8 +75,16 @@ public sealed class SystemChildProcessFactory : ILauncherChildProcessFactory
new SystemChildProcess(spec);
}
internal sealed class SystemChildProcess : ILauncherChildProcess
internal sealed partial class SystemChildProcess : ILauncherChildProcess
{
// SIGINT's numeric value (POSIX-stable across Linux distributions).
// K4/Slice K already proved the headless host's SIGINT handler
// produces an ACE-confirmed graceful logout.
private const int Sigint = 2;
[LibraryImport("libc", SetLastError = true)]
private static partial int kill(int pid, int sig);
private readonly Process _process;
private bool _raisingEnabled;
@ -99,6 +128,31 @@ internal sealed class SystemChildProcess : ILauncherChildProcess
_process.Start();
}
public bool TryRequestGracefulStop()
{
if (!OperatingSystem.IsLinux())
{
// No reliable cross-console mechanism exists for an
// arbitrary no-window Windows child process — tracked gap,
// see docs/ISSUES.md.
return false;
}
try
{
return kill(_process.Id, Sigint) == 0;
}
catch
{
// Matches CloseMainWindow's "never throws" contract — the
// process may not have started yet, may have already exited
// (ESRCH), or the platform may lack libc under an unusual
// Linux runtime; any of these degrade to "signal not sent"
// rather than an exception out of Stop().
return false;
}
}
public bool CloseMainWindow() => _process.CloseMainWindow();
public void Kill() => _process.Kill(entireProcessTree: true);