heartbeat: Tick never verifies the live DNS record, so external mis-point never self-heals (heartbeat-repoint, signature 8ff2bd61a4d7) #642

Closed
opened 2026-08-21 23:41:33 +00:00 by matou-build-agent · 2 comments

Failure: the heartbeat-repoint rehearsal leg mis-points rehearsal-b.idss.nz to 203.0.113.250 via the broker (claim secret, ADR 0135) while leaving the droplet's real address (209.38.95.103) unchanged, then polls dig for up to 900s waiting for the live address heartbeat (ADR 0136) to correct it. It never does — dig still answers 203.0.113.250 at the deadline. See app/tests/e2e/journey.selfhosted.spec.ts:517-556 (leg body) and the leg-13 comment at 417-421 ("the exact state an ISP rotation leaves"). Run evidence: test-results/drive-selfhosted/20260821T231633Z/artifacts/legs.json — heartbeat-repoint red after 917554ms with dig last answered: \"203.0.113.250\".

Root cause: Heartbeat.Tick (internal/heartbeat/heartbeat.go:180-205) only compares the gateway's self-observed public IP (read via internal/dns reflection, behind NAT) against h.lastIP, the last address the heartbeat itself successfully wrote:

if ip == lastIP && !owed {
    h.confirmCurrent(ip)   // silent no-op — never calls the broker
    return
}

It never reads back what the DNS record currently answers. In this scenario the gateway's own address hasn't changed (ip == lastIP), so every tick — at the wired 5-minute interval (control-plane/cmd/control-plane/main.go:84, addressHeartbeatInterval) — takes the silent no-op branch, and the broker is never called again. The mis-pointed record stands indefinitely.

internal/heartbeat/heartbeat_test.go confirms this is the implemented design, not a regression: its cases (TestTick_UnchangedAddressIsSilentNoOp, TestTick_ChangedAddressRepoints, TestTick_RepointFailureRaisesStandingFaultThatHolds, TestTick_DiscoveryFailureIsNotSilentlyHealthy, TestTick_DiscoveryGapDoesNotMaskAKnownStaleRecord) never exercise "the live record drifted while the gateway's own observed address stayed the same." ADR 0136 (docs/adr/0136-*.md) matches the code: it explicitly scopes the heartbeat to react to a self-observed address change ("observes the gateway's public address and, when it changes, re-points"), not to verify or reconcile the live record.

The rehearsal drive's heartbeat-repoint leg is holding the heartbeat to a stronger bar (self-healing externally-drifted DNS, e.g. a mis-point from another actor or a broker-side mistake) than ADR 0136 currently scopes it to.

Suspected layer: internal/heartbeat (Tick's change-detection branch), and its production wiring in control-plane/cmd/control-plane/main.go:475-522 (productionAddressHeartbeat) if closing the gap needs a DNS-read dependency.

What plugging it needs: a design ruling on the correction strategy, since either option changes the loop's broker-call cost profile and the accepted ADR 0136 scope:

  • Tick reads back the live <slug> record each pass and repoints whenever it diverges from lastIP, even when the self-observed gateway IP is unchanged, or
  • the loop unconditionally re-asserts the full record family on some cadence regardless of observed change.

This likely needs an ADR 0136 amendment (or a new ADR) before implementation, not just a patch — flagging confident: false.

drive 20260821T231633Z red at heartbeat-repoint: rehearsal-b.idss.nz never re-pointed to the droplet (209.38.95.103) within 900s — the gateway heartbeat did not correct the mis-point to 203.0.113.250; dig last answered: "203.0.113.250"
evidence: test-results/…/20260821T231633Z/ on matou-workstation (legs.json, droplet-journal.txt, trace) — a representative screenshot is attached here if one was captured (#596)

**Failure:** the `heartbeat-repoint` rehearsal leg mis-points `rehearsal-b.idss.nz` to `203.0.113.250` via the broker (claim secret, ADR 0135) while leaving the droplet's real address (`209.38.95.103`) unchanged, then polls `dig` for up to 900s waiting for the live address heartbeat (ADR 0136) to correct it. It never does — `dig` still answers `203.0.113.250` at the deadline. See `app/tests/e2e/journey.selfhosted.spec.ts:517-556` (leg body) and the leg-13 comment at 417-421 ("the exact state an ISP rotation leaves"). Run evidence: `test-results/drive-selfhosted/20260821T231633Z/artifacts/legs.json` — `heartbeat-repoint` red after 917554ms with `dig last answered: \"203.0.113.250\"`. **Root cause:** `Heartbeat.Tick` (`internal/heartbeat/heartbeat.go:180-205`) only compares the gateway's *self-observed* public IP (read via `internal/dns` reflection, behind NAT) against `h.lastIP`, the last address the heartbeat itself successfully wrote: ```go if ip == lastIP && !owed { h.confirmCurrent(ip) // silent no-op — never calls the broker return } ``` It never reads back what the DNS record currently answers. In this scenario the gateway's own address hasn't changed (`ip == lastIP`), so every tick — at the wired 5-minute interval (`control-plane/cmd/control-plane/main.go:84`, `addressHeartbeatInterval`) — takes the silent no-op branch, and the broker is never called again. The mis-pointed record stands indefinitely. `internal/heartbeat/heartbeat_test.go` confirms this is the implemented design, not a regression: its cases (`TestTick_UnchangedAddressIsSilentNoOp`, `TestTick_ChangedAddressRepoints`, `TestTick_RepointFailureRaisesStandingFaultThatHolds`, `TestTick_DiscoveryFailureIsNotSilentlyHealthy`, `TestTick_DiscoveryGapDoesNotMaskAKnownStaleRecord`) never exercise "the live record drifted while the gateway's own observed address stayed the same." ADR 0136 (`docs/adr/0136-*.md`) matches the code: it explicitly scopes the heartbeat to react to a *self-observed* address change ("observes the gateway's public address and, when it changes, re-points"), not to verify or reconcile the live record. The rehearsal drive's `heartbeat-repoint` leg is holding the heartbeat to a stronger bar (self-healing externally-drifted DNS, e.g. a mis-point from another actor or a broker-side mistake) than ADR 0136 currently scopes it to. **Suspected layer:** `internal/heartbeat` (Tick's change-detection branch), and its production wiring in `control-plane/cmd/control-plane/main.go:475-522` (`productionAddressHeartbeat`) if closing the gap needs a DNS-read dependency. **What plugging it needs:** a design ruling on the correction strategy, since either option changes the loop's broker-call cost profile and the accepted ADR 0136 scope: - Tick reads back the live `<slug>` record each pass and repoints whenever it diverges from `lastIP`, even when the self-observed gateway IP is unchanged, or - the loop unconditionally re-asserts the full record family on some cadence regardless of observed change. This likely needs an ADR 0136 amendment (or a new ADR) before implementation, not just a patch — flagging `confident: false`. drive `20260821T231633Z` red at `heartbeat-repoint`: `rehearsal-b.idss.nz never re-pointed to the droplet (209.38.95.103) within 900s — the gateway heartbeat did not correct the mis-point to 203.0.113.250; dig last answered: "203.0.113.250"` evidence: `test-results/…/20260821T231633Z/` on matou-workstation (legs.json, droplet-journal.txt, trace) — a representative screenshot is attached here if one was captured (#596) <!-- rehearsal-sig: 8ff2bd61a4d7 -->
Owner

Design ruling — Ben, 2026-08-21: option (a), the heartbeat RECONCILES the live record

The self-hosted drive now runs 12/13 legs green (20260821T231633Z); this is the only remaining blocker, and it is a design gap in ADR 0136's scope, not a regression. Ben ruled: the heartbeat's job is to keep the live <slug> record answering the gateway's true address — not merely to react when the gateway's own address changes. External drift (the record mis-pointed by a broker error, another actor, or a registrar/cache glitch, while the gateway's own IP is unchanged) must self-heal.

This is needs-design no longer — it is implementable against the amendment below. A swarm session may take it.

Land this ADR 0136 amendment VERBATIM (same commit as the code)

Append to docs/adr/0136-the-address-heartbeat-is-idss-only-and-rewrites-glue.md:

## Amendment — the heartbeat reconciles the live record, not only self-observed change (Ben, 2026-08-21; #642)

The Decision above scopes the loop to react **when the gateway's own public
address changes**. The `heartbeat-repoint` rehearsal leg exposed the gap this
leaves: when `<slug>` is mis-pointed by anything OTHER than the gateway's address
moving — a broker-side error, another actor, a registrar/cache glitch — the
gateway's self-observed IP is unchanged, so every Tick takes the silent no-op
branch and the wrong record stands indefinitely. External drift never self-heals.

Ben ruled: each Tick now READS BACK what `<slug>` currently answers and re-points
the full record family whenever it diverges from the gateway's observed address —
even when that observed address is unchanged since the last write. Reconciliation,
not just change-detection.

Bounds preserved:
- Steady state stays cheap: one record read per tick at the existing ~5-min
  cadence; a broker WRITE happens only on an actual divergence — a correct record
  costs one read and zero writes.
- Fault posture unchanged (ADR 0071/0100): success silent; an unwritable OR
  unverifiable record raises the standing named state and holds loud until the
  record answers the true address again.
- A failed live-record READ must never be read as "record is current" (the
  "absence read as healthy" the fleet forbids): a read gap raises the
  discovery-gap warning exactly as a self-IP discovery gap does, and never clears
  a known-stale record.
- The reconcile signal is the `<slug>` A record; on divergence the loop re-points
  the SAME full address-bearing family it already owns (community A + acme-dns
  NS/glue), unchanged.

Acceptance criteria

  1. Heartbeat.Tick (internal/heartbeat/heartbeat.go:180-205) reads the live <slug> answer each pass through a new injected resolver (wired like disc/repoint so the seam tests script it), and re-points when liveRecord != observedIP even if observedIP == lastIP. The current if ip == lastIP && !owed { confirmCurrent(); return } short-circuit must no longer skip a divergent live record.
  2. New seam test — the case internal/heartbeat/heartbeat_test.go never had: live record drifted while the gateway's own observed address stayed the same → Tick re-points. (The reporter named this exact missing case.)
  3. All existing tests still hold unchanged in intent: TestTick_UnchangedAddressIsSilentNoOp (now: unchanged AND live record already correct → silent no-op, zero Repoint calls — assert it), TestTick_ChangedAddressRepoints, TestTick_RepointFailureRaisesStandingFaultThatHolds, TestTick_DiscoveryFailureIsNotSilentlyHealthy, TestTick_DiscoveryGapDoesNotMaskAKnownStaleRecord.
  4. Live-record READ failure raises the discovery-gap warning and does NOT take the silent no-op branch nor clear a known-stale record (new test).
  5. Reading mechanism — read the record the way the drive verifies it (the served/authoritative <slug> answer, matching journey.selfhosted.spec.ts:517-556's dig). Mind DNS TTL: read authoritatively enough that a stale cache neither masks a real divergence nor triggers a phantom re-point. If brokerclient already exposes a records read-back, prefer it (authoritative, cache-free) over a recursive DNS lookup; if not, an authoritative-NS query. Do NOT add a new inbound door.
  6. Production wiring: productionAddressHeartbeat (control-plane/cmd/control-plane/main.go:475-522) gains the resolver dependency.
  7. Update STATUS.md in the same commit (ADR 0136 amended, heartbeat-repoint leg now covered); add a docs/GOTCHAS.md entry only if a real hazard surfaces during implementation.

Confidence

The mechanism is fully understood (drive 20260821T231633Z: dig answered the mis-pointed 203.0.113.250 at the 900s deadline; Tick's no-op branch never called the broker because observedIP == lastIP). No live droplet needed to implement — the seam tests drive Tick directly. Once green, close #640 (value-vs-timing) as moot — activation is proven clear by 12/13.

## Design ruling — Ben, 2026-08-21: option (a), the heartbeat RECONCILES the live record The self-hosted drive now runs **12/13 legs green** (`20260821T231633Z`); this is the only remaining blocker, and it is a design gap in ADR 0136's scope, not a regression. Ben ruled: **the heartbeat's job is to keep the live `<slug>` record answering the gateway's true address — not merely to react when the gateway's own address changes.** External drift (the record mis-pointed by a broker error, another actor, or a registrar/cache glitch, while the gateway's own IP is unchanged) must self-heal. This is `needs-design` no longer — it is implementable against the amendment below. A swarm session may take it. ### Land this ADR 0136 amendment VERBATIM (same commit as the code) Append to `docs/adr/0136-the-address-heartbeat-is-idss-only-and-rewrites-glue.md`: ```markdown ## Amendment — the heartbeat reconciles the live record, not only self-observed change (Ben, 2026-08-21; #642) The Decision above scopes the loop to react **when the gateway's own public address changes**. The `heartbeat-repoint` rehearsal leg exposed the gap this leaves: when `<slug>` is mis-pointed by anything OTHER than the gateway's address moving — a broker-side error, another actor, a registrar/cache glitch — the gateway's self-observed IP is unchanged, so every Tick takes the silent no-op branch and the wrong record stands indefinitely. External drift never self-heals. Ben ruled: each Tick now READS BACK what `<slug>` currently answers and re-points the full record family whenever it diverges from the gateway's observed address — even when that observed address is unchanged since the last write. Reconciliation, not just change-detection. Bounds preserved: - Steady state stays cheap: one record read per tick at the existing ~5-min cadence; a broker WRITE happens only on an actual divergence — a correct record costs one read and zero writes. - Fault posture unchanged (ADR 0071/0100): success silent; an unwritable OR unverifiable record raises the standing named state and holds loud until the record answers the true address again. - A failed live-record READ must never be read as "record is current" (the "absence read as healthy" the fleet forbids): a read gap raises the discovery-gap warning exactly as a self-IP discovery gap does, and never clears a known-stale record. - The reconcile signal is the `<slug>` A record; on divergence the loop re-points the SAME full address-bearing family it already owns (community A + acme-dns NS/glue), unchanged. ``` ### Acceptance criteria 1. `Heartbeat.Tick` (`internal/heartbeat/heartbeat.go:180-205`) reads the live `<slug>` answer each pass through a new **injected resolver** (wired like `disc`/`repoint` so the seam tests script it), and re-points when `liveRecord != observedIP` **even if `observedIP == lastIP`**. The current `if ip == lastIP && !owed { confirmCurrent(); return }` short-circuit must no longer skip a divergent live record. 2. **New seam test** — the case `internal/heartbeat/heartbeat_test.go` never had: *live record drifted while the gateway's own observed address stayed the same* → Tick re-points. (The reporter named this exact missing case.) 3. All existing tests still hold unchanged in intent: `TestTick_UnchangedAddressIsSilentNoOp` (now: unchanged AND live record already correct → silent no-op, **zero** Repoint calls — assert it), `TestTick_ChangedAddressRepoints`, `TestTick_RepointFailureRaisesStandingFaultThatHolds`, `TestTick_DiscoveryFailureIsNotSilentlyHealthy`, `TestTick_DiscoveryGapDoesNotMaskAKnownStaleRecord`. 4. **Live-record READ failure** raises the discovery-gap warning and does NOT take the silent no-op branch nor clear a known-stale record (new test). 5. **Reading mechanism** — read the record the way the drive verifies it (the served/authoritative `<slug>` answer, matching `journey.selfhosted.spec.ts:517-556`'s `dig`). Mind DNS TTL: read authoritatively enough that a stale cache neither masks a real divergence nor triggers a phantom re-point. If `brokerclient` already exposes a records read-back, prefer it (authoritative, cache-free) over a recursive DNS lookup; if not, an authoritative-NS query. Do NOT add a new inbound door. 6. Production wiring: `productionAddressHeartbeat` (`control-plane/cmd/control-plane/main.go:475-522`) gains the resolver dependency. 7. Update `STATUS.md` in the same commit (ADR 0136 amended, heartbeat-repoint leg now covered); add a `docs/GOTCHAS.md` entry only if a real hazard surfaces during implementation. ### Confidence The mechanism is fully understood (drive `20260821T231633Z`: `dig` answered the mis-pointed `203.0.113.250` at the 900s deadline; Tick's no-op branch never called the broker because `observedIP == lastIP`). No live droplet needed to implement — the seam tests drive `Tick` directly. Once green, close **#640** (value-vs-timing) as moot — activation is proven clear by 12/13.
Author
Member

Ruled by agent under ADR 0174 — veto anytime

Ben's design ruling (comment above, 2026-08-21) already settled the one-way-door part of this ticket — the ADR 0136 amendment and the correction-strategy choice (option a, reconciliation). What remained (wiring the injected resolver, updating Tick, TDD) is a two-way door: revertible by commit, provable by the seam tests below. No further human ruling needed; this comment is the audit trail for the implementation session.

Close-report

Landed (a883e249bc312d5e642149424a34a9747bfb434e, pushed to origin/main):

  • ADR 0136 amendment landed verbatim (Ben's text) in docs/adr/0136-the-address-heartbeat-is-idss-only-and-rewrites-glue.md.
  • internal/dns.AuthoritativeReader (new, TDD red-first — internal/dns/authoritative_test.go written and confirmed failing to compile before authoritative.go existed): looks up the zone's authoritative nameserver via the system resolver, then dials it directly for the live A record — bypassing any caching recursive resolver. Injectable lookupNS/dialAndLookup seams, scripted contract tests (5 cases), no fake in the real constructor (NewAuthoritativeReader).
  • internal/heartbeat: new LiveRecordReader port, third required constructor arg on New. Tick now reads the live record every pass; the silent no-op branch requires observed-IP-unchanged and no owed write and live-record-already-correct — a live-record divergence now re-points even with the gateway's own address unchanged (acceptance criterion 1). A live-record read failure raises the same StateDiscoveryFailed warning a self-IP read failure does and never masks a StateRepointFailed known-stale record (criteria 4). All 5 pre-existing seam tests updated (confirmed still passing with intent unchanged) + 3 new: TestTick_LiveRecordDriftedWhileAddressUnchangedRepoints (the exact missing case, criterion 2), TestTick_LiveRecordReadFailureRaisesDiscoveryGapAndDoesNotRepoint, TestTick_LiveRecordReadFailureDoesNotMaskAKnownStaleRecord (criterion 4).
  • control-plane/cmd/control-plane/main.go: productionAddressHeartbeat wires dns.NewAuthoritativeReader(brokerclient.IssuanceApex) reading the community apex, satisfying criterion 6. brokerclient has no records read-back today, so per criterion 5's fallback this is the authoritative-NS query, not a recursive lookup.
  • STATUS.md updated in the same commit (header + this session's summary); no new docs/GOTCHAS.md entry — no hazard surfaced, just the scoped design gap the amendment already documents.

Proof: go build ./..., go vet ./..., gofmt -l (clean), go test ./... — all green, including the full internal/heartbeat and internal/dns suites.

Not done in this session (structural, not a gap in the fix): this session cannot itself fire the standing self-hosted rehearsal (host_capacity_acquire_exclusive, #577/ADR 0184 holds the same lock this session holds), so the heartbeat-repoint leg's live re-run is the next cron-triggered rehearsal, not this session — closing on the strength of the seam tests directly exercising the exact gap the leg found, per the #635/#636/#641 precedent (see STATUS.md).

Note for whoever next looks at #640 (ready-for-human, value-vs-timing): Ben's ruling comment above said to close it as moot once this lands, since 12/13 legs green already proves activation clear. Left untouched per this session's single-ticket scope (ADR 0174 rule 1) — routing, not doing.

## Ruled by agent under ADR 0174 — veto anytime Ben's design ruling (comment above, 2026-08-21) already settled the one-way-door part of this ticket — the ADR 0136 amendment and the correction-strategy choice (option a, reconciliation). What remained (wiring the injected resolver, updating Tick, TDD) is a two-way door: revertible by commit, provable by the seam tests below. No further human ruling needed; this comment is the audit trail for the implementation session. ## Close-report **Landed** (`a883e249bc312d5e642149424a34a9747bfb434e`, pushed to `origin/main`): - **ADR 0136 amendment landed verbatim** (Ben's text) in `docs/adr/0136-the-address-heartbeat-is-idss-only-and-rewrites-glue.md`. - **`internal/dns.AuthoritativeReader`** (new, TDD red-first — `internal/dns/authoritative_test.go` written and confirmed failing to compile before `authoritative.go` existed): looks up the zone's authoritative nameserver via the system resolver, then dials it directly for the live A record — bypassing any caching recursive resolver. Injectable `lookupNS`/`dialAndLookup` seams, scripted contract tests (5 cases), no fake in the real constructor (`NewAuthoritativeReader`). - **`internal/heartbeat`**: new `LiveRecordReader` port, third required constructor arg on `New`. `Tick` now reads the live record every pass; the silent no-op branch requires observed-IP-unchanged **and** no owed write **and** live-record-already-correct — a live-record divergence now re-points even with the gateway's own address unchanged (acceptance criterion 1). A live-record read failure raises the same `StateDiscoveryFailed` warning a self-IP read failure does and never masks a `StateRepointFailed` known-stale record (criteria 4). All 5 pre-existing seam tests updated (confirmed still passing with intent unchanged) + 3 new: `TestTick_LiveRecordDriftedWhileAddressUnchangedRepoints` (the exact missing case, criterion 2), `TestTick_LiveRecordReadFailureRaisesDiscoveryGapAndDoesNotRepoint`, `TestTick_LiveRecordReadFailureDoesNotMaskAKnownStaleRecord` (criterion 4). - **`control-plane/cmd/control-plane/main.go`**: `productionAddressHeartbeat` wires `dns.NewAuthoritativeReader(brokerclient.IssuanceApex)` reading the community apex, satisfying criterion 6. brokerclient has no records read-back today, so per criterion 5's fallback this is the authoritative-NS query, not a recursive lookup. - **STATUS.md** updated in the same commit (header + this session's summary); no new `docs/GOTCHAS.md` entry — no hazard surfaced, just the scoped design gap the amendment already documents. **Proof:** `go build ./...`, `go vet ./...`, `gofmt -l` (clean), `go test ./...` — all green, including the full `internal/heartbeat` and `internal/dns` suites. **Not done in this session (structural, not a gap in the fix):** this session cannot itself fire the standing self-hosted rehearsal (`host_capacity_acquire_exclusive`, #577/ADR 0184 holds the same lock this session holds), so the `heartbeat-repoint` leg's live re-run is the next cron-triggered rehearsal, not this session — closing on the strength of the seam tests directly exercising the exact gap the leg found, per the #635/#636/#641 precedent (see STATUS.md). **Note for whoever next looks at #640** (`ready-for-human`, value-vs-timing): Ben's ruling comment above said to close it as moot once this lands, since 12/13 legs green already proves activation clear. Left untouched per this session's single-ticket scope (ADR 0174 rule 1) — routing, not doing.
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
Matou/idss#642
No description provided.