Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

fix(backend): a renewed or re-revoked harness share tells nobody (#1724)

0xken151b6709ae5f35
diff --git a/backend/src/routes/harnessShares.test.ts b/backend/src/routes/harnessShares.test.ts
index d526b8aa9..e9c017104 100644
--- a/backend/src/routes/harnessShares.test.ts
+++ b/backend/src/routes/harnessShares.test.ts
@@ -114,12 +114,35 @@ describe('account-bound harness invitations', () => {
const id = randomUUID()
const remove = () => app.inject({ method: 'DELETE', url: `/api/harness-shares/${id}`, headers: auth })
expect((await remove()).json()).toEqual({ success: true, data: { removed: true } })
- expect(mocks.prisma.harnessShare.updateMany).toHaveBeenCalledWith({ where: { id, ownerId: 'owner', autonomousEnv: 'prod' }, data: { revokedAt: expect.any(Date) } })
+ expect(mocks.prisma.harnessShare.updateMany).toHaveBeenCalledWith({ where: { id, ownerId: 'owner', autonomousEnv: 'prod', OR: [{ revokedAt: null }, { revokedAt: { isSet: false } }] }, data: { revokedAt: expect.any(Date) } })
expect(mocks.changed).toHaveBeenCalledWith(id)
mocks.prisma.harnessShare.updateMany.mockResolvedValue({ count: 0 })
expect((await remove()).statusCode).toBe(404)
expect(mocks.changed).toHaveBeenCalledTimes(1)
})
+ // diego@'s 0.4.55 dev build took back the same invitations every few seconds and renewed others as often; each
+ // poked every member's every app to re-read its machines and shares (2026-10-26, the backend at its CPU limit).
+ it('answers a repeated revocation and a renewal without telling anyone again', async () => {
+ const id = randomUUID()
+ mocks.prisma.harnessShare.updateMany.mockResolvedValue({ count: 0 })
+ mocks.prisma.harnessShare.findFirst.mockResolvedValue({ id })
+ const removed = await app.inject({ method: 'DELETE', url: `/api/harness-shares/${id}`, headers: auth })
+ expect(removed.json()).toEqual({ success: true, data: { removed: true } })
+ const saved = { id, ...input(), ownerId: 'owner', superTabId: null, revokedAt: null, expiresAt: new Date(input().expiresAt) }
+ mocks.prisma.harnessShare.findUnique.mockResolvedValue(saved)
+ expect((await put({ ...input(), expiresAt: new Date(Date.now() + 31 * 86400_000).toISOString() }, id)).statusCode).toBe(200)
+ expect(mocks.prisma.harnessShare.upsert).toHaveBeenCalledTimes(1)
+ expect(mocks.changed).not.toHaveBeenCalled()
+ expect(mocks.listChanged).not.toHaveBeenCalled()
+ // What the recipient sees, changed: told.
+ for (const change of [{ name: 'Renamed' }, { engine: 'claude' }, { superTabId: 'c51479bd73b59e58176ad9e4' }]) {
+ mocks.prisma.harnessShare.findUnique.mockResolvedValue(saved)
+ await put({ ...input(), ...change }, id)
+ }
+ mocks.prisma.harnessShare.findUnique.mockResolvedValue({ ...saved, revokedAt: new Date() })
+ await put(input(), id)
+ expect(mocks.changed).toHaveBeenCalledTimes(4)
+ })
it('tells the invited account that its list changed, so its apps need not poll for invitations', async () => {
const id = randomUUID()
// First read is the "may this grant be changed" check (no row yet); the second is the saved invitation.
@@ -178,7 +201,7 @@ describe('account-bound harness invitations', () => {
expect(mocks.prisma.harnessShare.upsert).toHaveBeenCalledTimes(1)
const id = randomUUID()
expect((await app.inject({ method: 'DELETE', url: `/api/harness-shares/${id}`, headers: auth })).statusCode).toBe(200)
- expect(mocks.prisma.harnessShare.updateMany).toHaveBeenLastCalledWith({ where: { id, ownerId: 'owner', autonomousEnv: 'prod', machineId: 'team-mac' },
+ expect(mocks.prisma.harnessShare.updateMany).toHaveBeenLastCalledWith({ where: { id, ownerId: 'owner', autonomousEnv: 'prod', machineId: 'team-mac', OR: [{ revokedAt: null }, { revokedAt: { isSet: false } }] },
data: { revokedAt: expect.any(Date) } })
})
it('rechecks Super Tab membership for session admission and excludes revoked views from inventory', async () => {
diff --git a/backend/src/routes/harnessShares.ts b/backend/src/routes/harnessShares.ts
index 7bc1884f1..083c795d6 100644
--- a/backend/src/routes/harnessShares.ts
+++ b/backend/src/routes/harnessShares.ts
@@ -112,8 +112,14 @@ export async function harnessShareRoutes(app: FastifyInstance): Promise<void> {
ownerId: req.user!.sub, autonomousEnv: req.user!.autonomousEnv }
await prisma.harnessShare.upsert({ where: { id: req.params.id },
create: { id: req.params.id, ...data }, update: data })
- await publishShareChanged(req.params.id)
- await tellRecipient(req.params.id)
+ // Told only when what the recipient sees changes. A renewal moves only the expiry, and an owner daemon that
+ // renewed every few seconds (diego@'s 0.4.55 dev build, 2026-10-26) poked every member's every app to re-read
+ // its machines and shares three times a second, with the backend pinned at its CPU limit.
+ if (!existing || existing.revokedAt != null || existing.name !== data.name || existing.engine !== data.engine
+ || (existing.superTabId ?? null) !== data.superTabId || existing.ownerPublicKey !== data.ownerPublicKey) {
+ await publishShareChanged(req.params.id)
+ await tellRecipient(req.params.id)
+ }
sendSuccess(reply, { id: req.params.id })
},
)
@@ -122,10 +128,14 @@ export async function harnessShareRoutes(app: FastifyInstance): Promise<void> {
{ preHandler: [validateParams(params)] }, async (req, reply) => {
// A team session takes back only its own machine's shares.
const team = await teamMachineScope(req.user!)
- const changed = await prisma.harnessShare.updateMany({ where: {
- id: req.params.id, ownerId: req.user!.sub, autonomousEnv: req.user!.autonomousEnv, ...(team === null ? {} : { machineId: team }),
- }, data: { revokedAt: new Date() } })
- if (!changed.count) return sendError(reply, 'Invitation not found.', 'NOT_FOUND', 404)
+ const mine = { id: req.params.id, ownerId: req.user!.sub, autonomousEnv: req.user!.autonomousEnv, ...(team === null ? {} : { machineId: team }) }
+ // Only a live invitation is taken back and told: taking one back again changes nothing, and is answered so.
+ const changed = await prisma.harnessShare.updateMany({ where: { ...mine, OR: [{ revokedAt: null }, { revokedAt: { isSet: false } }] },
+ data: { revokedAt: new Date() } })
+ if (!changed.count) {
+ if (await prisma.harnessShare.findFirst({ where: mine, select: { id: true } })) return sendSuccess(reply, { removed: true })
+ return sendError(reply, 'Invitation not found.', 'NOT_FOUND', 404)
+ }
await publishShareChanged(req.params.id)
await tellRecipient(req.params.id)
sendSuccess(reply, { removed: true })