Skip to content
Open
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,6 @@ FakesAssemblies/
src/.vs
src/.idea
src/global.json

# Mimosa security scan local state
.mimosa/
84 changes: 80 additions & 4 deletions docs/bowl-integration-v1.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,47 @@ after starting the application.

## Configuration

For crash collection during an update, enable the independent option on the
Client bootstrap:

```csharp
bootstrap.SetOption(Option.BowlCrashCollectionEnabled, true);
```

It defaults off. When enabled it requests v1 monitoring and crash capture,
using `C:\Bowl\Bowl.Host.exe` unless `Monitoring.ExecutablePath` is already
set. Deploy a compatible Bowl host first; an unavailable host stops the update
before application files are changed. This option does not change
`LaunchClientAfterUpdate`: without application relaunch, Bowl supervises the
updater but has no relaunched application to observe. Capture is Windows-only
and limited to the v1 update/health-observation window, not a long-running
watchdog. A valid target version is required.

The current standalone Bowl.Host does not implement that crash capture request
or produce `crash-outbox` cases. The separate `bowl.exe watch` diagnostic
program produces legacy `<installPath>\fail` cases, but is not launched by this
option and must be deployed and configured separately. Do not rely on this
option alone to collect crashes with the current Bowl.Host.

The Client uploads Bowl's completed crash cases from
`<DiagnosticsDirectory>\crash-outbox\<version>\<guid>`; the legacy
`<installPath>\fail` outbox remains supported. Use the same durable state root
for updater, Bowl and subsequent Client runs. Configure `ReportUrl` (whose
origin determines `/Fault/UploadArtifact`) or `Option.DiagnosticsReportUrl`,
and set `X-Tenant-Id` through `UpdateRequest.CustomHeaders` as required by
GeneralSpace. Outbox failures remain on disk for retry on a subsequent Client
run; no retry limit applies to this option. Evidence is removed only after the
server returns HTTP success, JSON `code` 200 and a matching `body.artifactId`.
Oversized or excluded dumps remain on disk. Existing separately enabled
self-check/rollback diagnostics are unchanged.

Ordinary update failures with a server record ID also publish a minimal,
credential-free case under `<state-root>\update-outbox\<installation-id>\<guid>`.
It contains only an allowlisted failure phase and record identifiers, not a
stack trace or dump. A subsequent Client run with diagnostics enabled and the
same installation identity uploads it; failed delivery remains pending without
a retry limit. No case is created if the server record ID is unavailable.

Configure `UpdateRequest.Monitoring` and `UpdateRequest.DiagnosticsDirectory`
through `SetConfig`, JSON configuration, or `UpdateRequestBuilder`:

Expand All @@ -38,11 +79,26 @@ builder.SetDiagnosticsDirectory(@"C:\ProgramData\MyProduct\UpdateState")
HealthTimeoutSeconds = 5,
UpdateTimeoutSeconds = 600,
AutoRollback = false,
CredentialEnvironmentVariable = "MYPRODUCT_REPORT_TOKEN"
CredentialEnvironmentVariable = "MYPRODUCT_REPORT_TOKEN",
AppKeyEnvironmentVariable = "MYPRODUCT_APP_KEY"
});
```

Only enable this after deploying a separately validated compatible production host.
`AppKeyEnvironmentVariable` names a separately provisioned environment variable
whose value must equal the verification `AppSecretKey`; it must be available to
both the initial host and every `--retry` process. Only the name is persisted.
App-key reporting requires HTTPS (or HTTP to a literal loopback IP for local
testing). Missing credentials leave Bowl delivery pending.

**Automatic monitored rollback is currently unavailable.** Setting `AutoRollback`
to true aborts before application files are modified: the producer cannot yet
provide Bowl's complete write-ahead rollback plan. In particular, do not use
older mirror-rollback hosts against real installations: backup-excluded
directories and newly created user data could otherwise be deleted.
The Client rejects all update preparation when monitored automatic rollback
is requested: backup and updater packages otherwise run before the monitor
can hold a trusted installation lease.
Timeouts must be positive and the update timeout must exceed the readiness
timeout. Missing executables, malformed/mismatched ready records, host exit, or
readiness timeout abort the update before application file operations.
Expand All @@ -61,6 +117,11 @@ including attempts launched by different users or schedulers. Bowl's persistent
installation-owner lock is scoped to that root; choosing a fresh root per attempt
would bypass cross-attempt coordination. Configure an explicit shared root when
the default per-user directory does not provide this guarantee.
The Client stores a random installation UUID under that root and sends it as
`deviceId` in both version-verification calls; keep the root and installation
path stable across upgrades and restarts. Clearing the root, relocating the
installation, or using different roots creates a new identity. Custom download
sources must provide their own stable identity when calling GeneralSpace.

Client creates `UpdateAttemptId` once per workflow; standard/silent IPC carries
it, the root and monitor options to Update. OSS transfers these through child
Expand Down Expand Up @@ -103,11 +164,13 @@ replaceable files must permit `FileShare.Delete` as well as reading.
"healthTimeoutSeconds": 5,
"updateTimeoutSeconds": 600,
"autoRollback": false,
"crashCollectionEnabled": false,
"report": {
"url": "https://updates.example.test/report",
"recordId": 42,
"type": 1,
"credentialEnvironmentVariable": "MYPRODUCT_REPORT_TOKEN"
"credentialEnvironmentVariable": "MYPRODUCT_REPORT_TOKEN",
"appKeyEnvironmentVariable": "MYPRODUCT_APP_KEY"
}
}
```
Expand Down Expand Up @@ -219,7 +282,8 @@ Bowl.Host --retry 100 --state-root <shared-absolute-directory>
```

The retry limit is 1 through 100. Failed HTTP delivery stays pending and follows
the host's retry backoff; only 2xx acknowledges it. Provision reporting credentials
the host's retry backoff; app-key reports require HTTP success and JSON
`code=200`, `isSuccess=true`, `body=true`. Provision reporting credentials
for that scheduled process as well as the initially launched host. The optional
Bearer environment credential is only sent over HTTPS.

Expand Down Expand Up @@ -270,7 +334,13 @@ depend on a successful network call.

Default HTTP serialization is deliberately still exactly
`{"recordId":42,"status":2,"type":1}` (1 Updating / 2 Success / 3 Failure).
The richer local shape is **not uploaded** and no server API is changed.
When configured by the bootstrap, the in-memory app key is also sent in the
HTTP body and never persisted in pending reports. A scheduler replaying pending
reports must configure the reporter with the same app key and endpoint used by
the original verification; a business rejection keeps the report pending.
Credentialed reports require HTTPS or a literal loopback HTTP address and a
confirmed GeneralSpace business response. Legacy uncredentialed endpoints may
still acknowledge with an empty 2xx response. The richer local shape is **not uploaded**.
Non-2xx responses now throw from `HttpUpdateReporter`; role-level wrappers
log/isolate them so application/rollback work can proceed. Direct reporter
callers must handle those exceptions. `monitorUnavailable` has no honest
Expand Down Expand Up @@ -309,6 +379,12 @@ $env:GENERALUPDATE_REAL_BOWL_HOST = 'C:\External\Bowl.Host.exe'
dotnet test tests\CoreTest\CoreTest.csproj --filter FullyQualifiedName~RealBowlIntegrationTests
```

On Windows, setting `GENERALUPDATE_CRASH_TEST_PEER` to the independently built
`Bowl.TestPeer.dll` also enables a real unhandled-exception capture test. It
checks the resulting nonempty dump and schema-2 outbox, then exercises the
Client scanner against a simulated HTTP server that first rejects the upload
at the business layer and then acknowledges the same GUID.

Six scenarios have been verified against the independently built net8.0 host:
files-only success, the complete application-survival window, launch failure,
application exit during that window (`healthCheckFailure`), real updater
Expand Down
77 changes: 77 additions & 0 deletions docs/controlled-full-zip-apply-internal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Internal controlled full ZIP apply foundation

This Windows-only component is **not wired into production**, is not an
authorization entrypoint, and does not perform rollback or recovery. It assumes
a trusted caller with externally enforced exclusive access to the target tree,
staging files, snapshots, and state directory for the whole operation and any
subsequent recovery. Path and hash checks do not provide fencing or establish
ACL authorization. Do not call it against a live, concurrently writable tree.

`GeneralUpdate.ControlledWorker` is a separate executable placeholder for a
future production controller. It currently rejects every invocation with exit
code 2 without reading requests, preparing snapshots, or writing to disk. The
test-only READY/GO protocol below must not be used to enable it. A production
implementation requires an independently verified Host protocol and full
recovery/reporting lifecycle before this guard can be removed.

`ControlledFullZipPlan` copies the supplied entries and protected relative paths.
Each `ControlledFullZipEntry` describes a relative destination, staged payload and
SHA-256, and either a snapshot plus original SHA-256, or two nulls indicating a
destination that must not exist. Paths use canonical Windows spelling and `\`
separators. The caller must provide existing destination parent directories,
existing stage and snapshot files, and an existing trusted state directory.
State and inputs must be outside the target tree; state is also separate from
inputs. Only fixed local NTFS volumes are supported. Reparse points, hard-linked
files, alternate streams, sparse, encrypted, offline, read-only and device files,
short-name-style components, reserved names, overlapping entries and protected
paths are rejected. `.backups` is always protected. There is no directory
creation, file deletion, metadata preservation contract, or support for
arbitrary package executors.

`ControlledFullZipPrepare.Prepare` builds this write set from one staged full ZIP.
It requires disjoint existing target, state, stage and empty backup directories,
checks the complete set of target paths and opens existing originals before
copying and flushing snapshots under `backup\<relative path>`. The target parent
directories must already exist. Preparation retains any partial snapshots after
failure and does not create an intent or modify the installation. Like apply,
it requires an independently authenticated controller and exclusive access;
its checks cannot establish either. It does not preserve file metadata.
Once an intent is published, the owner must retain the stage as well as the
snapshots until a trusted recovery or completion decision. Calling
`StagedZip.RetainForRecovery` in the intent callback prevents normal disposal
from removing files referenced by the intent; this transfers cleanup ownership
to the controller and is not itself a cleanup or recovery protocol.

`ControlledFullZipApply.Apply(plan)` validates every entry and verifies the
original, snapshot and payload hashes before writing targets. It flushes supplied
snapshots, publishes a complete versioned JSON intent in the state directory
using create-new and `Flush(true)`, then copies each payload to a create-new
temporary file in the destination directory, flushes and verifies it, checks the
target again, replaces or moves without overwrite, and verifies the result. The
intent includes entries with `path`, `originalSha256` (null for new files), and
`updatedSha256`, plus paths required to inspect the operation. Snapshots remain
at the caller-provided paths and must remain protected and available. On failure,
intent, snapshots, and any temporary files are retained; exceptions report
conflicts. Nothing automatically removes unknown content.

There is no cross-file transaction, external fencing, progress journal, resume,
or automatic recovery. A process interruption can leave some files applied and
temporary files or incomplete `.writing` state files. Even after `Flush(true)`
and rename, power-loss durability of directory entries and replace operations is
not proven; neither the intent nor targets are guaranteed to be in only an old
or new state after power loss. A future Host must independently validate and
interpret the persisted intent and snapshots, maintain its own recovery journal,
and decide how to handle conflicts and retained artifacts.

The opt-in cross-repository tests can set `GENERALUPDATE_BOWL_SUPERVISOR` to a
separately built `Bowl.TestPeer.exe`. Its **test-only** supervisor starts the
`MonitoringTestHost` fixture in a Windows Job and exchanges READY/GO/DONE over
a PID-checked pipe. Only after GO does the fixture download a loopback ZIP,
prepare the write set and apply it. Failure cases exercise Bowl's test recovery;
another test kills the supervisor and checks worker termination and rejection of
attempt reuse. This is not the production Bowl.Host entrypoint, service
authentication, an authorization protocol, or proof of safe crash restart.
An additional test enables the supervisor's test-only durable delivery and
verifies a 503 leaves a pending outbox, then a separate retry process sends the
same event and receives a business acknowledgment. No credential is stored in
the outbox. This exercises the test supervisor, not production reporting.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>
</Project>
4 changes: 4 additions & 0 deletions src/GeneralUpdate.ControlledWorker/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// This entrypoint deliberately accepts no authorization until the production
// Host protocol and its process/lease binding have been implemented.
Console.Error.WriteLine("Controlled worker unavailable: production Host authorization is not implemented.");
return 2;
Loading