Files
ScadaBridge/code-reviews/README.md
T
Joseph Doherty 55f46e7c92 perf: close Theme 6 — 11 allocation / N+1 / lock-contention findings
Well-localised perf fixes across 8 modules.

Lock decoupling / SQL streaming:
- AuditLog-005: SqliteAuditWriter gains dedicated read-only _readConnection
  (+ _readLock) backed by WAL journal mode. GetBacklogStatsAsync,
  ReadPendingAsync, ReadPendingSinceAsync, ReadForwardedAsync no longer
  contend with the hot-path INSERT lock — backlog probes on a 30s timer
  can't stall the writer under multi-hundred-K Pending backlog.
- SEL-022: dropped Cache=Shared from SiteEventLogger's default connection
  string (single-connection logger; mode was dormant config).

Memory / streaming:
- CLI-019: bundle export streams base64 in 1 MB-aligned chunks via
  Convert.TryFromBase64Chars straight into the FileStream — no more
  full-bundle byte[] allocation.
- CentralUI-031: TransportImport now stages the upload to a per-session
  temp file under Path.GetTempPath() (replaces in-memory byte[] field);
  page implements IDisposable to delete the temp file on reset / new
  upload / dispose. Per-circuit working set drops from ~100 MB to ~80 KB.

N+1 hoisting:
- Transport-008: added ITemplateEngineRepository.GetTemplatesWithChildrenAsync
  bulk method; BundleImporter.PreviewAsync calls it once instead of per-
  template-name. Single query with .Include(...).AsSplitQuery().
- DM-023: BuildDeployArtifactsCommandAsync's per-site loop now references
  a pre-fetched GlobalArtifactSnapshot (shared scripts, external systems,
  DB connections, notification lists, SMTP) instead of re-querying per site.
- MgmtSvc-023: HandleQueryDeployments unfiltered branch uses one
  GetAllInstancesAsync bulk load + Dictionary<int,int?> lookup (was a
  GetInstanceByIdAsync per record).

Small allocations / per-tick rebuilds:
- InboundAPI-019: AuditWriteMiddleware gates EnableBuffering() on
  RequestHasBody() so GET/HEAD/DELETE/TRACE/OPTIONS and Content-Length:0
  requests skip the FileBufferingReadStream allocation.
- NotifOutbox-006: ResolveAdapters dictionary now cached on
  _adaptersCache (built lazily on first sweep) + actor-lifetime
  _adaptersScope; ResolveAdapters no longer rebuilds per dispatch tick.

Verify-only:
- Comm-017: Confirmed _inProgressDeployments was deleted by Comm-016 in
  commit ac96b83 — marked Resolved with that attribution. No code change.

Doc-correction:
- NS-022: Updated MailKitSmtpClientWrapper XML doc to spell out single-
  connection / per-delivery-factory contract (option (b) — transient
  client per Send — rejected because it re-handshakes TLS per email).

10+ new regression tests across 8 test projects. Build clean; affected
suites all green. README regenerated: 54 open (was 65).
2026-05-28 07:47:24 -04:00

13 KiB

Code Reviews

Comprehensive, per-module code reviews of the ScadaLink codebase. Each module (one buildable project under src/) has its own folder containing a findings.md. This README is the aggregated index — the single place to see all outstanding work.

Generated by regen-readme.py from the per-module findings.md files. Do not edit by hand — edit the findings files and re-run the script.

How it works

  • Reviews are performed one module at a time against a fixed checklist.
  • Every finding is recorded in the module's findings.md with a severity and status.
  • Findings are never deleted — they are closed by changing their status, keeping a full audit trail.
  • This README aggregates every pending finding (Open / In Progress) across all modules.

See REVIEW-PROCESS.md for the full procedure: the review checklist, severity definitions, finding format, and how to mark items resolved.

Layout

code-reviews/
├── README.md            # this file — process overview + pending findings
├── REVIEW-PROCESS.md     # how to perform a review and track findings
├── regen-readme.py       # regenerates this README from the findings files
├── _template/findings.md # copy-this template for a module review
└── <Module>/findings.md  # one folder per src/ project

Baseline review — 2026-05-16

All 19 modules were reviewed at commit 9c60592 (241 findings: 6 Critical, 46 High, 100 Medium, 89 Low). The tables below track what remains open as findings are resolved and re-triaged; findings discovered after the baseline are appended to their module file and counted in Total.

Severity Open findings
Critical 0
High 0
Medium 19
Low 35
Total 54

Module Status

Module Last reviewed Commit Open (C/H/M/L) Open Total
AuditLog 2026-05-28 1eb6e97 0/0/1/1 2 11
CLI 2026-05-28 1eb6e97 0/0/0/2 2 23
CentralUI 2026-05-28 1eb6e97 0/0/0/3 3 33
ClusterInfrastructure 2026-05-28 1eb6e97 0/0/0/3 3 14
Commons 2026-05-28 1eb6e97 0/0/0/4 4 23
Communication 2026-05-28 1eb6e97 0/0/0/1 1 22
ConfigurationDatabase 2026-05-28 1eb6e97 0/0/1/2 3 24
DataConnectionLayer 2026-05-28 1eb6e97 0/0/0/0 0 22
DeploymentManager 2026-05-28 1eb6e97 0/0/0/3 3 24
ExternalSystemGateway 2026-05-28 1eb6e97 0/0/1/1 2 23
HealthMonitoring 2026-05-28 1eb6e97 0/0/0/2 2 23
Host 2026-05-28 1eb6e97 0/0/1/3 4 22
InboundAPI 2026-05-28 1eb6e97 0/0/1/1 2 25
ManagementService 2026-05-28 1eb6e97 0/0/2/0 2 23
NotificationOutbox 2026-05-28 1eb6e97 0/0/0/1 1 10
NotificationService 2026-05-28 1eb6e97 0/0/1/1 2 25
Security 2026-05-28 1eb6e97 0/0/0/1 1 21
SiteCallAudit 2026-05-28 1eb6e97 0/0/2/1 3 6
SiteEventLogging 2026-05-28 1eb6e97 0/0/0/2 2 23
SiteRuntime 2026-05-28 1eb6e97 0/0/2/0 2 26
StoreAndForward 2026-05-28 1eb6e97 0/0/3/2 5 24
TemplateEngine 2026-05-28 1eb6e97 0/0/3/0 3 22
Transport 2026-05-28 1eb6e97 0/0/1/1 2 12

Pending Findings

Every Open / In Progress finding across all modules, highest severity first. Resolved findings drop off this list but remain recorded in their module's findings.md (see REVIEW-PROCESS.md §4–§5). Full detail — description, location, recommendation — lives in the module's findings.md.

Critical (0)

None open.

High (0)

None open.

Medium (19)

ID Module Title
AuditLog-001 AuditLog Combined-telemetry transport is plumbed end-to-end but never invoked in production
ConfigurationDatabase-016 ConfigurationDatabase InboundApiRepository.GetApiKeyByValueAsync hashes the candidate with the unpeppered ApiKeyHasher.Default
ExternalSystemGateway-020 ExternalSystemGateway JsonElementToParameterValue silently downcasts non-Int64 JSON numbers to double, losing precision for decimal SQL parameters on retry
Host-016 Host Site CentralContactPoints second entry targets the site's own remoting port
InboundAPI-025 InboundAPI AuditWriteMiddleware runs against the entire /api/* branch — emits spurious ApiInbound audit rows for /api/audit/query and /api/audit/export
ManagementService-020 ManagementService UpdateSmtpConfig returns and audits the SMTP Credentials field verbatim
ManagementService-021 ManagementService Transport bundle handlers have zero test coverage
NotificationService-024 NotificationService No test affirms the central-only invariant; the orphaned-path tests give a false coverage signal
SiteCallAudit-001 SiteCallAudit SupervisorStrategy override is dead code; XML claims Resume that is not enforced
SiteCallAudit-003 SiteCallAudit OnUpsertAsync does not refresh IngestedAtUtc; direct-write callers must remember to stamp it
SiteRuntime-021 SiteRuntime HandleDeployArtifacts updates DataConnections in SQLite but never sends CreateConnectionCommand to the DCL
SiteRuntime-022 SiteRuntime AuditingDbCommand.DbConnection.set uses reflection to read AuditingDbConnection._inner
StoreAndForward-019 StoreAndForward Notifications park after DefaultMaxRetries exhaustion, contradicting "retried until central acks"
StoreAndForward-020 StoreAndForward RetryParkedMessageAsync skips standby replication when the message is deleted between local update and re-load
StoreAndForward-021 StoreAndForward Design doc claims the Operation Tracking Table lives in StoreAndForward but the implementation is in SiteRuntime
TemplateEngine-018 TemplateEngine DiffService reports no entries for added/removed/changed connections
TemplateEngine-019 TemplateEngine TemplateResolver.BuildInheritanceChain still uses the 0-as-no-parent sentinel that was removed from CycleDetector
TemplateEngine-020 TemplateEngine Create* audit entries are written with EntityId = "0" before SaveChangesAsync populates the real key
Transport-010 Transport Critical Overwrite + cross-cutting paths uncovered by tests

Low (35)

ID Module Title
AuditLog-008 AuditLog Test composition roots that omit IAuditPayloadFilter silently pass UNREDACTED payloads through the writer chain
CLI-020 CLI bundle export success-envelope parse is unguarded
CLI-022 CLI CommandTreeTests excludes the two new command groups
CentralUI-029 CentralUI ConfigurationAuditLog uses JS.InvokeAsync<int>("eval", ...) instead of a dedicated JS module
CentralUI-032 CentralUI AuditResultsGrid paging is forward-only, no Previous button
CentralUI-033 CentralUI Drill-in / query-string code paths for the new Transport + SiteCalls pages are untested
ClusterInfrastructure-011 ClusterInfrastructure SectionName constant is decorative — no binding site references it
ClusterInfrastructure-013 ClusterInfrastructure Test uses catastrophic config values without an inline-intent comment
ClusterInfrastructure-014 ClusterInfrastructure AddClusterInfrastructureActors is dead surface — no caller, no behaviour
Commons-016 Commons BundleSession.Locked uses a magic 3 rather than a named constant
Commons-018 Commons IOperationTrackingStore and IPartitionMaintenance are at the root of Interfaces/ instead of Interfaces/Services/
Commons-020 Commons Transport types and new Audit-message types have no unit tests in ScadaLink.Commons.Tests
Commons-023 Commons Trailing-optional SourceNode on positional records mixes additive evolution patterns
Communication-020 Communication SiteAddressCacheLoaded carries mutable Dictionary/List types
ConfigurationDatabase-021 ConfigurationDatabase SwitchOutPartitionAsync interpolates monthBoundary / staging table name into raw SQL
ConfigurationDatabase-024 ConfigurationDatabase Missing test coverage for SPLIT-RANGE failure-continuation and production-shape rowversion delete
DeploymentManager-021 DeploymentManager ResolveSiteIdentifierAsync silently substitutes the DB id when the site row is missing
DeploymentManager-022 DeploymentManager Pending and InProgress are written back-to-back with no intervening work
DeploymentManager-024 DeploymentManager Test probe actors hold mutable static state across tests
ExternalSystemGateway-021 ExternalSystemGateway ApplyAuth silently sends an unauthenticated request on unknown AuthType, empty AuthConfiguration, or malformed Basic config
HealthMonitoring-021 HealthMonitoring CentralSiteId = "central" reserved constant silently collides with a real site named "central"
HealthMonitoring-022 HealthMonitoring CentralHealthReportLoopTests uses real-time PeriodicTimer + Task.Delay; flake-prone on slow CI
Host-018 Host Shipped per-role configs omit NodeOptions.NodeName, leaving SourceNode null
Host-020 Host MinimumLevel.Is silently overrides any operator-set Serilog:MinimumLevel
Host-021 Host Microsoft Logging:LogLevel section in appsettings.json is dead config under Serilog
InboundAPI-023 InboundAPI EndpointExtensions.HandleInboundApiRequest composition wiring has no test coverage
NotificationOutbox-008 NotificationOutbox FallbackMaxRetries / FallbackRetryDelay path is unreachable in production AND untested
NotificationService-025 NotificationService CredentialRedactor over-masks: any 4-character credential component is masked anywhere it appears, including unrelated log text
Security-021 Security RequireHttpsCookie=false dev opt-out has no warning path — an HTTP production deployment silently transmits the JWT bearer credential in cleartext
SiteCallAudit-006 SiteCallAudit Stuck-only paging test does not exercise the multi-page boundary with an interleaved non-stuck row at the cursor
SiteEventLogging-018 SiteEventLogging FailedWriteCount is exposed but never consumed by Health Monitoring
SiteEventLogging-023 SiteEventLogging Concurrent-stress test uses a non-volatile stop flag
StoreAndForward-022 StoreAndForward NotifyCachedCallObserverAsync silently drops the entire audit lifecycle when the message id is not a parseable TrackedOperationId
StoreAndForward-023 StoreAndForward siteId silently defaults to empty when no IStoreAndForwardSiteContext is registered, degrading audit telemetry correlation
Transport-012 Transport "Bundle Import" filter promised in design doc not surfaced in Configuration Audit Log Viewer UI