rehearsal-4: broker rent face — Provider port (DO real, fake), rental ledger + TTL reaper, offer/rent/renew/release #647
Labels
No labels
agent-blocked
agent-working
autopilot
bug
deferred
deploy-pending
enhancement
landing-pr
model-haiku
model-opus
model-sonnet
needs-design
needs-info
needs-triage
no-triage
out-of-scope
priority
ready-for-agent
ready-for-human
ready-for-session
rehearsal-183
snapshot-pending
standing-drive
wayfinder:grilling
wayfinder:map
wayfinder:prototype
wayfinder:research
wayfinder:task
wontfix
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Blocks
Reference
Matou/idss#647
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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 3: Broker rent face — Provider port, rental ledger + reaper, four routes
Files:
broker/internal/broker/provider.go(Provider interface,FakeProvider)broker/internal/broker/provider_do.go(DigitalOcean overnet/http, no SDK)broker/internal/broker/rentals.go(ledger +Rental+ reaper)broker/internal/broker/rentals_store.go(RentalStoreiface, memory + file)broker/internal/broker/rentals_test.go,provider_do_test.go,http_rent_test.gobroker/internal/broker/http.go(four routes),broker/internal/broker/broker.go(Version = "0.2.0-alpha-rentals")broker/cmd/broker/main.go(wire provider + ledger + reaper from env)broker/README.md(or create) — env vars + OpenAPI snippetSTATUS.mdInterfaces:
Produces:
Wire:
GET /v1/gateways/offer→OfferJSON;POST /v1/gateways/rent {host, ssh_pubkey}+ Bearer claim secret →{host, ip, server_id, image, provider, region, size, expires}200 / 401 / 403 / 409 already rented / 502{error, stage:"provision"};POST /v1/gateways/renew {host}+ Bearer →{expires};POST /v1/gateways/release {host}+ Bearer → 204. Rehearsal fault hook:hostwhose slug starts withrehearsal-rentfail→ after a REALCreatethe brokerDestroys it and returns 502 stageprovisionmessagerehearsal fault: provision failed after create (server destroyed).Env:
IDSS_DO_TOKEN(file pathIDSS_DO_TOKEN_FILEpreferred),IDSS_GATEWAY_SIZE(defaults-2vcpu-4gb),IDSS_GATEWAY_REGION(defaultsyd1),IDSS_GATEWAY_TTL(default24h),IDSS_GATEWAY_IMAGE_PREFIX(defaultidss-gateway-), ledgerBROKER_STATE_DIR/rentals.json, reaper every 5 min.Consumes:
Registry.Authorize(slug, secret)(exists),issuer.slugOf(host)(exists), Task 2's snapshot naming (the DO provider resolves the image by listing snapshots with the prefix, newestcreated_at).Step 1: Write
rentals_test.go(failing) with aFakeProviderrecording calls:TestRent_BindsToHostAndPersists,TestRent_TwiceRefusesAlreadyRented,TestRent_ProviderFailureAfterCreateDestroysAndLeavesNoRecord(fake fails on a post-create hook — simulate withFakeProvider.FailAfterCreate = truethat returnsServer+ error),TestRentFailHostIsDestroyedAndErrors(rehearsal-rentfail.idss.nz),TestRenew_ExtendsExpires,TestRelease_DestroysAndIsIdempotent,TestReap_DestroysLapsedUnreleasedOnly,TestLedger_SurvivesRestart(memory store shared across twoNewRentals).Step 2: Run
cd broker && go test ./internal/broker -run 'Rent|Renew|Release|Reap|Ledger' -v→ FAIL (undefined).Step 3: Implement
provider.go,rentals_store.go,rentals.goper the Interfaces block (mutex + persist-on-every-change, mirroringRegistry;Rent:CreatewithName: "idss-gateway-"+slug+"-"+rand4hex,Tags: []string{"idss-gateway", "idss-rental"}; on any error after a non-emptyServer.IDcallDestroythen return&ProvisionError{Stage:"provision", Err: err}).Step 4: Run tests → PASS.
Step 5: Write
provider_do_test.go(failing) usinghttptest.Server:CreatePOSTs/v2/dropletswithimage(numeric id resolved from/v2/snapshots?resource_type=droplet, newest name matching prefix),ssh_keys= the fingerprint of a key it first POSTs to/v2/account/keys(or reuses when 422 duplicate), polls/v2/droplets/<id>untilstatus=="active"and a public v4 IP is present;DestroyDELETEs and treats 404 as nil;ExistsGETs.Step 6: Implement
provider_do.go(NewDigitalOcean(token string, client *http.Client, imagePrefix string)), run → PASS.Step 7: Write
http_rent_test.go(failing): offer 200 withprice==""; rent without bearer 401, wrong bearer 403, unknown host 400, happy 200 body fields, second rent 409, rentfail host 502 withstage:"provision"; renew/release 204/200 shapes.Step 8: Add the routes to
http.go;NewHandler(issuer *Issuer, rentals *Rentals, log)(update the two existing callers/tests); run → PASS.Step 9: Wire
main.go: read env,resolveProvider(no token →UnconfiguredProvider{}that fails loud: "no IDSS_DO_TOKEN — renting is refused, never a fabricated server"),OpenRentals(store),go rentals.RunReaper(ctx, 5*time.Minute). README documents env + the four routes.Step 10: Run
cd broker && go vet ./... && go test ./...→ PASS;gofmt -l .empty.Step 11: Commit —
git commit -m "rehearsal-4: broker rent face — Provider port (DO real, fake), rental ledger + TTL reaper, offer/rent/renew/release (ADR 0189) (#647)".swarm-claim host=matou-dev-server-01 run=8627
(automated multi-host claim — lowest live claim id works this ticket)
close-report for #647 — status
success✅ close-report gates passed — every claim verified against main; closing.
envelope