feat(agent-harness): reuse authorized invitations with durable replay - #5704
Open
iscekic wants to merge 1 commit into
Open
feat(agent-harness): reuse authorized invitations with durable replay#5704iscekic wants to merge 1 commit into
iscekic wants to merge 1 commit into
Conversation
This was referenced Aug 29, 2026
Contributor
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Files Reviewed (8 files)
Reviewed by grok-4.6 · Input: 195.1K · Output: 23.5K · Cached: 961.7K Review guidance: REVIEW.md from base branch |
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.
No new behavior — this change prepares invitation handling without changing the existing invitation flow or adding approval controls.
Summary
executeHarnessInvitationandreconcileHarnessInvitationadd authorized backend execution and permanentkilo.invitereplay, usingInvocationSchemafor immutable arguments andCanonicalResultSchemafor stored responses.One transaction commits the invitation, audit, queue entry, and
agent_harness_invitation_resultsrecord containing the operation identity, fingerprint, invitation reference, and canonical result.Matching retries recover that result; changed arguments return
CONFLICT, and reconciliation returnsnullwithout a new effect when no result exists.Files
apps/web/src/lib/agent-harness/invitation.ts— adds server-derived actor/context, immutable recipient/role, normalized identifiers, a harness-only 64 KiB limit, and rejection of personal conversations or caller-selected authority. Execution calls the shared backend operation without a coding sandbox. User-before-thread locks serialize admission even without an operation record; both calls recheck current account, organization, membership, context, and grant authority under locks. Both calls check grant expiry after waiting for its lock. Replay survives invitation expiry, acceptance, revocation, deletion, and later billing expiry; invalid canonical results fail without replacement. Accepted work survives client sign-out; output includes onlyinvitationIdandemailQueued: true, not an invitation link or a delivery claim.apps/web/src/lib/agent-harness/invitation.test.ts— adds pure validation and mapping cases plus PostgreSQL cases for replay, reconciliation, atomic writes, current authority, transaction-local reads, and progress with occupied connections. Race cases exercise duplicate admission, role revocation, retirement, and account deletion in both orders; rollback cases cover queue and result failures.inviteOrganizationMemberextracts the complete authorized invitation operation and accepts a caller-owned transaction, so the harness andorganizations.members.inviteuse the same rules.Billing/trial checks, management-role and owner restrictions, single sign-on (SSO), audit records, queueing, and existing error mappings stay intact.
Legacy callers keep their input, response, middleware ordering, and duplicate-request conflicts; they need no operation identity and create no replay record.
Files
apps/web/src/lib/organizations/member-invitation.ts— adds the server-only operation and reuses the supplied transaction or opens one for the invitation, audit, and queue writes. It preserves pending-invitation and existing-member conflicts, child-organization refusal, SSO errors, and owner-only grants. The response remains{ acceptInviteUrl, invitationId, emailStatus: 'pending' }; email delivery retries and cron processing do not change.apps/web/src/routers/organizations/organization-members-router.ts— delegatesinviteto the shared operation while retainingInviteMemberSchemaand billing middleware. The compatibility comment retains old web/native callers until those clients retire.apps/web/src/routers/organizations/organization-members-router.test.ts— adds compatibility coverage for recipient case, seven-day expiry, the response and queue payload, absent replay records, duplicate-request conflicts without extra effects, authorization-before-validation, and SSO/trial failures.ensureOrganizationAccess,requireActiveSubscriptionOrTrial, andgetMostRecentSeatPurchaseaccept an optionalDrizzleTransactionso invitation checks use the same connection and transaction-local data.getOrganizationEntitlementClassificationpropagates that transaction through organization and seat reads, avoiding another pool checkout during execution and reconciliation.Callers that omit the transaction retain the primary-database default, role priority and inheritance, admin elevation telemetry, entitlement classification, ordering, and errors.
Files
apps/web/src/routers/organizations/utils.ts— uses the supplied transaction for direct and inherited membership queries, with the existing primary database as the default.apps/web/src/lib/organizations/trial-middleware.ts— passes the optional transaction through trial classification and organization/seat lookups; existing compute entitlement calls retain their default.apps/web/src/lib/organizations/organization-seats.ts— adds transaction-based lookup without changing newest-created ordering or thenullresult when no purchase exists.Tests: 2 files changed —
invitation.test.tsadded (1,170 lines);organization-members-router.test.tsexpanded (195 added lines).Generated: 0 files changed.
Verification
No manual verification ran for this level. Runtime verification remains pending at the completed stack tip; this level does not activate the complete runtime.
Visual Changes
Visual Changes: N/A
Reviewer Notes
run-checks.sh: formatting, lint, format verification, pure tests, test discovery, and diff validation.Human steps
Notes
Runtime verification remains pending at the completed stack tip. Local checks passed 24 pure cases; 52 PostgreSQL cases await CI. Test discovery does not prove transaction behavior or live effects.
Stacked PRs — merge bottom to top. Each level shows only its own diff.
Runtime verification (E2E, user advocacy, simplify) runs on the tip PR over every level.
Every level keeps its own checks, its own bot review, and its own threads; each one is answered on its own PR.
Each level is its own deliverable: it builds and passes its own checks alone.
A finding on a level is repaired on that level, then carried upward with stack.sh forward.
shared-agent-harness-3bb0— chore(agent-harness): register workspaces and enforce CI boundaries #5632shared-agent-harness-3bb0-s2— feat(agent-harness): define portable domain and snapshots #5637shared-agent-harness-3bb0-s3— feat(agent-harness): define commands tools and permission policy #5639shared-agent-harness-3bb0-s4— feat(agent-harness): share client state and cursor recovery #5643shared-agent-harness-3bb0-s5— feat(agent-harness): persist command intents and execution receipts #5647shared-agent-harness-3bb0-s6— feat(db): add harness ingress grants and retirement fences #5655shared-agent-harness-3bb0-s7— feat(agent-harness): deliver legacy history and project durable text #5659shared-agent-harness-3bb0-s8— feat(agent-harness): authorize durable grants and registered clients #5662shared-agent-harness-3bb0-s9— feat(agent-harness): fence retirement and retry payload cleanup #5667shared-agent-harness-3bb0-s10— feat(agent-harness): persist authoritative state in SQLite #5675shared-agent-harness-3bb0-s11— feat(agent-harness): admit durable runs and revisioned commands #5678shared-agent-harness-3bb0-s12— feat(agent-harness): recover queued runs and stream checkpointed steps #5688shared-agent-harness-3bb0-s13— feat(agent-harness): resolve interactions and dispatch tools sequentially #5693shared-agent-harness-3bb0-s14— feat(agent-harness): fence designated client tool execution #5697shared-agent-harness-3bb0-s15— feat(agent-harness): synchronize durable snapshots and legacy history #5701shared-agent-harness-3bb0-s16— feat(agent-harness): reuse authorized invitations with durable replay #5704 ← this PRshared-agent-harness-3bb0-s17— feat(integrations): bound repository transport for harness reads #5710shared-agent-harness-3bb0-s18— feat(integrations): expose bounded authorized repository reads #5714shared-agent-harness-3bb0-s19— feat(agent-harness): expose named authorized resource reads #5718 (tip)