Build the three things the phone's + needs, before the + exists

Steps 1 to 3 of docs/adding-hosts-on-the-phone.md: the domain half. Nothing
on either head has changed, which is deliberate — the plan orders these first
because everything the editors will bind to has to exist and be merge-safe
before a screen can offer it.

HostGroupSecret gains a parent and four defaults, and the codec gains the
version rule it never had. It stamped CurrentSchemaVersion unconditionally,
which was harmless with one field and one version and stops being harmless
here: upgrading one machine and renaming any group would have made that group
uneditable on every machine still on the old build. It now emits the lowest
version that loses nothing, so a flat group with no defaults still encodes at
version 1, byte for byte, pinned against a literal.

Tags become a real item over the reserved slot. Secret, codec, merge, cipher,
repository, both registries, the EF entity and a generated AddTagItem
migration. TagCipher names AadResourceType.Tag as a constant rather than
casting the wire type, because Tag is 5 on the wire and 8 in the crypto enum
and 5 there is Credential — a cast would seal every tag under the resource
type for a password, encrypt and decrypt perfectly on the machine that wrote
it, and only fail when another implementation refused the item, by which time
the AAD is frozen into stored ciphertext. HostTag stays reserved and unused:
the one thing the join buys over a set on the host is bought instead by
merging TagIds per id.

HostSecret grows TagIds and Port goes nullable, which is the change with the
widest blast radius and the only one that loses an item rather than locking
one. A host with no port of its own omits the property, an older build reads
int Port as 0, and TryValidate refuses it — unreadable rather than read-only.
That cost is confined to hosts which actually inherit, because the version is
a maximum over the fields present; the alternative, writing 22 into every
host, is the lie inheritance exists to stop telling.

One decision the plan did not specify. "Three states where there were two" is
four — key, credential, typed password, or the group's answer — and two
nullable ids carry three. Naming neither id now means inherit, so
AsksForPassword says "a typed password even under a group that lends a key"
out loud. Only true is ever written and a decoded false folds back to null, so
a host that never touched it encodes as it always did. Nothing already stored
changed meaning: no group could lend a binding before this build, so every
existing host resolves exactly as it did.

HostInheritance is the resolver, and its visited set is load-bearing rather
than defensive. Two clients can each re-parent A under B and B under A while
offline; the merge sees one item against one item and the server sees
ciphertext, so nothing upstream can refuse the pair. With inheritance the
chain is walked at connect time, so an unguarded cycle is not an undrawable
sidebar — it is a shell that never opens. Stopping at the first repeat
degrades it to a group that reads as a root, and clearing the parent is the
repair.

A tag set turns out to be the one field on a host that can never ask the user
anything. TagSet.ToIdMap keys by the value, so no key can hold two values, so
the both-sides-moved-differently branch of the keyed merge is unreachable —
asserted over the whole eight-row matrix. The conflict loop is kept anyway,
because that proof is one edit from ceasing to hold and what it would cause is
a discarded tag nothing records.

Three guard tests failed by design and were fixed rather than relaxed: the
ordered pull filter, the AAD pinning table, and the server's refusal of a
plaintext parent — that last one survives with its reason rewritten, because
the refusal now means "the parent is not the server's to hold" rather than
"there is no such thing as a parent". The prose that said groups are flat is
rewritten in all four places it appeared, not deleted.

The five view-model sites that read Port directly now go through the resolver,
which is a down payment on step 4 rather than the whole of it. HostFields.From
still emits the stored port, and that is the one remaining place where an
unresolved read would be a wrong wire rather than a wrong label.

Verified by the whole suite: 1382 tests over nineteen projects, none failing.
Both heads build. Nothing seen on a display, because nothing on a display has
changed yet.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
jaap-janandClaude Opus 5 committed 2026-08-03 10:21:02 +02:00
1 parent c9eca96ce7
commit 8c04ba60b0
35 files changed
+4921 -120

No files matched your search

+60 -1
View File
@@ -84,7 +84,7 @@ public static class HostSecretMerge
local.Port,
remote.Port,
conflicts,
static port => port.ToString(CultureInfo.InvariantCulture)),
static port => port?.ToString(CultureInfo.InvariantCulture) ?? "the group's port"),
Username = Text(
nameof(HostSecret.Username), ancestor.Username, local.Username, remote.Username, conflicts),
Notes = Text(nameof(HostSecret.Notes), ancestor.Notes, local.Notes, remote.Notes, conflicts),
@@ -96,6 +96,7 @@ public static class HostSecretMerge
conflicts,
FormatChain),
Options = MergeOptions(ancestor.Options, local.Options, remote.Options, conflicts),
TagIds = MergeTags(ancestor.TagIds, local.TagIds, remote.TagIds, conflicts),
RelayEnabled = Field(
nameof(HostSecret.RelayEnabled),
ancestor.RelayEnabled,
@@ -155,6 +156,14 @@ public static class HostSecretMerge
remote.GroupId,
conflicts,
static id => id?.ToString() ?? "ungrouped"),
AsksForPassword = Field(
nameof(HostSecret.AsksForPassword),
ancestor.AsksForPassword,
local.AsksForPassword,
remote.AsksForPassword,
conflicts,
static asked => asked is true ? "a typed password" : "the group's binding"),
};
private static string Text(
@@ -231,6 +240,56 @@ public static class HostSecretMerge
merge.Merged.Select(entry => new HostOption(entry.Key, entry.Value)));
}
/// <summary>
/// Merges the tag set per tag, so two people each adding a different one both keep theirs.
/// </summary>
/// <remarks>
/// <para>
/// The reason <see cref="TagSet"/> exposes a map at all. A whole-value merge here would take one side's
/// set entire and drop the other's — so a colleague tagging a host "pci" while you tagged it "eu-west"
/// would silently lose one of the two, which is the single most visible difference between a field-level
/// merge and last-writer-wins.
/// </para>
/// <para>
/// <b>No conflict is reachable, and the loop below is kept anyway.</b> The value in the map is the key,
/// so a tag can only be present or absent — and running that through
/// <see cref="ThreeWayMerge.Map"/> leaves nothing to disagree about. Where both sides hold the tag or
/// neither does they agree; where exactly one side moved, the other still matches the ancestor and the
/// move is taken. The "both sides moved differently" branch needs one key to hold two values, which this
/// map cannot express. A set is the one collection shape that merges without ever asking the user.
/// </para>
/// <para>
/// The loop stays because that proof depends on <see cref="TagSet.ToIdMap"/> keying by the value, which
/// is one edit away from ceasing to be true — and the failure it would cause is a discarded tag that
/// nothing records. Unreachable code that costs a <c>foreach</c> over an empty list is a cheaper way to
/// hold that invariant than a comment alone.
/// </para>
/// </remarks>
private static TagSet MergeTags(
TagSet ancestor,
TagSet local,
TagSet remote,
List<HostFieldConflict> conflicts)
{
var merge = ThreeWayMerge.Map(
ancestor.ToIdMap(),
local.ToIdMap(),
remote.ToIdMap(),
EqualityComparer<Guid>.Default);
foreach (var conflict in merge.Conflicts)
{
conflicts.Add(new HostFieldConflict(
$"{nameof(HostSecret.TagIds)}[{conflict.Key}]",
conflict.DiscardedSide,
conflict.Kept == Guid.Empty ? "not tagged" : "tagged",
conflict.DiscardedWasRemoval ? "not tagged" : "tagged",
conflict.DiscardedWasRemoval));
}
return TagSet.Create(merge.Merged.Keys);
}
private static string FormatChain(JumpChain chain) =>
chain.Count == 0 ? "(none)" : string.Join(" → ", chain);
}