Repository navigation
feat: one-time agent enrollment codes (#286 P4) - #311
Merged
Merged
Conversation
An owner mints a short-lived, one-time code in Settings and gives it to an agent. P5 will require the code in the agent's access request (plans/002 D14), so only an agent the owner started can ask for access. Nothing redeems a code yet. - agentEnrollmentCodes table: only the SHA-256 of a code is stored. - mint (returns the code once), list and revoke for the signed-in owner; internal redeemEnrollmentCode validates and marks redeemed in one transaction and returns the owner. - 15 minute lifetime, 5 unused codes per account, 10 mints an hour through the rateLimits budget. - Settings section behind VITE_AGENT_ENROLLMENT_CODES, and minting behind the Convex env var AGENT_ENROLLMENT_CODES. Both are off by default. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
🚅 Deployed to the boop-pr-311 environment in Friends
|
# Conflicts: # docs/authenticated-function-inventory.md
|
This run was cancelled before it finished. |
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

PR P4 of the agent-signing plan:
plans/002-agent-signing-decisions.md(D14, Track A row P4, on thedocs/agent-signing-planbranch). Part of #286.An owner mints a short-lived, one-time code in Settings and gives it to an agent. P5 will require that code in the agent's access request, so only an agent the owner started can ask for access. That answers the request-spam question left open on #308.
Nothing consumes a code yet, and the feature is off by default.
What's here
agentEnrollmentCodes:ownerId,codeHash,label,createdAt,expiresAt,redeemedAt. Only the SHA-256 of a code is stored. Indexed by hash, by owner and by expiry.convex/agentEnrollment.tsmintEnrollmentCode({ label? })returns the plaintext code once.listEnrollmentCodes()returns the owner's unused codes, without the code or its hash.revokeEnrollmentCode({ codeId })deletes an unredeemed code.redeemEnrollmentCode({ code })checks that the code exists, is unexpired and is unredeemed, marks it redeemed in the same transaction, and returns{ ownerId, ownerDid, codeId, label }. Every failure returnsnull.ENROLLMENT_CODE_TTL_MS), 5 unused codes per account, 10 mints an hour per account.BOOP-XXXXX-XXXXX-XXXXX-XXXXX-XXXXX, 25 characters of Crockford base32 (125 bits). Case, spaces and hyphens are ignored, andI/L/Oread as1/1/0.docs/agent-enrollment-codes.md, including what P5 has to do with the code.Decisions worth a look
true. The repo has no feature-flag convention, so I addedsrc/lib/featureFlags.tswith the build-timeVITE_AGENT_ENROLLMENT_CODES. Minting is also gated on the Convex env varAGENT_ENROLLMENT_CODES, so the endpoint does nothing on a deployment that hasn't opted in.rateLimits. I pulled the body ofcheckAndIncrementInternalinto an exportedconsumeRateLimit(ctx, key, endpoint)so a mutation can spend a budget in its own transaction, and added anenrollmentCodeMintbudget. Behaviour of the existinginitiateandverifybudgets is unchanged.revokedAt.redeemEnrollmentCodeis internal with no caller. P5's unauthenticated endpoint has to limit attempts per IP.convex/_generated/api.d.tswas edited by hand to register the new module, becauseconvex codegenneeds a deployment and I didn't connect to one.Verification
tsc -b, the Convex and e2e typechecks, andeslinton the changed files: clean.bun test: 887 pass, 0 fail (main: 866).bun run build: green.scripts/agent-enrollment-codes.test.mjs(format, mint, hash-only storage, redeem, double redeem, expiry, revoke, cap, rate limit, session-only, server switch, cleanup) andscripts/agent-enrollment-code-ui.test.mjs(build flag, Settings section).🤖 Generated with Claude Code
Note
Add one-time agent enrollment codes behind feature flag (#286 P4)
BOOP-prefixed 25-symbol Crockford base32 strings, stored only as SHA-256 hashes, with a 15-minute lifetime and a 5-active-code per-account cap.agentEnrollmentCodesschema table, and a mint rate limit of 10 per hour in rateLimits.ts (with the fixed-window logic extracted intoconsumeRateLimit).AGENT_ENROLLMENT_CODES_ENABLEDis true; the server also requiresAGENT_ENROLLMENT_CODES="true"for minting.users.deleteUserStepduring account deletion. Codes are added but not yet consumed anywhere.rateLimits.tsendpoint validators now accept the newenrollmentCodeMintendpoint; account deletion now includes a bounded enrollment-code deletion step before the user row is removed.Macroscope summarized 2ec6987.