Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
record the cleanup receipt when a visitor leaves through the action channel
[._.]/ Adam Eivy502a07cbb753
diff --git a/server/routes/managedVisitors.test.js b/server/routes/managedVisitors.test.jsindex 820658d0a1..60f7c05f81 100644--- a/server/routes/managedVisitors.test.js+++ b/server/routes/managedVisitors.test.js@@ -157,6 +157,19 @@ it('unsequenced scoped leave revokes pending actions and retries unconfirmed cleexpect((await shared.broker.leave(auth, visit.sessionId, scope(visit))).status).toBe('left');expect((await shared.broker.leave(auth, visit.sessionId, scope(visit))).status).toBe('left');});+it('leaves through the action channel and still answers the follow-up cleanup call idempotently', async () => {+ // An app may end a visit in-band (`action: { type: 'leave' }`) and then make+ // the documented cleanup call. The host already acknowledged `status: 'left'`+ // for this scope, so the receipt is earned — without it the follow-up 409s+ // inside the boot quarantine window and the app holds embodiment ownership+ // paused for the full lease deadline over a session that left cleanly.+ const auth = await shared.broker.authenticate(credentials.credential), visit = await shared.broker.admit(auth, admission);+ const left = await shared.broker.action(auth, visit.sessionId, { ...scope(visit), sequence: 0, action: { type: 'leave' } });+ expect(left.status).toBe('left');+ expect((await shared.broker.leave(auth, visit.sessionId, scope(visit))).status).toBe('left');+ // The receipt is scope-checked like any other, not a blanket pass.+ await expect(shared.broker.leave(auth, visit.sessionId, { ...scope(visit), individualId: 'outside' })).rejects.toThrow(/scope/);+});it('cancels an unknown pending admission by original scope, waits for its acknowledgment and cleans it before confirming', async () => {const auth = await shared.broker.authenticate(credentials.credential); let release;delayed = new Promise(resolve => { release = resolve; });diff --git a/server/services/managedVisitorBroker.js b/server/services/managedVisitorBroker.jsindex 483baa82ed..dbf0289140 100644--- a/server/services/managedVisitorBroker.js+++ b/server/services/managedVisitorBroker.js@@ -173,7 +173,16 @@ export function createManagedVisitorBroker({ path, getApp, host, now = Date.nowconst expected = { start: 'running', pause: 'paused', rest: 'resting', move: 'running', leave: 'left' }[request.action.type];if (result.sequence !== request.sequence || result.status !== expected || result.expiresAt !== session.hostExpiresAt) throw fail('Host action sequence/status mismatch.');session.sequence = result.sequence;- if (request.action.type === 'leave') sessions.delete(id);+ // Same bookkeeping `close()` does on an acknowledged leave: the host+ // just confirmed `status: 'left'` for this scope, so the receipt is+ // earned. Without it a follow-up cleanup call inside the boot+ // quarantine window 409s on a session this process saw leave cleanly,+ // pausing the app's embodiment ownership for the full lease deadline.+ if (request.action.type === 'leave') {+ sessions.delete(id);+ remember(confirmedSessions, id, { ...session.scope });+ if (session.provenAdmission) remember(confirmedScopes, originalScopeKey(session.scope), true);+ }}return { ...result, sessionId: id, ...(observation ? {} : { expiresAt: session.expiresAt }) };})().catch(async () => { await close(session); throw fail('Host operation unavailable or inconsistent; visitor authority revoked.'); })