rehearsal-4: app side — brokerclient goes real, rent binds to the claim, release on reopen, heartbeat renews the TTL #648

Closed
opened 2026-08-22 04:12:34 +00:00 by ben · 2 comments
Owner

Arc: #183 rehearsal phase 4 — rented gateway (S4a). Spec: docs/superpowers/specs/2026-08-21-183-phase-4-rented-gateway-rehearsal-design.md. Plan: docs/superpowers/plans/2026-08-21-183-phase-4-rented-gateway-rehearsal.md (read its Global Constraints first — they apply to this task). This ticket's body is the plan's task verbatim. Phase-3 precedent: #515–#523.

Task 4: App side — real brokerclient rent face, founding types, release on reopen, heartbeat renew

Files:

  • Modify: internal/founding/access.go (GatewayOffer gains TTL, Terms string; RentRequest becomes {PubKey string} — Provider/Region/PaymentToken removed; RentResult gains SSHUser, ServerID, Expires string; BrokerClient gains RenewGateway(ctx, host, secret string) error and ReleaseGateway(ctx, host, secret string) error; Rent(ctx, req RentRequest, host, secret string)), RentServer signature stays RentServer(ctx, req RentRequest) — it reads host+secret from the draft's Address claim. Order change: rent needs the claim, so S4a must run AFTER S5's claim? No — ADR 0047/flow: S4a precedes S5. Resolution: RentServer claims <slug>.idss.nz itself when d.Address == nil using d.Details.Slug (the same ClaimSubdomain S5 would make; S5 then shows the already-claimed name as reserved). Record the claim on the draft exactly as S5 does (AddressChoice{Kind: AddressSubdomain, Host, Secret}).
  • Modify: internal/brokerclient/client.go (Offer GETs /v1/gateways/offer; Rent POSTs /v1/gateways/rent with bearer; RenewGateway, ReleaseGateway), client_test.go (retire TestClient_RentIsHonestlyUnavailableInAlpha; add TestClient_RentPostsPubKeyWithBearer, TestClient_RentProvisionErrorIsBrokerError, TestClient_OfferCarriesTermsNoPrice)
  • Modify: internal/founding/testing/fakes.go (FakeBroker.Rent scripted: RentResult or *BrokerError; record RenewGateway/ReleaseGateway calls)
  • Modify: internal/founding/standup.go ReopenAccess (when current Access is AccessRented and a host+secret exist: call broker.ReleaseGateway; record Abandoned{Released: true} in the durable community state the DDR 0142 §4 marker already uses)
  • Modify: internal/founding/access_test.go (rent happy path auto-fills IP + claims; rent failure leaves draft at S4 untouched; reopen-away releases)
  • Modify: internal/heartbeat/heartbeat.go (Option WithRenewer(Renewer); Renewer interface{ Renew(ctx) error }; Tick calls it after a successful pass — failure logs + sets Detail, never changes State), heartbeat_test.go (renew called on every healthy tick; renew error does not flip state)
  • Modify: control-plane/cmd/control-plane/main.go productionAddressHeartbeat (when IDSS_ACCESS_KIND=="rented" wire RenewerFunc(func(ctx) error { return client.RenewGateway(ctx, apex, secret) })); internal/clan gateway facts export IDSS_ACCESS_KIND (find where IDSS_CLAIM_SECRET is exported — publicGatewayFacts → the gateway env file — and add the kind beside it)
  • Modify: app/src/lib/founding.ts types (mirror Go), STATUS.md

Interfaces:

  • Consumes: Task 3's routes + bodies.

  • Produces: founding.BrokerClient with Offer/Rent/RenewGateway/ReleaseGateway/ClaimSubdomain/PointSubdomain/...; RentRequest{PubKey}; RentResult{IP, Provider, Region, Price, SSHUser, ServerID, Expires}; Draft.Access = {Kind: AccessRented, IP, Summary: "Rented gateway — <provider> · <region> · free while alpha · <ip>"} and Draft.Address already claimed after RentServer.

  • Step 1: Write the three client_test.go tests (failing) with the existing doerFunc harness: assert method/path/body {"host":..,"ssh_pubkey":..} and Authorization: Bearer s; a 502 {error, stage} → *founding.BrokerError{Stage:"provision"}; offer decode with Price=="" and Terms!="".

  • Step 2: Run go test ./internal/brokerclient -run 'Rent|Offer' -v → FAIL.

  • Step 3: Implement the client methods (reuse postJSON; add a getJSON), delete the alpha test.

  • Step 4: Run → PASS.

  • Step 5: Write the founding tests (failing): TestRentServer_ClaimsNameThenRentsAndAutoFillsIP, TestRentServer_BrokerErrorLeavesDraftUntouched, TestReopenAccess_AwayFromRentedReleases.

  • Step 6: Implement RentServer (claim-if-needed → Rent(ctx, req, host, secret) → set Access + advance), ReopenAccess release, fakes.

  • Step 7: Run go test ./internal/founding/... → PASS.

  • Step 8: Heartbeat renew — tests first (TestTick_RenewsOnHealthyPass, TestTick_RenewFailureDoesNotFlipState), implement, wire in control-plane main + the IDSS_ACCESS_KIND fact export (add a seam assertion to the existing gateway-facts test that the env file carries IDSS_ACCESS_KIND=rented on a rented draft).

  • Step 9: Run go build ./... && go vet ./... && go test ./... → PASS; gofmt -l . empty; pnpm -r typecheck PASS.

  • Step 10: Commit — git commit -m "rehearsal-4: brokerclient goes real — rent binds to the claim, pubkey in, release on reopen, heartbeat renews the TTL (#648)".

**Arc:** #183 rehearsal phase 4 — rented gateway (S4a). Spec: `docs/superpowers/specs/2026-08-21-183-phase-4-rented-gateway-rehearsal-design.md`. Plan: `docs/superpowers/plans/2026-08-21-183-phase-4-rented-gateway-rehearsal.md` (read its **Global Constraints** first — they apply to this task). This ticket's body is the plan's task verbatim. Phase-3 precedent: #515–#523. ### Task 4: App side — real `brokerclient` rent face, founding types, release on reopen, heartbeat renew **Files:** - Modify: `internal/founding/access.go` (`GatewayOffer` gains `TTL, Terms string`; `RentRequest` becomes `{PubKey string}` — Provider/Region/PaymentToken removed; `RentResult` gains `SSHUser, ServerID, Expires string`; `BrokerClient` gains `RenewGateway(ctx, host, secret string) error` and `ReleaseGateway(ctx, host, secret string) error`; `Rent(ctx, req RentRequest, host, secret string)`), `RentServer` signature stays `RentServer(ctx, req RentRequest)` — it reads host+secret from the draft's Address claim. **Order change:** rent needs the claim, so S4a must run AFTER S5's claim? No — ADR 0047/flow: S4a precedes S5. Resolution: `RentServer` claims `<slug>.idss.nz` itself when `d.Address == nil` using `d.Details.Slug` (the same `ClaimSubdomain` S5 would make; S5 then shows the already-claimed name as reserved). Record the claim on the draft exactly as S5 does (`AddressChoice{Kind: AddressSubdomain, Host, Secret}`). - Modify: `internal/brokerclient/client.go` (`Offer` GETs `/v1/gateways/offer`; `Rent` POSTs `/v1/gateways/rent` with bearer; `RenewGateway`, `ReleaseGateway`), `client_test.go` (retire `TestClient_RentIsHonestlyUnavailableInAlpha`; add `TestClient_RentPostsPubKeyWithBearer`, `TestClient_RentProvisionErrorIsBrokerError`, `TestClient_OfferCarriesTermsNoPrice`) - Modify: `internal/founding/testing/fakes.go` (`FakeBroker.Rent` scripted: `RentResult` or `*BrokerError`; record `RenewGateway`/`ReleaseGateway` calls) - Modify: `internal/founding/standup.go` `ReopenAccess` (when current Access is `AccessRented` and a host+secret exist: call `broker.ReleaseGateway`; record `Abandoned{Released: true}` in the durable community state the DDR 0142 §4 marker already uses) - Modify: `internal/founding/access_test.go` (rent happy path auto-fills IP + claims; rent failure leaves draft at S4 untouched; reopen-away releases) - Modify: `internal/heartbeat/heartbeat.go` (`Option WithRenewer(Renewer)`; `Renewer interface{ Renew(ctx) error }`; Tick calls it after a successful pass — failure logs + sets `Detail`, never changes `State`), `heartbeat_test.go` (renew called on every healthy tick; renew error does not flip state) - Modify: `control-plane/cmd/control-plane/main.go` `productionAddressHeartbeat` (when `IDSS_ACCESS_KIND=="rented"` wire `RenewerFunc(func(ctx) error { return client.RenewGateway(ctx, apex, secret) })`); `internal/clan` gateway facts export `IDSS_ACCESS_KIND` (find where `IDSS_CLAIM_SECRET` is exported — `publicGatewayFacts` → the gateway env file — and add the kind beside it) - Modify: `app/src/lib/founding.ts` types (mirror Go), `STATUS.md` **Interfaces:** - Consumes: Task 3's routes + bodies. - Produces: `founding.BrokerClient` with `Offer/Rent/RenewGateway/ReleaseGateway/ClaimSubdomain/PointSubdomain/...`; `RentRequest{PubKey}`; `RentResult{IP, Provider, Region, Price, SSHUser, ServerID, Expires}`; `Draft.Access = {Kind: AccessRented, IP, Summary: "Rented gateway — <provider> · <region> · free while alpha · <ip>"}` and `Draft.Address` already claimed after `RentServer`. - [ ] **Step 1: Write the three `client_test.go` tests** (failing) with the existing `doerFunc` harness: assert method/path/body `{"host":..,"ssh_pubkey":..}` and `Authorization: Bearer s`; a 502 `{error, stage}` → `*founding.BrokerError{Stage:"provision"}`; offer decode with `Price==""` and `Terms!=""`. - [ ] **Step 2: Run** `go test ./internal/brokerclient -run 'Rent|Offer' -v` → FAIL. - [ ] **Step 3: Implement** the client methods (reuse `postJSON`; add a `getJSON`), delete the alpha test. - [ ] **Step 4: Run** → PASS. - [ ] **Step 5: Write the founding tests** (failing): `TestRentServer_ClaimsNameThenRentsAndAutoFillsIP`, `TestRentServer_BrokerErrorLeavesDraftUntouched`, `TestReopenAccess_AwayFromRentedReleases`. - [ ] **Step 6: Implement** `RentServer` (claim-if-needed → `Rent(ctx, req, host, secret)` → set Access + advance), `ReopenAccess` release, fakes. - [ ] **Step 7: Run** `go test ./internal/founding/...` → PASS. - [ ] **Step 8: Heartbeat renew** — tests first (`TestTick_RenewsOnHealthyPass`, `TestTick_RenewFailureDoesNotFlipState`), implement, wire in control-plane main + the `IDSS_ACCESS_KIND` fact export (add a seam assertion to the existing gateway-facts test that the env file carries `IDSS_ACCESS_KIND=rented` on a rented draft). - [ ] **Step 9: Run** `go build ./... && go vet ./... && go test ./...` → PASS; `gofmt -l .` empty; `pnpm -r typecheck` PASS. - [ ] **Step 10: Commit** — `git commit -m "rehearsal-4: brokerclient goes real — rent binds to the claim, pubkey in, release on reopen, heartbeat renews the TTL (#648)"`.

swarm-claim host=elitebook-distributed-server-03 run=8634
(automated multi-host claim — lowest live claim id works this ticket)

swarm-claim host=elitebook-distributed-server-03 run=8634 (automated multi-host claim — lowest live claim id works this ticket)

close-report for #648 — status success

✅ close-report gates passed — every claim verified against main; closing.

envelope
{
  "issue": 648,
  "status": "success",
  "commits": [
    "a6b37b9c543cc0debb2cb4f4916a7d89f5c94692"
  ],
  "changed_files": [
    "STATUS.md",
    "app/src/components/founding/FoundingAccess.vue",
    "app/src/lib/founding.ts",
    "control-plane/cmd/control-plane/main.go",
    "internal/brokerclient/client.go",
    "internal/brokerclient/client_test.go",
    "internal/clan/clan.go",
    "internal/clan/vmguest.go",
    "internal/clan/vmguest_test.go",
    "internal/founding/access.go",
    "internal/founding/access_test.go",
    "internal/founding/draft.go",
    "internal/founding/ownvpspath.go",
    "internal/founding/selfhostedpath.go",
    "internal/founding/standup.go",
    "internal/founding/standup_test.go",
    "internal/founding/testing/fakes.go",
    "internal/heartbeat/heartbeat.go",
    "internal/heartbeat/heartbeat_test.go"
  ],
  "tests": [
    {
      "command": "go test ./internal/brokerclient -run 'Rent|Offer' -v",
      "exit_code": 0
    },
    {
      "command": "go test ./internal/founding/...",
      "exit_code": 0
    },
    {
      "command": "go test ./internal/heartbeat/...",
      "exit_code": 0
    },
    {
      "command": "go build ./... && go vet ./... && go test ./...",
      "exit_code": 0
    },
    {
      "command": "gofmt -l internal/ control-plane/",
      "exit_code": 0
    },
    {
      "command": "CI=true pnpm run build (vue-tsc typecheck)",
      "exit_code": 0
    },
    {
      "command": "CI=true pnpm exec vitest run tests/unit",
      "exit_code": 0
    }
  ],
  "criteria": {
    "Step 1-4: brokerclient client_test tests (RentPostsPubKeyWithBearer, RentProvisionErrorIsBrokerError, OfferCarriesTermsNoPrice) written red then green; alpha test retired": "internal/brokerclient/client_test.go + client.go (Offer GET, Rent POST {host,ssh_pubkey} + Bearer, Renew/Release, getJSON, brokerErr->*BrokerError); test cmd exit 0",
    "Step 5-7: founding tests (RentServer_ClaimsNameThenRentsAndAutoFillsIP, BrokerErrorLeavesDraftUntouched, ReopenAccess_AwayFromRentedReleases) + RentServer claim-if-needed + ReopenAccess release + fakes": "internal/founding/access.go RentServer, standup.go ReopenAccess, draft.go Abandoned/AbandonedRentals, testing/fakes.go Rent(host,secret)+Renew/Release; access_test.go + standup_test.go; go test ./internal/founding/... exit 0",
    "Step 8: heartbeat WithRenewer/Renewer, Tick renews on healthy pass, renew failure never flips state; control-plane wires renewer on IDSS_ACCESS_KIND==rented; clan GatewayFacts.AccessKind exports IDSS_ACCESS_KIND with seam assertion": "internal/heartbeat/heartbeat.go + heartbeat_test.go (TestTick_RenewsOnHealthyPass, TestTick_RenewFailureDoesNotFlipState); control-plane/cmd/control-plane/main.go; internal/clan/clan.go+vmguest.go+vmguest_test.go (TestRenderGatewayGuest_CarriesRentedAccessKind); publicGatewayFacts sets AccessKind",
    "Step 9: go build/vet/test ./... green, gofmt clean, TS typecheck PASS": "all commands exit 0 (56 Go pkgs ok, vue-tsc clean, 828 vitest pass); pre-push hook re-ran full suite green including broker module",
    "app/src/lib/founding.ts types mirror Go (GatewayOffer.ttl/terms, RentRequest={sshPubkey?}, offer price '')": "app/src/lib/founding.ts + FoundingAccess.vue rent call trimmed to {} (full DDR 0190 S4a screen is Task 5)"
  },
  "summary": "Made the app-side brokerclient real (rent binds to the claim with the app's pubkey, renew/release), released the box on reopen with a durable marker, and had the heartbeat renew the rental TTL on every healthy pass.",
  "reason": "",
  "blockers": [],
  "no_code_change": ""
}
**close-report** for #648 — status `success` :white_check_mark: **close-report gates passed** — every claim verified against main; closing. <details><summary>envelope</summary> ```json { "issue": 648, "status": "success", "commits": [ "a6b37b9c543cc0debb2cb4f4916a7d89f5c94692" ], "changed_files": [ "STATUS.md", "app/src/components/founding/FoundingAccess.vue", "app/src/lib/founding.ts", "control-plane/cmd/control-plane/main.go", "internal/brokerclient/client.go", "internal/brokerclient/client_test.go", "internal/clan/clan.go", "internal/clan/vmguest.go", "internal/clan/vmguest_test.go", "internal/founding/access.go", "internal/founding/access_test.go", "internal/founding/draft.go", "internal/founding/ownvpspath.go", "internal/founding/selfhostedpath.go", "internal/founding/standup.go", "internal/founding/standup_test.go", "internal/founding/testing/fakes.go", "internal/heartbeat/heartbeat.go", "internal/heartbeat/heartbeat_test.go" ], "tests": [ { "command": "go test ./internal/brokerclient -run 'Rent|Offer' -v", "exit_code": 0 }, { "command": "go test ./internal/founding/...", "exit_code": 0 }, { "command": "go test ./internal/heartbeat/...", "exit_code": 0 }, { "command": "go build ./... && go vet ./... && go test ./...", "exit_code": 0 }, { "command": "gofmt -l internal/ control-plane/", "exit_code": 0 }, { "command": "CI=true pnpm run build (vue-tsc typecheck)", "exit_code": 0 }, { "command": "CI=true pnpm exec vitest run tests/unit", "exit_code": 0 } ], "criteria": { "Step 1-4: brokerclient client_test tests (RentPostsPubKeyWithBearer, RentProvisionErrorIsBrokerError, OfferCarriesTermsNoPrice) written red then green; alpha test retired": "internal/brokerclient/client_test.go + client.go (Offer GET, Rent POST {host,ssh_pubkey} + Bearer, Renew/Release, getJSON, brokerErr->*BrokerError); test cmd exit 0", "Step 5-7: founding tests (RentServer_ClaimsNameThenRentsAndAutoFillsIP, BrokerErrorLeavesDraftUntouched, ReopenAccess_AwayFromRentedReleases) + RentServer claim-if-needed + ReopenAccess release + fakes": "internal/founding/access.go RentServer, standup.go ReopenAccess, draft.go Abandoned/AbandonedRentals, testing/fakes.go Rent(host,secret)+Renew/Release; access_test.go + standup_test.go; go test ./internal/founding/... exit 0", "Step 8: heartbeat WithRenewer/Renewer, Tick renews on healthy pass, renew failure never flips state; control-plane wires renewer on IDSS_ACCESS_KIND==rented; clan GatewayFacts.AccessKind exports IDSS_ACCESS_KIND with seam assertion": "internal/heartbeat/heartbeat.go + heartbeat_test.go (TestTick_RenewsOnHealthyPass, TestTick_RenewFailureDoesNotFlipState); control-plane/cmd/control-plane/main.go; internal/clan/clan.go+vmguest.go+vmguest_test.go (TestRenderGatewayGuest_CarriesRentedAccessKind); publicGatewayFacts sets AccessKind", "Step 9: go build/vet/test ./... green, gofmt clean, TS typecheck PASS": "all commands exit 0 (56 Go pkgs ok, vue-tsc clean, 828 vitest pass); pre-push hook re-ran full suite green including broker module", "app/src/lib/founding.ts types mirror Go (GatewayOffer.ttl/terms, RentRequest={sshPubkey?}, offer price '')": "app/src/lib/founding.ts + FoundingAccess.vue rent call trimmed to {} (full DDR 0190 S4a screen is Task 5)" }, "summary": "Made the app-side brokerclient real (rent binds to the claim with the app's pubkey, renew/release), released the box on reopen with a durable marker, and had the heartbeat renew the rental TTL on every healthy pass.", "reason": "", "blockers": [], "no_code_change": "" } ``` </details>
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#648
No description provided.