thinkpool-pair 0.7.249 → 0.7.250
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bridge.mjs +3 -1
- package/dispatch-permission-cleanup.mjs +8 -5
- package/package.json +1 -1
package/bridge.mjs
CHANGED
|
@@ -3142,7 +3142,9 @@ async function cancelRestoredDispatchPermissions(terminalIds) {
|
|
|
3142
3142
|
await Promise.all(terminals.map(async (terminalId) => {
|
|
3143
3143
|
const result = await cancelDurableDispatchPermissions({
|
|
3144
3144
|
supabaseUrl: SUPABASE_URL, anonKey: SUPABASE_ANON, token: codeAuthToken, roomCode: room,
|
|
3145
|
-
|
|
3145
|
+
// New bridge process, old durable bridge authority: filter by the
|
|
3146
|
+
// restored terminal and let the cleanup read each historical binding.
|
|
3147
|
+
terminalId, reason: 'bridge_restarted',
|
|
3146
3148
|
})
|
|
3147
3149
|
if (!result.ok && process.env.TP_DEBUG) process.stderr.write(`\n ◇ restored dispatch cleanup incomplete (${result.code})\n`)
|
|
3148
3150
|
}))
|
|
@@ -9,13 +9,13 @@ const SETTLED = new Set(['denied', 'idempotent_replay', 'already_resolved', 'sta
|
|
|
9
9
|
|
|
10
10
|
const safeString = (value) => typeof value === 'string' && value.length > 0
|
|
11
11
|
|
|
12
|
-
export function pendingDispatchItems (items, { bridgeId, terminalId, permissionIds = null } = {}) {
|
|
13
|
-
if (!safeString(bridgeId) || !safeString(terminalId)) return []
|
|
12
|
+
export function pendingDispatchItems (items, { bridgeId = null, terminalId, permissionIds = null } = {}) {
|
|
13
|
+
if ((bridgeId != null && !safeString(bridgeId)) || !safeString(terminalId)) return []
|
|
14
14
|
const requested = permissionIds == null ? null : new Set(permissionIds.filter(safeString))
|
|
15
15
|
return (Array.isArray(items) ? items : []).filter((item) => {
|
|
16
16
|
const permissionId = item?.request_context?.permission_id
|
|
17
17
|
return PENDING.has(item?.status) && item?.item_kind === 'approval' && item?.action_kind === 'dispatch' &&
|
|
18
|
-
item?.bridge_authority_id === bridgeId && item?.local_authority_id === terminalId &&
|
|
18
|
+
(!bridgeId || item?.bridge_authority_id === bridgeId) && item?.local_authority_id === terminalId &&
|
|
19
19
|
safeString(permissionId) && (!requested || requested.has(permissionId))
|
|
20
20
|
})
|
|
21
21
|
}
|
|
@@ -35,7 +35,7 @@ export async function cancelDurableDispatchPermissions ({
|
|
|
35
35
|
terminalId, permissionIds = null, reason = 'dispatch_superseded',
|
|
36
36
|
} = {}) {
|
|
37
37
|
if (typeof fetchImpl !== 'function' || !safeString(supabaseUrl) || !safeString(anonKey) ||
|
|
38
|
-
!safeString(token) || !safeString(roomCode) || !safeString(bridgeId) || !safeString(terminalId)) {
|
|
38
|
+
!safeString(token) || !safeString(roomCode) || (bridgeId != null && !safeString(bridgeId)) || !safeString(terminalId)) {
|
|
39
39
|
return Object.freeze({ ok: false, code: 'cleanup_unavailable', canceled: 0 })
|
|
40
40
|
}
|
|
41
41
|
if (permissionIds != null && (!Array.isArray(permissionIds) || !permissionIds.length)) {
|
|
@@ -54,7 +54,10 @@ export async function cancelDurableDispatchPermissions ({
|
|
|
54
54
|
p_decision: 'deny',
|
|
55
55
|
p_resolution_code: 'canceled',
|
|
56
56
|
p_resolution_payload: { decision: 'deny', reason },
|
|
57
|
-
|
|
57
|
+
// A restart receives a fresh bridge ID. The old row remains protected
|
|
58
|
+
// by its immutable authority binding, so resolve it with that exact
|
|
59
|
+
// value after the owner-authenticated RLS list—not a guessed current ID.
|
|
60
|
+
p_bridge_authority_id: item.bridge_authority_id,
|
|
58
61
|
p_local_authority_id: terminalId,
|
|
59
62
|
p_idempotency_key: `cancel-dispatch:${item.id}:${reason}`.slice(0, 160),
|
|
60
63
|
} })
|