Skip to content

feat(serving): give patches readable company addresses - #211

Merged
allisonmahmood merged 2 commits into
mainfrom
sdk/195-addresses
Sep 12, 2026
Merged

allisonmahmood merged 2 commits into
mainfrom
sdk/195-addresses

Conversation

@allisonmahmood

Copy link
Copy Markdown
Owner

Patches still used opaque /d/<id> links. Every patch now has a company-scoped name and a readable address, without changing who can open it or how tier-0 pages render.

Publishing assigns names atomically, preserves them on file updates, and supports explicit renames with --name. Old names redirect until reclaimed; deletion frees them. Address, version and internal content routes preserve the existing door and cache rules, and /d/* now returns 404. The wire contract, seed backfill, CLI, docs and public skill are updated together.

Stacked on #210 (sdk/194-publish, issue #194). This PR builds on its existing publish flow and must land after it.

Closes #195.

Verification

  • 361 tests across 38 files; typecheck, lint, build and formatting passed.
  • Packed CLI end-to-end flow and isolated real-server/browser checks passed.
  • Standards and spec reviews completed. The opposing-rename deadlock was reproduced on PostgreSQL, fixed and covered by a regression test.

Implemented with GPT-6 Astra in the Oh My Pi harness.

@github-actions github-actions Bot added area:server Touches the server area area:ci CI, shared testing infrastructure, development scripts and tooling area:cli Touches the cli area area:docs Touches the docs area size:l 501-1,000 changed lines labels Sep 10, 2026
@allisonmahmood

Copy link
Copy Markdown
Owner Author

Astra review

Reviewed git diff origin/sdk/194-publish...HEAD: base 2282a57, PR head ce744ba, against issue #195 and its referenced address decisions. One pass, no subagents; merge-blocking findings only.

Standards

No merge-blocking method or YAGNI findings. Name allocation uses the unique index inside the publish transaction; the existing Patches, Content and Door boundaries are retained. The content URL, tier-specific CSP and route handoff are explicitly requested by #195, not unrequested future machinery.

Spec

No merge-blocking intent findings. The change covers company-scoped names, explicit-name refusals, filename-derived collision suffixes, name preservation on updates, rename redirects and reclamation, deletion freeing names, address/version/content routes, and the CLI/wire/documentation cutover. Higher-tier publishing remains refused.

Verification:

  • Focused Vitest run of Patches.test.ts, PatchesApi.test.ts, Pages.test.ts, Server.test.ts and cli.test.ts: 106 tests passed across 5 files.
  • Additional isolated Postgres/serving probe passed filename derivation and suffixing; 308 redirects preserving version, route and query; tier-0 trailing routes and reserved-segment rejection; name reclamation followed by deletion without resurrecting the previous redirect; /d/* removal; authenticated historical content with private caching; and two users racing for one explicit name with exactly one winner.
  • No repository files changed. No live Clerk, production or daily-driver instance used.

Summary: Standards: 0 blockers, worst issue: none. Spec: 0 blockers, worst issue: none.

@allisonmahmood

Copy link
Copy Markdown
Owner Author

Review of #211 against #195 (sdk/194-publish...ce744ba). Stacked on #210.

Standards

Documented

  • CONTEXT-MAP.md Patches line. CLAUDE.md / docs/agents/domain.md: vocabulary and product shape follow through to the map. The map still says “human-readable addresses … remain future work” after this PR ships names, patch_names, and /<company>/<patch>. Glossaries and docs/product.md were updated; the map was not.
  • Patches.backfillNames is TypeScript, not a Migrator step. ADR-0003: “Schema changes and any required data backfill are Postgres steps.” The rewrite of 0003_patches_baseline itself is what feat(serving): names and addresses at /<company>/<patch>, the content URL, /d/* removed #195 asked for, and ADR-0003 still endorses pre-deploy baseline rewrites (pnpm dev reset). The leftover tension is the seed backfill living in Effect (supervisor, test/postgres.ts, packed-cli e2e) rather than SQL next to the table.
  • packages/cli/src/commands.ts (~454). decodePublishName maps a SchemaError to LocalError and drops cause. Effect service conventions: when wrapping a real failure, keep the underlying error as cause (this file already does that for decodeSharingScope).

Smells (judgement)

  • Speculative Generality — render.ts route?: string, Pages.ts ~142–144. Passed only when tier >= 1; the wrapper never reads it; publish still refuses tier ≥ 1. Ticket 12’s door is the address splat and the content URL, not a dead field.
  • Duplicated Code — Patches.ts. backfillNames (~493–503) repeats claimName’s INSERT … ON CONFLICT … WHERE NOT current plus the deriveName ordinal loop from record (~779–785).
  • Mysterious Name — ScopeRow. Now carries scope, companyId, companyHandle, and name.
  • Repeated Switches — Pages.servePatch. Six kind === "content" branches in one handler.

Shotgun edits match “Hit every surface”; not a smell here. No UI-consistency findings. No Effect import/runtime/Schema-compile breaches.

Spec

(a) Missing or partial

Done when: “a rename redirects the old name with 308 until a new patch takes it, after which the redirect is gone for good.”
Pages.ts can 308, but no HTTP test does. PatchesApi.test.ts only checks resolveName current=false and the same patch reclaiming the name. Nothing publishes a second patch onto the old name and asserts the 308 is gone and that name now serves the new patch.

Done when: “/d/<id> is 404 for every id.”
* /d/* is registered, but Pages, Server, e2e, and browser never hit it. The old Playwright /d/000000000000 case now uses a named miss. If FindMyWay did not prefer static /d/* over GET /:company/:name/*, /d/<id> would be a two-segment address: unsigned 401 door, not 404 (d is reserved and too short to resolve).

Spec: “/<company> alone 404.” Catch-all implements it; no test.

Done when: “two patches racing for one name leave one winner.”
Uniqueness is the (company_id, name) index and ON CONFLICT, but the only race test is opposing renames (both 409). No concurrent create for one derived name.

Spec: “delete frees it.” DELETE FROM patch_names exists; no test that a later publish can take the freed name.

Spec: “name_taken 409 on create and rename alike.” Rename is in PatchesApi.test.ts; create only in packed-cli-e2e. Patches.test.ts has no name cases (derivation, -2/-3, patch fallback, backfill).

(b) Scope creep

Content URLs send Permissions-Policy: camera=(), microphone=(), geolocation=() (and ui-consistency documents it). #195 asked for “that version's bytes with that version's tier and CSP”, not this header. (It is in spec §10’s tier ≥ 1 content response.)

(c) Implemented but wrong

None beyond the untested /d/* vs address-route risk in (a).


Issue 195 intent vs what landed

#195’s admitted-at-merge line is the product: every patch has a name and an address; nothing else changes in what serves.

That is what landed. Identity stays the id. The share link is /<handle>/<name> (and /~v/<n>). /d/* is gone, not redirected. Door, 401/404 shapes, visit clock, cache keyed to sharing, and tier-0 srcdoc + sandbox="" moved onto the new routes. /~content/<patchId>/<versionId> is the internal bytes URL, same door, that version’s CSP. Publish prints address and takes --name. Seed backfill runs.

The only real intent gap is proof, not shape: the done-when cases above are implemented and mostly untested on the HTTP path. route “carried to the shell for tier ≥ 1” is a typed no-op, which matches “nothing else changes in what serves” and leaves ticket 12 a dead parameter.

A user or agent gets the experience 195 promised: open /<handle>/<name>, same page.

Method

The method is the right small one.

Uniqueness lives only on patch_names(company_id, name). Claim is one statement:

INSERT INTO patch_names (company_id, name, patch_id, current)
VALUES (...)
ON CONFLICT (company_id, name) DO UPDATE
SET patch_id = EXCLUDED.patch_id, current = true
WHERE NOT patch_names.current
RETURNING name

No pre-check. Empty RETURNING is a live occupant (NameTaken for explicit names, -2/-3 for derived). Redirects are stolen; live names are not. patches.name is denormalized for reads because the ticket asked for both; it is not the uniqueness source (a unique on patches.name would collide file-mode creates before claim).

Rename claims the new name before retiring the old. That is the opposing-rename deadlock fix, and the test actually holds both puts then races record(). Both 409, addresses unchanged. Retire-then-claim would deadlock or swap.

Routing is one GET /:company/:name/* plus addressRouteOf. Find-my-way * matches an empty remainder, so /acme/hello works. /acme is one segment → catch-all 404. versionNumber: null is the reserved-~ 404; that three-state is clever rather than obvious.

backfillNames in the service is defensible: Unicode suffix logic does not belong in SQL, and seed/vitest share one path.

No correctness bug in the claim/rename protocol. This is the smallest model that makes “the index is truth, claim is atomic, rename cannot swap” unsurprising.

YAGNI

Keep. claimName, claim-before-retire, deriveName, one PatchName schema on the wire/row/--name, door/cache/visit moved rather than reimplemented, delete frees names.

Cut or simplify.

  1. Drop route? on renderPatchWrapper. Parse ~v, refuse other ~, stop building a route the shell ignores.
  2. Dual address and publicUrl on the publish body. feat(serving): names and addresses at /<company>/<patch>, the content URL, /d/* removed #195 added name and address. Share still saying publicUrl is the leftover, not a reason to duplicate it on publish. The API doc even has to explain they are equal.
  3. contentSecurityPolicy(tier) plus a test that UPDATEs a row to tier 1. Today no published version is tier ≥ 1. Ticket 12 can add the switch when a tier 1 version can exist. (Permissions-Policy on the content URL is the same family.)
  4. Don’t triple the CLI 409 fixture for name_taken; it is one more definitive 409.

A partial unique index on (patch_id) WHERE current would make “one current name” a fact. Not required by the ticket.

Tests to add, not smoke: HTTP 308 + reclaim-by-second-patch, /d/<id> 404 (signed out), concurrent create of one derived name, delete then reuse. Those are the merge invariants. The poked tier-1 CSP is not.


Standards: 7 findings (3 documented, 4 smells). Worst: CONTEXT-MAP.md still calling addresses future work.

Spec: 7 findings (6 missing/partial coverage of done-when, 1 scope-creep). Worst: /d/<id> is 404 for every id is untested and would be a 401 door if the static /d/* route lost to /:company/:name/*.

@allisonmahmood

Copy link
Copy Markdown
Owner Author

Addressed the reviews in 5f8d093. Read both discussion comments, the Reviews tab, and inline review comments; the latter two were empty. No new review findings appeared after the push.

Fixed

  • Stale context map: Patches now lists company-scoped names; Serving lists addresses and version/content URLs. Addresses are no longer described as future work.
  • Dropped CLI cause: invalid --name wraps the SchemaError in LocalError with its original cause, matching sharing-scope validation. The CLI error/exit contract is unchanged.
  • Misleading ScopeRow: renamed the private projection to PatchTargetRow; it carries the locked target's company, name and scope, not just its sharing scope.
  • ADR-0003 tension: clarified that feat(serving): names and addresses at /<company>/<patch>, the content URL, /d/* removed #195's pre-deployment name repair is a shared Postgres seed operation after the rewritten baseline, not a replacement for deployed-schema migrations and their required data backfills.
  • Missing durable acceptance coverage: added real-socket HTTP tests for admitted 308s preserving version/route/query, private and historical alias admission, second-patch reclamation, and deletion without resurrecting the previous alias. Added signed-out GET/HEAD checks for removed /d/* paths and bare company handles, plus static-route precedence. Added real-Postgres API races between different users in the same company: one exact-name winner/one 409 name_taken, two derived-name winners receiving base/-2, then -3; deletion followed by explicit-name reuse; normalization, truncation and fallback; and creation-ordered, idempotent title backfill preserving existing names and excluding deleted patches. The races cannot be serialized by a shared owner-quota lock.

Kept, with reasons

  • Route handoff: feat(serving): names and addresses at /<company>/<patch>, the content URL, /d/* removed #195 explicitly requires carrying the route toward the tier ≥ 1 shell while tier 0 ignores it. Removing the field would remove that requested seam; this PR does not implement ticket 12's shell.
  • Both address and publicUrl: SDK: primitives, integrations, init and the dev loop on tier 1 #193 §8 explicitly includes both in the publish response. Removing one would contradict the wire contract, not simplify an unspecified detail.
  • Per-version CSP, its historical-tier test, and Permissions-Policy: feat(serving): names and addresses at /<company>/<patch>, the content URL, /d/* removed #195 requires the content URL to use the selected version's tier/CSP; SDK: primitives, integrations, init and the dev loop on tier 1 #193 §10 specifies the scripted CSP and denied camera/microphone/geolocation. The historical fixture tests selecting the stored version's policy rather than the current version's policy. This does not enable higher-tier publishing or change the tier-0 wrapper.
  • Separate seed/publish claim loops: both use the same index-backed claim rule and shared normalization. Seed repair iterates missing records; publishing handles one request, explicit-name refusal and its existing transaction. A parameterized allocator/service is not needed for these two bounded paths.
  • The shared serving handler's address/content branches: admission, visits and cache selection stay together; splitting handlers would duplicate the security-sensitive common path merely to eliminate discriminants.
  • The name_taken CLI refusal case: it proves a persisted ambiguous attempt is replayed, then cleared on this specific definitive refusal, allowing a corrected name/new key. Omitting name_taken from recovery classification would fail it; this is not just another status-code assertion.
  • No extra partial unique index on current names: an immediate one-current-name constraint would conflict with the deliberate claim-before-retire rename transaction. Changing that protocol would require redesigning the deadlock-safe rename order; the issue requires company/name uniqueness, which the existing index enforces.

Verification and merge state

  • Local affected suites: 105 tests / 4 files passed.
  • Full offline suite: 368 tests / 38 files passed.
  • Typecheck, lint and formatting passed; packed CLI against an isolated real server passed.
  • An initial overlapping offline/packed run failed two CLI launches. Both commands replace the same CLI dist; after correcting that validation ordering, the full suite passed alone. No assertions were weakened to get the pass.
  • CI run 34485922639 passed on 5f8d093: test (22), test (24), lint, cli-smoke, clerk-live, and dependency-review; PR labels also passed. These are all six contexts required by the repository's main-branch ruleset. The stack target itself has no required-check rule.
  • GitHub reports MERGEABLE / CLEAN. No unresolved review or CI blockers. Still intentionally based on sdk/194-publish: preserve the stack order behind feat(patches): make publishing replay-safe #210 before this reaches main. Not merged.

Implement #195 on the existing publish stack: atomic name claims and redirects, address and content routes, CLI --name, seed backfill, and updated contracts.
@allisonmahmood
allisonmahmood merged commit bdac928 into main Sep 12, 2026
7 of 14 checks passed
@allisonmahmood
allisonmahmood deleted the sdk/195-addresses branch September 12, 2026 11:35
allisonmahmood added a commit that referenced this pull request Sep 12, 2026
…212)

Patch-owned resources need a durable home separate from platform
records, without creating databases for companies that only publish
primitive-free patches.

Add lazy, resumable company-database provisioning with bounded
connection pools and transactional patch locks. Keep resource inventory
consistent with schema changes, reclaim orphaned namespaces and files,
and provide the same inventory services through a directory-backed
PGlite development layer. Wire migrations and configuration through the
server, dev runner and test harnesses.

Stacked on #211 (`sdk/195-addresses`); this PR intentionally targets
that branch and contains only the company-database work.

Uses `0005_company_database_baseline` because `0004_invites_expiry`
already occupies the issue's proposed migration number.

Closes #196.

## Verification
- `pnpm lint` — passed.
- `pnpm typecheck` — passed.
- `pnpm test` — 395 tests passed across 41 files.
- Postgres and PGlite coverage includes provisioning recovery, capacity
exhaustion, inventory consistency and orphan reclamation.

Implemented with GPT-6 Astra in the Oh My Pi harness.
allisonmahmood added a commit that referenced this pull request Oct 3, 2026
The /d links were replaced by readable addresses in #211. Without the
leftover route, /d/<x> still answers the HTML 404 through the address
handler (no company handle is one character). The bare-handle 404 moves
into the catch-all test.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
(cherry picked from commit d1e7cbf2c9d7cfe4ae70a415d80b064c34d1dc48)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:ci CI, shared testing infrastructure, development scripts and tooling area:cli Touches the cli area area:docs Touches the docs area area:server Touches the server area size:l 501-1,000 changed lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(serving): names and addresses at /<company>/<patch>, the content URL, /d/* removed

1 participant