Skip to content

chore(patches): remove operator routes and pins - #147

Merged
allisonmahmood merged 2 commits into
mainfrom
auth/136-remove-operator-routes
Sep 6, 2026
Merged

allisonmahmood merged 2 commits into
mainfrom
auth/136-remove-operator-routes

Conversation

@allisonmahmood

Copy link
Copy Markdown
Owner

Operator-only routes and token scopes need to leave before the auth data rewrite. Removing their guards without removing token management would let any bearer revoke another token.

This removes the operator routes, scope checks, and pins together, leaving mint, me, upload, and owner-only delete. It updates analytics, tests, generated API docs, and domain documentation, and deletes the operator mint-token skill. The patches baseline is edited in place as requested; existing local instances can use pnpm dev reset.

Stacked directly on main; main is this PR's base branch.

Closes #136.

Verification

  • pnpm test — 151 tests passed across 25 files.
  • pnpm typecheck, pnpm lint, and pnpm test:packed-cli-e2e passed.
  • Real HTTP smoke: scope-free publishing works; all seven removed routes return 404; admin tokens cannot update or delete another principal's patch; owner deletion stops serving.
  • Standards and spec reviews completed; the stale-navigation finding was fixed.

Implemented with OpenAI GPT-6 Astra (openai-codex/gpt-6-astra) in the Oh My Pi harness.

Remove scoped operator APIs and pin storage before the auth data rewrite. Keep mint, me, upload, and owner-only delete; update contracts, analytics, tests, and domain documentation.

Refs #136.
@github-actions github-actions Bot added area:server Touches the server area area:docs Touches the docs area size:l 501-1,000 changed lines labels Sep 5, 2026
@allisonmahmood

Copy link
Copy Markdown
Owner Author

Astra review

No merge-blocking findings.

Reviewed ea36ec24b99057b7b112794ce6590818435f6d50 with git diff origin/main...HEAD, with origin/main pinned at 60711ecd5954124fbb222ee8cb20a390411b7c2e, against issue #136. One pass, no subagents; intent, method, and YAGNI only at merge-blocking severity.

Standards

No merge-blocking method or YAGNI findings. The change removes the capabilities at their existing wire, handler, and persistence boundaries without introducing replacement abstractions or future-facing machinery. Owner-only deletion is enforced directly in the SQL predicate. No blocking Effect-service convention violations found.

Spec

No merge-blocking intent findings. The four requested routes remain; operator token-management routes disappear alongside their scope guards. Upload/update and delete stay principal-owned, without admin reach. Pins, moderation methods/schemas, and the specified analytics fields are removed. The baseline edit, generated API documentation, glossary/operator wording, and internal skill deletion match #136. The CLI README and public skill do not document the removed routes and need no changes here.

Verification

  • Local focused run: 41 tests passed across 9 files, covering API schemas and generated docs, auth, patches, content, expiry, API guard behavior, and serving render fixtures:
    pnpm exec vitest run packages/api/src packages/auth/src/AuthApi.test.ts packages/patches/src apps/server/src/ApiGuard.test.ts packages/serving/src/render.test.ts
  • No remaining pinned_at, hasScope, or removed capability-symbol references in the searched source, scripts, skills, and documentation.
  • CI is green on the reviewed head: tests on Node 22/24, lint/typecheck, packed CLI smoke, and dependency review.

Summary: Standards: 0 blockers (worst: none). Spec: 0 blockers (worst: none).

@allisonmahmood

Copy link
Copy Markdown
Owner Author

Two-axis review of ea36ec2 vs origin/main (60711ec), against #136. Eight sub-agents: Standards, Spec, intent vs #136, implementation method, YAGNI, Effect service conventions, hit-every-surface, leftover-code beauty. Tests/lint/e2e were not re-run.

Standards

Deletion is mostly consistent: pin/unpin left together, hasScope/Forbidden gone, docs/API.md regenerated from @patchy/api, Effect file order in the changed services is fine.

Documented-standard findings

  1. Hit every surface — product shape (hard). CLAUDE.md: product-shape moves go through docs/product.md. This PR edited that file and deleted disable/read/list/pin. It still says:

    moderation, which stays what it is today — taking a patch off its address

    (docs/product.md § The operator). There is no such surface today. The added “separate dashboards” sentence does not make present tense true.

  2. Hit every surface — vocabulary (hard). Drop a concept everywhere it is mirrored. packages/patches/CONTEXT.md, CONTEXT-MAP.md, and README.md dropped moderation; apps/server/CONTEXT.md still says the patches group “publishes and moderates it.”

  3. Leftover operator method (judgement). YAGNI + leftover methods that no longer belong. Tokens.create (packages/auth/src/Tokens.ts) had one production caller: deleted POST /api/tokens. Only Tokens.test.ts still uses it. revoke is documented as remaining without a bearer route (packages/auth/CONTEXT.md); create is not. Leaving it for the data ticket is reasonable, but the asymmetry is in this change’s scope.

  4. Dead helper after deletion (judgement). malformedBody in packages/api/src/respond.ts lost its last callers when AuthApi dropped create-token and PatchesApi dropped disable. It is now an unused export.

  5. Stale test path (judgement). apps/server/src/ApiGuard.test.ts still posts /api/patches/${long}/disable as an unmatched shape. Works as a 404, but the path is leftover operator machinery.

Baseline smells (all judgement)

None beyond leftover names: identities.admin / reader in packages/patches/src/test/fixtures.ts still carry admin/read scopes. Tests now use them to prove scopes grant nothing — intentional until the data rewrite, not a rename demand.

Explicitly not findings

  • Identity.scopes, CLI whoami printing scopes, the scopes column, seed ["admin","upload"]: Auth CONTEXT calls these legacy and inert. Next data ticket.
  • disabled_at / disabled_reason: chore(patches): remove the operator's routes, the admin scope and pins #136 removed the disable route, not the column. Sweep/find/countLive still honoring the stamps is the SQL-by-hand seam The operator is Patchy, not a token #134 left in place.
  • Reverse states: pin and unpin deleted together.
  • Effect service order / catchTags / layers on touched Patches, PatchesApi, AuthApi, Analytics: no violations.

Spec

HEAD ea36ec2 vs origin/main. Tests/lint/e2e not re-run.

(a) Missing or partial

None of the listed Do items are missing.

Routes in packages/api/src/api.ts and docs/API.md are the four: POST /api/tokens/self-service, GET /api/me, POST /api/uploads, DELETE /api/patches/:patchId. Operator mint/revoke, moderated read, principal list, disable, pin, unpin, and the named wire schemas are gone. grep for pinned_at and hasScope is empty. No “Admin scope” sentence in docs/API.md. Scope-shaped Forbidden text is gone.

Pins are gone end-to-end: setPinned / findForModeration / listByPrincipal / disable / ModerationOptions, pinned_at and its partial index (baseline edited in place), pin term in notExpired and the sweep. patch.disabled is off the event union; patch.deleted no longer carries admin.

Glossary: Pinned patch and Moderation left packages/patches/CONTEXT.md; Retire/Delete lost the moderation/operator clauses; intro is upload + delete. docs/product.md § The operator has the issue-134 line; packages/companies/CONTEXT.md Operator has the same. Moderation/pin suites are gone; sweep tests have no pin case. patchy-mint-token and its docs/SKILL_DISTRIBUTION.md line are gone. CLI README / patchy skill still do not document the removed routes.

Upload/delete are owner-only by principal: no hasScope; Patches.delete(patchId, accountId); admin fixture cannot update/delete another principal’s patch (PatchesApi.test.ts “gives an admin no reach”).

(b) Scope creep

None material. Extra edits (CONTEXT-MAP, README, auth/analytics glossaries, package.json, product expiry sentence) follow the same pin/operator removal.

(c) Implemented but looks wrong

Leftover operator store, not routes. Spec: “Remove from the wire and the server: … POST /api/tokens and POST /api/tokens/:apiTokenId/revoke” and “no route acts on another bearer's token.” Routes are gone. Tokens.create still issues a token onto any existing principal (scopes included); Tokens.revoke still revokes any id with no owner check. Nothing in production calls them (only Tokens.test.ts). Spec listed routes/schemas, not the service, so this is leftover capability, not a missed Do.

Stale hosting copy. Spec surfaces include vocabulary. apps/server/CONTEXT.md still says the patches API group “publishes and moderates” it. Unlisted file; patches CONTEXT was updated.

AuthConfig still calls bootstrap “an admin token”; leftover scopes data is in-spec until the data ticket.

Intent vs #136

The remaining system matches the intent sentence: after this PR the API is mint, me, upload and delete; a bearer has no scopes to check; no route acts on another bearer's token; nothing can be pinned.

This removed operator capability in Patches, not just the HTTP door: disable / findForModeration / listByPrincipal / ModerationOptions are gone. An admin-scoped token cannot do what a ["read"] owner cannot. Taking a page down is a SQL stamp on disabled_at, which is the #134 interim (“a SQL statement by hand until the operator effort is designed”).

Tokens is door-only: create / revoke remain on the service with no bearer route. Bootstrap still labels itself an operator (admin scopes on /api/me, whoami prints them, comments still say “operator's own”) but does not authorize as one. Cosmetic, not a power hole — unless a later ticket re-exposes those methods.

skills/patchy still has “Publishing with an operator-issued token.” #136 said the public skill loses nothing here (it never documented these routes). Parent spec §4 deletes that section later. Correctly deferred.

Method

The cut is the right seam. Operator HTTP had to leave before the auth rewrite, and token create/revoke routes with it — their only guard was hasScope(..., "admin"). Leaving mint, /api/me, bootstrap, and the scopes column for the data ticket keeps Auth’s production interface intact. Dropping Identity.scopes now would change /api/me while the column still exists. Leaving pinned_at until a table rewrite would leave a dead column in the baseline an agent reads. Mixing disabled_at into this PR would steal retire (#93).

In-place baseline edit is honest. ADR-0003 rewrites history because nothing is deployed; a new 0004_drop_pinned_at would carry what that ADR rejected. Issue 136 asked for the same.

The 29 files are the surface list, not invented machinery. Net −1,298 lines. Remaining modules were mostly reshaped: Patches lost the moderation methods, PatchesApi is two handlers, AuthApi is mint + me, analytics dropped patch.disabled.

Verdict: sound with scars. The scars are leftover labels (admin fixture, bootstrap scopes, Tokens.create with no production caller), not a wrong cut.

YAGNI

No speculative generality was added. This is a real delete.

Would trim now, at zero extra cost:

  • The present-tense “moderation stays what it is today” sentence in docs/product.md, and “moderates” in apps/server/CONTEXT.md.
  • Unused malformedBody.
  • The /disable path in ApiGuard.test.ts (any unmatched /api/… shape would do).

Would not trim in this PR:

  • disabled_at / disabled_reason — that is the SQL takedown seam The operator is Patchy, not a token #134 left, not pin-column residue.
  • Identity.scopes, bootstrap ["admin","upload"], CLI whoami scopes — data ticket.
  • Tokens.revoke — visit freeze still needs it; login will too.
  • The “admin no reach” test — it is a deletion-regression that scopes grant nothing. Rename the fixture if you want, but keep the invariant until scopes leave Identity.

Tokens.create is the one leftover method that could go now: tests can insert via SQL the way Fixtures.revoke already does. Not a merge blocker.


Standards: 2 hard + 3 judgement; worst: docs/product.md still describing moderation as “what it is today.” Spec: 0 missing Do items, 2 leftover/wrong-copy findings; worst: apps/server/CONTEXT.md still saying the patches group “moderates.”

Address PR #147 review findings: remove unused operator creation and response helpers, keep revocation coverage through self-service minting, and correct stale operator surface documentation and guard fixtures.
@allisonmahmood

Copy link
Copy Markdown
Owner Author

Reviewed both agent reports against the source and #136. All five actionable findings are addressed in 6fceca5, committed and pushed.

Fixed

  1. Present-tense operator surfaces: docs/product.md now says the operator surfaces are not built and takedowns use SQL by hand until that effort is designed. The separate-login/dashboard boundary remains.
  2. Hosting vocabulary: apps/server/CONTEXT.md now describes the patches group as publishing and deleting, not moderating.
  3. Unused operator token creation: removed Tokens.create, CreateInput, and its now-unused scope encoder. It had no production caller. Existing revocation tests now obtain tokens through the surviving Tokens.mint service rather than introducing a SQL fixture helper.
  4. Unused response helper: removed the lowercase malformedBody export and its unused import. The MalformedBody error, body reader/decoder, and upload-specific refusals remain because upload still uses them. Corrected the body-reader comment to leave validation to the route schema.
  5. Obsolete guard fixture: replaced the /disable path with an unmatched POST to the patch path, preserving coverage of authentication and rate limiting before route-shape refusals.

Kept as-is, with reasons

  • Tokens.revoke: retains the existing revocation-state contract, including authentication refusal after revocation and idempotent/concurrent revocation semantics. There is no bearer route to it; the credential lifecycle rewrite remains feat(companies): companies, users and the machine token replace accounts and API tokens #137's work.
  • disabled_at / disabled_reason: required for the explicitly retained SQL-by-hand takedown state. Reads, writes, quota counting, and expiry must continue to honor it.
  • Legacy scope data and labels: Identity.scopes, stored/seeded scopes, CLI whoami output, bootstrap labels, and admin/reader fixtures remain inert until the data rewrite. The ownership tests still prove that an admin scope gives no cross-principal reach.
  • Public skill's existing-credential path: chore(patches): remove the operator's routes, the admin scope and pins #136 explicitly leaves the CLI README and public patchy skill unchanged; neither teaches the removed routes. The parent auth rollout removes that section later.
  • In-place patches baseline edit: explicitly required by chore(patches): remove the operator's routes, the admin scope and pins #136 because nothing is deployed. Existing local instances use pnpm dev reset; no new migration or replacement pin index is needed.

Verification on the pushed revision

  • Focused token/auth/API/guard/patch/expiry run: 35 tests passed across 8 files. This includes revocation through minted tokens, first-stamp concurrency, upload-body refusals, and owner-only writes/deletion.
  • Full pnpm test: 151 tests passed across 25 files.
  • pnpm typecheck, pnpm lint, pnpm format:check, and the packed CLI real-server e2e all passed locally.
  • CI run 33942629779 passed on 6fceca5: Node 22 and 24 tests, lint/format/typecheck, packed CLI smoke including lifecycle/signal probes, and dependency review. The labels job also passed.
  • GitHub reports CLEAN / MERGEABLE, with no unresolved review threads or change-request reviews. gh pr checks --required reports no checks marked required for this branch; every reported check is nevertheless green on the latest head.

No unresolved blockers. Ready to merge; not merged.

@vsrikar08

Copy link
Copy Markdown
Collaborator

Also find it extremely weird that someone who works at Patchy cannot delete stuff by other companies unless they directly go to the database. At that point let there be a special key for Patchy admins. come on.

@allisonmahmood

Copy link
Copy Markdown
Owner Author

@vsrikar08 Following up on your operator-key suggestion: Allison disagrees with this change. Keeping the removal of operator routes as proposed; we aren't restoring a special Patchy admin key or adding an operator takedown surface to this PR.

@allisonmahmood
allisonmahmood merged commit 456329b into main Sep 6, 2026
6 checks passed
@allisonmahmood
allisonmahmood deleted the auth/136-remove-operator-routes branch September 6, 2026 12:44
allisonmahmood added a commit that referenced this pull request Sep 6, 2026
## What changed

The auth build is complete, but its docs still mix the old publishing
model, shipped auth behavior and future plans. This pass reconciles the
map, glossaries, product, ADRs and setup recipes so a fresh agent can
sign in, log in the CLI, publish and open a page without reading an
issue.

**Rebased onto `main` after the auth stack merged.** This PR contains
the final documentation pass over PRs #147–#159, preserving the newer
invitation-expiry and current-public-version rules throughout the docs
and skills.

Closes #145.

## Surface audit

| Surface | What this pass found |
| --- | --- |
| Wire contract | Corrected deletion cleanup timing in endpoint prose
and regenerated `docs/API.md`; wire shapes unchanged. |
| CLI | Aligned login completion, credential precedence, sharing and
browser-only company reads across README, skill and onboarding;
refreshed the skill hash. |
| Dev loop | Reconciled Clerk keys, seed binding, isolated CLI state,
lifecycle and both live test tiers. |
| Vocabulary and product | Unified the five glossaries, corrected
context relationships, separated shipped behavior from future plans and
audited ADRs 0002–0008; none is superseded. |
| Migrations | Verified the three baselines at server, dev-runner and
Vitest composition sites; documentation clarified, migrations unchanged.
|
| Served pages | Corrected the example's publishing/access copy; no
product UI or HTML-policy changes. |
| Reverse states | Covered denial, logout, revocation, reactivation and
sharing reversal. |
| Repository layout | Updated package responsibilities, agent guidance
and authoritative versus generated skill paths. |

Removed obsolete route assertions while retaining general API-guard
coverage. The retired-concept sweep leaves only legitimate lexical
matches: dependency/origin pinning, sharing/cookie scopes and Effect's
`Command.unlisted`.

## How it was verified

- [x] `pnpm lint`, `pnpm typecheck`, `pnpm test` — 322 tests across 38
files.
- [x] `pnpm test:packed-cli-e2e` — complete packed CLI real-server
contract.
- [x] `pnpm test:clerk` — two Backend-API tests and two Playwright
workflows; cleanup confirmed zero test users remain.
- [x] Local dev startup, publishing, both sharing transitions at both
URL shapes, login handoff/pending/logout and rendered-example
inspection.
- [x] Skill hash and generated-bundle parity; relative Markdown file
links; 62 unique glossary headings with no duplicates.
- Standards review: two vocabulary findings fixed. Spec review:
state-directory default clarified. No open findings.

## Release impact

- [ ] **Breaking** — requires action from anyone already running this
- [x] **Not breaking** — documentation, endpoint-description and
obsolete-test cleanup only; runtime behavior and wire shapes unchanged.

Model: OpenAI GPT-6 Astra. Harness: Oh My Pi.

Integration verification: local formatting, lint, typecheck and all 322
offline tests pass. Reconciled both rounds of rebase conflicts,
refreshed the public skill hash, corrected ADR-0007’s stale no-expiry
claim, and documented the invitation-expiry migration. Final-head CI,
including live Clerk/browser and packed CLI checks, is the merge gate.

Integration: GPT-6 in the Codex harness.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

chore(patches): remove the operator's routes, the admin scope and pins

2 participants