Skip to content

refactor: wire alert factory, doctor helpers, and IdGen (Phase 4)#687

Closed
Aaronontheweb wants to merge 2 commits intodevfrom
feature/alert-factory-doctor-helpers
Closed

refactor: wire alert factory, doctor helpers, and IdGen (Phase 4)#687
Aaronontheweb wants to merge 2 commits intodevfrom
feature/alert-factory-doctor-helpers

Conversation

@Aaronontheweb
Copy link
Copy Markdown
Collaborator

Summary

  • OperationalAlert.Create(): Replace all 16 new OperationalAlert { ... } constructions across 10 production files with calls to OperationalAlert.Create(timeProvider, ...), which auto-generates AlertId via IdGen.AlertId() and sets Timestamp from the injected TimeProvider. Also fixes a bug in BinaryUpdateCheckService where AlertId was set to a full 32-char GUID instead of the expected 12-char truncation.
  • DoctorJsonConfigReader.ReadBool / ReadStringArray: Remove 4 private ReadBool copies and 1 private ReadStringArray copy from doctor check files, replacing all call sites with DoctorJsonConfigReader.ReadBool(...) and DoctorJsonConfigReader.ReadStringArray(...).
  • CrashLogHelper.IsCrashLogStale / TryParseCrashTimestamp: Remove 2 private IsCrashLogStale and 2 private TryParseCrashTimestamp copies from doctor check files, replacing all call sites with shared CrashLogHelper methods.
  • IdGen.ShortId() / IdGen.Suffix(): Replace 5 scattered Guid.NewGuid().ToString("N")[..8] patterns with IdGen.ShortId() and 2 Guid.NewGuid().ToString("N")[..6] patterns with IdGen.Suffix().

Files changed (22)

OperationalAlert.Create() wiring (10 files, 16 sites):

  • src/Netclaw.Daemon/Services/DaemonLifecycleNotifier.cs (3 sites)
  • src/Netclaw.Daemon/Mcp/McpClientManager.cs (2 sites)
  • src/Netclaw.Daemon/Mcp/McpOAuthService.cs (2 sites)
  • src/Netclaw.Daemon/Configuration/FailoverChatClient.cs (2 sites)
  • src/Netclaw.Daemon/Configuration/AlertingChatClientDecorator.cs (1 site)
  • src/Netclaw.Daemon/Services/BinaryUpdateCheckService.cs (1 site, also fixes missing [..12] truncation)
  • src/Netclaw.Daemon/Webhooks/WebhookEndpointRouteBuilderExtensions.cs (1 site)
  • src/Netclaw.Daemon/Webhooks/WebhookRouteCatalog.cs (1 site)
  • src/Netclaw.Channels.Slack/SlackChannel.cs (1 site)
  • src/Netclaw.Actors/Reminders/ReminderManagerActor.cs (2 sites)

Doctor helper dedup (6 files):

  • src/Netclaw.Cli/Doctor/SlackAuthDoctorCheck.cs (removed private ReadBool)
  • src/Netclaw.Cli/Doctor/SlackAclDoctorCheck.cs (removed private ReadBool + ReadStringArray)
  • src/Netclaw.Cli/Doctor/TelemetryDoctorCheck.cs (removed private ReadBool)
  • src/Netclaw.Cli/Doctor/DoctorFixService.cs (removed private ReadBool)
  • src/Netclaw.Cli/Doctor/DaemonCrashDoctorCheck.cs (removed IsCrashLogStale + TryParseCrashTimestamp)
  • src/Netclaw.Cli/Doctor/SqliteProvisioningDoctorCheck.cs (removed IsCrashLogStale + TryParseCrashTimestamp)

IdGen wiring (6 files, 7 sites):

  • src/Netclaw.Actors/Channels/ChannelPipeline.cs (ShortId)
  • src/Netclaw.Channels.Slack/SlackConversationActor.cs (ShortId)
  • src/Netclaw.Actors/Sessions/LlmSessionActor.cs (ShortId)
  • src/Netclaw.Cli/Tui/ProviderManagerViewModel.cs (ShortId + Suffix)
  • src/Netclaw.Cli/Tui/ModelManagerViewModel.cs (ShortId)
  • src/Netclaw.Actors/Reminders/ReminderIdGenerator.cs (Suffix)

Net impact

  • 22 files changed, 155 insertions, 279 deletions (-124 lines)
  • Zero new behavior changes (pure mechanical refactor)

Test plan

  • dotnet build succeeds with 0 errors, 0 warnings
  • dotnet test passes all 2,482 tests (0 failures)

…agnostics

Additive-only extraction of shared helpers to eliminate duplicated code across
pipeline actors, alert emission sites, and doctor checks. No existing behavior
changes — all helpers are new code with new tests.

New types:
- SessionPipelineHandle: composition helper for pipeline lifecycle (init, reinit, dispose)
- ExecutionOutputAccumulator: output buffering + notification tracking for execution actors
- OperationalAlert.Create(): factory method normalizing alert construction (replaces 16 sites)
- IdGen: centralized ID generation (AlertId, ShortId, Suffix, Full)
- CrashLogHelper: shared crash-log parsing for doctor checks
- DoctorJsonConfigReader.ReadBool/ReadStringArray: shared JSON helpers

Test infrastructure:
- ScriptedSessionPipeline and FailingSessionPipeline extracted to shared TestHelpers
- 22 new unit tests covering all extracted helpers

Refs #306
@Aaronontheweb
Copy link
Copy Markdown
Collaborator Author

Superseded by #686 which now includes the full consolidation.

@Aaronontheweb Aaronontheweb deleted the feature/alert-factory-doctor-helpers branch May 6, 2026 18:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant