fix(centralui): no-tracking default on the circuit DbContext; mutations on their own scope (UI-1, WP5 task 5.1)
The circuit-lifetime ScadaBridgeDbContext tracked every entity a page ever loaded, so a reload returned the first-loaded instance and never saw changes made in another scope (Move to Site, Topology area renames, a template script edited by the CLI/import - which a later save then silently reverted). - CircuitDbContextTrackingHandler (CircuitHandler, registered by AddCentralUI) sets QueryTrackingBehavior.NoTracking on the circuit scope's context only, when the circuit host is built (before any component). Management-actor, command-transaction, HTTP-request and hosted-service scopes keep TrackAll. - Every remaining page mutation that ran a load-modify-save service on the circuit context now runs it via ScopeFactory.InNewScopeAsync (fresh tracking context): TemplateEdit (17 TemplateService calls), Templates (5 TemplateService + 5 TemplateFolderService), TemplateCreate, SharedScripts, SharedScriptForm, TransportImport.ApplyAsync. (Sites/Topology moved in 5.2.) - Design doc: Component-CentralUI.md 'Circuit DbContext lifetime'. Tests: CircuitDbContextTrackingTests - handler scoping + registration, the three finding scenarios against a real SQLite context (moved connection also asserts the pre-fix staleness without the handler), and a source-scan guard that fails on any mutating call through a circuit-injected load-modify-save service.
This commit is contained in:
@@ -362,12 +362,20 @@ Per-leaf alarm rendering (leaf nodes are individual conditions for native alarms
|
||||
|
||||
### Configuration mutations and live circuit authority (2026-09-09)
|
||||
|
||||
Page configuration handlers use `ConfigurationCommandService` and the guarded management command boundary. Database changes and their scrubbed audit entries commit in one transaction, including generated entity IDs. Existing instance service operations execute through the same transaction seam and retain their domain validation and audit ownership. Circuit read tracking is cleared after a separate transaction scope changes configuration.
|
||||
Page configuration handlers use `ConfigurationCommandService` and the guarded management command boundary. Database changes and their scrubbed audit entries commit in one transaction, including generated entity IDs. Existing instance service operations execute through the same transaction seam and retain their domain validation and audit ownership. Circuit read tracking is cleared after a separate transaction scope changes configuration (a no-op since the circuit context stopped tracking — see below).
|
||||
|
||||
Cookie circuits retain their initial principal without retaining `HttpContext`; authoritative reads re-map stored directory groups against current grants. Mutation handlers recheck role and persisted target site immediately before dispatch. Passive session pings do not count as user activity. Trusted browser input posts an antiforgery-protected activity signal; the server activity tracker also makes it visible to the existing circuit.
|
||||
|
||||
The explicit server-configured development auto-login mode preserves its synthetic all-role principal. It uses the Cookies scheme but has no LDAP group claims; it must not enter directory re-mapping. This exception follows validated `AuthDisableLoginOptions`, never a caller-supplied claim.
|
||||
|
||||
### Circuit DbContext lifetime (code review 2026-12-02, UI-1/2/3/8)
|
||||
|
||||
In Blazor Server one DI scope — and so one scoped `ScadaBridgeDbContext` — lives for the whole circuit. That context now reads with a **no-tracking default**: `CircuitDbContextTrackingHandler` (a `CircuitHandler`, resolved when the circuit host is built, before any component) sets `ChangeTracker.QueryTrackingBehavior = NoTracking` on the circuit scope's context only. Every reload therefore sees the database as it is, including changes made in another scope — a data connection moved through the management actor, an area renamed by another user, a template script edited by the CLI or a Transport import. Contexts in every other scope (management-actor commands, the configuration command transaction, HTTP request scopes, hosted services, singleton actors) keep EF's tracking default.
|
||||
|
||||
No page mutates configuration on the circuit's context. Writes go through `ConfigurationCommandService` (its own transaction scope), the `ManagementActor`, or `ScopedServiceExtensions.InNewScopeAsync`, which resolves the load-modify-save service (`TemplateService`, `TemplateFolderService`, `SharedScriptService`, `DeploymentService`, `ArtifactDeploymentService`, `IBundleImporter.ApplyAsync`) from a fresh scope with an empty tracking context and disposes it when the action ends. A source-scan test (`CircuitDbContextTrackingTests`) fails the build if a page calls a mutating method on a circuit-injected instance of one of those services. Adding-only writes on the circuit context (an audit row, a bundle-unlock attempt) are unaffected by the tracking default.
|
||||
|
||||
Long or concurrent page work also runs on its own scope, so it can neither collide with another query on the circuit context ("A second operation was started on this context instance") nor die with the circuit: each Deployments-page load flight, the Sites page's **Deploy Artifacts** (per site and to all sites, whose record, audit rows and revision stamp are written after the site fan-out), and Topology's **Diff**, **Enable**, **Disable** and **Delete** (alongside the existing Deploy / Deploy all / staleness checks).
|
||||
|
||||
### Isolated Test Run workers
|
||||
|
||||
Test Run executes in a disposable `CentralUI.SandboxWorker` process. A process-wide admission gate permits at most four workers. Queueing, compilation, execution and gateway calls consume the requested deadline (1–10 seconds); cancellation kills the process tree and capacity is released only after confirmed exit. Console capture retains at most 32,000 characters with an explicit truncation marker; return JSON is limited to 32,000 bytes. Private IPC frames are limited to 1 MiB and stderr is drained without accumulation. Each worker has a 512 MiB managed-heap ceiling. The worker is a resource/lifetime boundary; the semantic script trust policy still gates compilation.
|
||||
|
||||
Reference in New Issue
Block a user