@capybara-hq/kernel 0.1.0-rc.77 → 0.1.0-rc.79
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/bootstrap.json +6 -6
- package/dist/admin/outbox-dead.service.js +4 -1
- package/dist/agents/admin-agents.js +2 -0
- package/dist/agents/agent-lookup.js +4 -0
- package/dist/agents/agent-profile.service.js +3 -0
- package/dist/agents/agents.service.js +7 -0
- package/dist/agents/org-templates.js +1 -0
- package/dist/agents/pending-connector-requests.js +6 -0
- package/dist/agents/pending-connectors.service.js +2 -0
- package/dist/agents/readiness.service.d.ts +9 -3
- package/dist/agents/readiness.service.js +3 -3
- package/dist/agents/templates.js +1 -0
- package/dist/background/finish.js +3 -0
- package/dist/background/stop.js +2 -0
- package/dist/background/store.js +44 -0
- package/dist/background/tasks.service.js +3 -2
- package/dist/background/wake-rules.js +1 -0
- package/dist/catalog/admin-catalog.controller.d.ts +6 -0
- package/dist/catalog/admin-catalog.controller.js +13 -0
- package/dist/catalog/catalog-content.d.ts +9 -0
- package/dist/catalog/catalog-content.js +3 -1
- package/dist/catalog/catalog-items.js +4 -0
- package/dist/catalog/catalog-scope.service.js +4 -1
- package/dist/catalog/component-promotion.js +2 -0
- package/dist/catalog/component-scope.controller.d.ts +9 -15
- package/dist/catalog/component-scope.controller.js +14 -9
- package/dist/catalog/component-scope.service.js +5 -0
- package/dist/catalog/component-state.d.ts +4 -1
- package/dist/catalog/component-state.js +4 -2
- package/dist/catalog/marketplace-fetch.d.ts +1 -1
- package/dist/catalog/marketplace-fetch.js +1 -1
- package/dist/catalog/marketplaces.service.d.ts +6 -1
- package/dist/catalog/marketplaces.service.js +8 -3
- package/dist/catalog/org-catalog.controller.d.ts +9 -0
- package/dist/catalog/org-catalog.controller.js +18 -0
- package/dist/catalog/org-catalog.schemas.d.ts +2 -4
- package/dist/catalog/org-catalog.schemas.js +2 -3
- package/dist/catalog/org-catalog.service.d.ts +10 -1
- package/dist/catalog/org-catalog.service.js +34 -23
- package/dist/catalog/org-extension-switch.d.ts +3 -10
- package/dist/catalog/org-extension-switch.js +14 -60
- package/dist/catalog/org-extension.controller.d.ts +6 -7
- package/dist/catalog/org-extension.controller.js +4 -4
- package/dist/catalog/org-extension.schemas.d.ts +1 -2
- package/dist/catalog/org-extension.schemas.js +1 -3
- package/dist/catalog/owned-items.js +10 -1
- package/dist/catalog/ownership.js +2 -0
- package/dist/catalog/plugin-import.d.ts +3 -0
- package/dist/catalog/plugin-import.js +10 -1
- package/dist/catalog/plugin-install.d.ts +1 -4
- package/dist/catalog/plugin-install.js +11 -12
- package/dist/catalog/plugin-upgrade.js +4 -1
- package/dist/catalog/request-rules.js +6 -0
- package/dist/catalog/requests.service.js +4 -0
- package/dist/catalog/scope-orgs.js +1 -0
- package/dist/catalog/scope-sync.d.ts +8 -5
- package/dist/catalog/scope-sync.js +21 -23
- package/dist/catalog/template-description.d.ts +17 -0
- package/dist/catalog/template-description.js +18 -0
- package/dist/catalog/unshare.js +3 -0
- package/dist/channels/connections.service.js +1 -0
- package/dist/channels/inbound.js +1 -0
- package/dist/channels/jobs.js +1 -0
- package/dist/channels/outbound.js +6 -0
- package/dist/channels/supervisor.js +1 -0
- package/dist/channels/threads.js +1 -0
- package/dist/client/client-reports.service.js +1 -0
- package/dist/config/fields.js +20 -4
- package/dist/config/schema.d.ts +1 -1
- package/dist/config/schema.js +13 -13
- package/dist/conversations/access.js +1 -0
- package/dist/conversations/attachments.service.js +16 -4
- package/dist/conversations/conversations.service.js +17 -3
- package/dist/conversations/event-log.js +2 -0
- package/dist/conversations/events.d.ts +1 -0
- package/dist/conversations/events.js +3 -1
- package/dist/conversations/files.js +3 -2
- package/dist/conversations/permission-profiles.service.js +1 -0
- package/dist/conversations/prompt-suggestions.js +2 -0
- package/dist/conversations/queue.js +8 -0
- package/dist/conversations/queue.service.js +6 -2
- package/dist/conversations/source.js +2 -0
- package/dist/conversations/titles.js +10 -2
- package/dist/conversations/tree.js +6 -0
- package/dist/db/kernel-schema.d.ts +5 -1
- package/dist/devices/conversation-devices.js +3 -0
- package/dist/devices/device-projects.service.js +2 -0
- package/dist/devices/devices.service.js +5 -0
- package/dist/devices/legacy-cleanup.job.js +5 -2
- package/dist/dial-in/handlers.js +2 -0
- package/dist/dial-in/machines.js +11 -2
- package/dist/dial-in/targets.d.ts +0 -2
- package/dist/dial-in/targets.js +0 -10
- package/dist/errors.d.ts +0 -1
- package/dist/errors.js +0 -1
- package/dist/evals/budget.js +14 -1
- package/dist/evals/run-replay.js +4 -0
- package/dist/evals/runs.service.js +13 -7
- package/dist/evals/sets.service.js +23 -8
- package/dist/evals/trajectory.service.d.ts +1 -1
- package/dist/evals/trajectory.service.js +1 -0
- package/dist/evals/worker.js +5 -1
- package/dist/extensions/admin-ops.js +1 -0
- package/dist/extensions/admin-view.js +3 -1
- package/dist/extensions/bootstrap-packages.d.ts +12 -1
- package/dist/extensions/bootstrap-packages.js +49 -9
- package/dist/extensions/bootstrap.d.ts +17 -2
- package/dist/extensions/bootstrap.js +41 -9
- package/dist/extensions/config-json-schema.d.ts +2 -2
- package/dist/extensions/config-json-schema.js +1 -3
- package/dist/extensions/deployment-config.d.ts +5 -3
- package/dist/extensions/deployment-config.js +3 -3
- package/dist/extensions/effective-config.d.ts +8 -7
- package/dist/extensions/effective-config.js +8 -7
- package/dist/extensions/enabled.js +1 -0
- package/dist/extensions/host.d.ts +4 -3
- package/dist/extensions/host.js +11 -12
- package/dist/extensions/instance.d.ts +1 -1
- package/dist/extensions/instance.js +17 -2
- package/dist/extensions/org-config.d.ts +35 -97
- package/dist/extensions/org-config.js +48 -315
- package/dist/extensions/org-levels.d.ts +22 -9
- package/dist/extensions/org-levels.js +100 -20
- package/dist/extensions/org-overrides.d.ts +14 -15
- package/dist/extensions/org-overrides.js +20 -20
- package/dist/extensions/package.js +1 -1
- package/dist/extensions/permission-set.d.ts +1 -3
- package/dist/extensions/permission-set.js +3 -7
- package/dist/extensions/permission-view.d.ts +3 -1
- package/dist/extensions/permission-view.js +5 -4
- package/dist/extensions/plugin-icons.d.ts +80 -1
- package/dist/extensions/plugin-icons.js +211 -2
- package/dist/extensions/point-defaults.d.ts +17 -18
- package/dist/extensions/point-defaults.js +25 -28
- package/dist/git/gateway.js +1 -1
- package/dist/git/identity.d.ts +1 -1
- package/dist/git/identity.js +2 -2
- package/dist/identity/accounts.js +6 -0
- package/dist/identity/api-tokens.js +8 -0
- package/dist/infra/outbox/outbox.dispatcher.js +4 -1
- package/dist/infra/outbox/outbox.service.js +2 -0
- package/dist/net/public-address.d.ts +3 -3
- package/dist/net/public-address.js +3 -3
- package/dist/orgs/directory-sync.d.ts +9 -6
- package/dist/orgs/directory-sync.js +15 -12
- package/dist/orgs/invitations.service.js +2 -0
- package/dist/orgs/members.service.js +2 -0
- package/dist/orgs/offboarding.js +2 -0
- package/dist/packages/npm.d.ts +10 -2
- package/dist/packages/npm.js +38 -6
- package/dist/platform/exclusions.js +20 -0
- package/dist/platform/ops/admin-items.ops.js +1 -0
- package/dist/platform/ops/agents.ops.js +1 -0
- package/dist/platform/ops/connectors.ops.js +7 -1
- package/dist/platform/ops/extensions.ops.d.ts +6 -8
- package/dist/platform/ops/extensions.ops.js +18 -97
- package/dist/platform/ops/org-plugins.ops.d.ts +3 -6
- package/dist/platform/ops/org-plugins.ops.js +14 -65
- package/dist/platform/ops/outbox.ops.js +1 -0
- package/dist/platform/ops/person-inputs.d.ts +0 -4
- package/dist/platform/ops/person-inputs.js +0 -8
- package/dist/platform/ops/plugins.ops.d.ts +4 -1
- package/dist/platform/ops/plugins.ops.js +27 -34
- package/dist/platform/person-fields.d.ts +1 -1
- package/dist/platform/person-fields.js +1 -1
- package/dist/platform/sealed-reveals.js +2 -0
- package/dist/push/recipients.js +9 -2
- package/dist/runtime/permission-context.service.js +1 -0
- package/dist/runtime/plugin-context.service.js +1 -0
- package/dist/runtime/project/knowledge.service.js +1 -0
- package/dist/runtime/run-context.service.js +1 -0
- package/dist/runtime/run-deletion.js +4 -0
- package/dist/runtime/run-execution.js +2 -0
- package/dist/runtime/run-finish.js +3 -0
- package/dist/runtime/run-jobs.js +3 -0
- package/dist/runtime/run-orphan-check.job.js +7 -0
- package/dist/runtime/run-queue.js +21 -2
- package/dist/runtime/run-worker.js +5 -0
- package/dist/runtime/step-log.js +1 -0
- package/dist/runtime/subagents/child.js +2 -0
- package/dist/runtime/subagents/deliveries.js +3 -0
- package/dist/runtime/subagents/dispatch.js +5 -1
- package/dist/runtime/subagents/messages.js +2 -0
- package/dist/runtime/subagents/org-agents.d.ts +1 -1
- package/dist/runtime/subagents/org-agents.js +2 -1
- package/dist/runtime/usage-report-jobs.js +1 -0
- package/dist/runtime/usage-report.js +3 -0
- package/dist/runtime/waits.js +5 -0
- package/dist/sandbox/cloud-permission-snapshot.js +9 -3
- package/dist/sandbox/device-reports.js +3 -0
- package/dist/sandbox/legacy-retirement.js +5 -1
- package/dist/sandbox/managed-device-context.js +1 -0
- package/dist/sandbox/modes.d.ts +5 -2
- package/dist/sandbox/modes.js +8 -4
- package/dist/sandbox/network-grants.js +2 -0
- package/dist/sandbox/operation-intents.js +58 -0
- package/dist/sandbox/operation-reconcile.job.js +2 -0
- package/dist/sandbox/permission-authority-lock.js +12 -6
- package/dist/sandbox/permission-call-grants.js +6 -0
- package/dist/sandbox/permission-ceiling-writes.js +5 -0
- package/dist/sandbox/permission-config-publication.js +5 -0
- package/dist/sandbox/permission-instance-writes.js +4 -0
- package/dist/sandbox/permission-runtime-reports.js +10 -1
- package/dist/sandbox/permission-transitions.js +3 -0
- package/dist/sandbox/review/review.service.js +8 -5
- package/dist/sandbox/sandbox.service.d.ts +14 -0
- package/dist/sandbox/sandbox.service.js +195 -29
- package/dist/sandbox/unreachable.js +4 -1
- package/dist/schedules/fire.js +9 -3
- package/dist/schedules/pause.js +2 -0
- package/dist/schedules/run-tracker.js +16 -1
- package/dist/schedules/scheduled-tasks.service.js +4 -2
- package/dist/schedules/store.js +8 -0
- package/dist/schedules/unattended.js +4 -0
- package/dist/setup/setup-checks.service.d.ts +1 -10
- package/dist/setup/setup-checks.service.js +19 -29
- package/dist/shares/share-open.service.js +1 -0
- package/dist/shares/shares.service.js +2 -0
- package/dist/skills/agent-skills.service.d.ts +1 -1
- package/dist/skills/agent-skills.service.js +13 -2
- package/dist/skills/catalog.js +3 -0
- package/dist/skills/changes.service.js +10 -2
- package/dist/skills/conversation-catalog.js +1 -0
- package/dist/skills/skills.service.js +4 -0
- package/dist/tools/approvals.service.js +40 -0
- package/dist/tools/builtins/schedules.js +11 -6
- package/dist/tools/builtins/web/fetch.js +1 -1
- package/dist/tools/builtins/web/search.js +1 -1
- package/dist/tools/connector-account-policies.js +3 -0
- package/dist/tools/connectors.controller.d.ts +37 -9
- package/dist/tools/connectors.controller.js +47 -12
- package/dist/tools/connectors.schemas.d.ts +4 -0
- package/dist/tools/connectors.schemas.js +13 -1
- package/dist/tools/connectors.service.d.ts +17 -0
- package/dist/tools/connectors.service.js +36 -2
- package/dist/tools/drift.js +5 -0
- package/dist/tools/git-push-policy.js +3 -0
- package/dist/tools/oauth/discovery.d.ts +2 -2
- package/dist/tools/oauth/discovery.js +2 -2
- package/dist/tools/oauth/flow.js +1 -0
- package/dist/tools/outputs.js +2 -0
- package/dist/tools/permission-approval-jobs.js +3 -0
- package/dist/tools/pipeline.js +2 -0
- package/dist/tools/policy.js +3 -0
- package/dist/tools/questions.service.js +13 -0
- package/package.json +3 -3
- package/src/migrations/0181_connector_description.sql +3 -0
package/dist/push/recipients.js
CHANGED
|
@@ -41,6 +41,8 @@ async function resolveConversation(db, conversationId, seq) {
|
|
|
41
41
|
const trigger = pushTriggerOf({ type: event.type, payload: event.payload });
|
|
42
42
|
if (trigger === null)
|
|
43
43
|
return null;
|
|
44
|
+
// org-filter: conversationId comes from the kernel-written push fan-out job; this read learns
|
|
45
|
+
// the conversation's org, which every later read filters by
|
|
44
46
|
const conv = await db
|
|
45
47
|
.selectFrom("conversations")
|
|
46
48
|
.select(["org_id", "kind", "account_id", "deleted_at"])
|
|
@@ -60,6 +62,7 @@ async function resolveConversation(db, conversationId, seq) {
|
|
|
60
62
|
.selectFrom("conversations")
|
|
61
63
|
.select(["org_id", "kind", "account_id", "deleted_at"])
|
|
62
64
|
.where("id", "=", rootId)
|
|
65
|
+
.where("org_id", "=", orgId)
|
|
63
66
|
.executeTakeFirst();
|
|
64
67
|
if (root !== null &&
|
|
65
68
|
(root === undefined ||
|
|
@@ -148,6 +151,7 @@ async function resolveConversation(db, conversationId, seq) {
|
|
|
148
151
|
.selectFrom("conversations")
|
|
149
152
|
.select(["agent_id", "title"])
|
|
150
153
|
.where("id", "=", rootId)
|
|
154
|
+
.where("org_id", "=", orgId)
|
|
151
155
|
.executeTakeFirstOrThrow();
|
|
152
156
|
const org = encodeURIComponent(orgId);
|
|
153
157
|
const path = rootId === conversationId
|
|
@@ -159,12 +163,14 @@ async function resolveConversation(db, conversationId, seq) {
|
|
|
159
163
|
category: trigger.category,
|
|
160
164
|
path,
|
|
161
165
|
threadId: rootId,
|
|
162
|
-
title: await agentName(db, rootRow.agent_id),
|
|
166
|
+
title: await agentName(db, orgId, rootRow.agent_id),
|
|
163
167
|
conversationTitle: rootRow.title,
|
|
164
168
|
text: trigger.text,
|
|
165
169
|
};
|
|
166
170
|
}
|
|
167
171
|
async function resolveSchedule(db, taskRunId) {
|
|
172
|
+
// org-filter: taskRunId comes from the kernel-written push fan-out job; this read learns the
|
|
173
|
+
// run's org (checked against its task's below), which every later read filters by
|
|
168
174
|
const row = await db
|
|
169
175
|
.selectFrom("scheduled_task_runs")
|
|
170
176
|
.innerJoin("scheduled_tasks", "scheduled_tasks.id", "scheduled_task_runs.task_id")
|
|
@@ -249,7 +255,7 @@ async function activeMembers(db, orgId, ids) {
|
|
|
249
255
|
return rows.map((r) => r.id);
|
|
250
256
|
}
|
|
251
257
|
/** The agent's name in its current version (empty when it has none). */
|
|
252
|
-
async function agentName(db, agentId) {
|
|
258
|
+
async function agentName(db, orgId, agentId) {
|
|
253
259
|
const row = await db
|
|
254
260
|
.selectFrom("agents")
|
|
255
261
|
.innerJoin("agent_versions", (j) => j
|
|
@@ -257,6 +263,7 @@ async function agentName(db, agentId) {
|
|
|
257
263
|
.onRef("agent_versions.version", "=", "agents.current_version"))
|
|
258
264
|
.select("agent_versions.definition")
|
|
259
265
|
.where("agents.id", "=", agentId)
|
|
266
|
+
.where("agents.org_id", "=", orgId)
|
|
260
267
|
.executeTakeFirst();
|
|
261
268
|
const name = row?.definition?.name;
|
|
262
269
|
return typeof name === "string" ? name : "";
|
|
@@ -137,6 +137,7 @@ let PermissionContextRecorder = class PermissionContextRecorder {
|
|
|
137
137
|
.selectFrom("conversations")
|
|
138
138
|
.select(["org_id", "kind", "eval_run_id"])
|
|
139
139
|
.where("id", "=", input.conversationId)
|
|
140
|
+
.where("org_id", "=", input.orgId)
|
|
140
141
|
.executeTakeFirst();
|
|
141
142
|
if (!conv || conv.org_id !== input.orgId)
|
|
142
143
|
throw new ApiError("conversation.not_found", "Conversation not found");
|
|
@@ -160,6 +160,7 @@ let PluginContextService = class PluginContextService {
|
|
|
160
160
|
.selectFrom("conversations")
|
|
161
161
|
.select("id")
|
|
162
162
|
.where("id", "=", input.conversationId)
|
|
163
|
+
.where("org_id", "=", input.orgId)
|
|
163
164
|
.forUpdate()
|
|
164
165
|
.executeTakeFirst();
|
|
165
166
|
if (await runEndedIn(t, input.runId))
|
|
@@ -297,6 +297,7 @@ let ProjectKnowledgeService = class ProjectKnowledgeService {
|
|
|
297
297
|
.selectFrom("conversations")
|
|
298
298
|
.select("id")
|
|
299
299
|
.where("id", "=", input.conversationId)
|
|
300
|
+
.where("org_id", "=", input.orgId)
|
|
300
301
|
.forUpdate()
|
|
301
302
|
.executeTakeFirst();
|
|
302
303
|
if (await runEndedIn(t, input.runId))
|
|
@@ -76,12 +76,15 @@ let RunDeletion = class RunDeletion {
|
|
|
76
76
|
.selectFrom("background_tasks as b")
|
|
77
77
|
.select("b.id")
|
|
78
78
|
.whereRef("b.sandbox_conversation_id", "=", "c.id")
|
|
79
|
+
.whereRef("b.org_id", "=", "c.org_id")
|
|
79
80
|
.where("b.status", "=", RUNNING_TASK_STATUS)),
|
|
80
81
|
]))
|
|
81
82
|
.orderBy("c.id")
|
|
82
83
|
.limit(100)
|
|
83
84
|
.execute();
|
|
84
85
|
}
|
|
86
|
+
// org-filter: the id is the deleted root (ConversationsService.remove checked writable(orgId)
|
|
87
|
+
// first, or the outbox row it wrote); only a deleted conversation is acted on
|
|
85
88
|
async stopTree(conversationId, byAccountId) {
|
|
86
89
|
const root = await this.db
|
|
87
90
|
.selectFrom("conversations")
|
|
@@ -107,6 +110,7 @@ let RunDeletion = class RunDeletion {
|
|
|
107
110
|
await this.stopConversationIn(conversationId, byAccountId);
|
|
108
111
|
await this.background.stopForDeletedConversation(conversationId);
|
|
109
112
|
}
|
|
113
|
+
// org-filter: locks a conversation stopTree / stopDeletedConversation / the org sweep resolved
|
|
110
114
|
async stopConversationIn(conversationId, byAccountId, reason = "user") {
|
|
111
115
|
await this.db
|
|
112
116
|
.selectFrom("conversations")
|
|
@@ -90,6 +90,7 @@ let RunExecution = class RunExecution {
|
|
|
90
90
|
async claim(conversationId, runId, executionId, live = () => true) {
|
|
91
91
|
if (!live())
|
|
92
92
|
return null;
|
|
93
|
+
// org-filter: the worker's claim of a kernel-written run job; reads the conversation's own org
|
|
93
94
|
const conv = await this.db
|
|
94
95
|
.selectFrom("conversations")
|
|
95
96
|
.select("org_id")
|
|
@@ -156,6 +157,7 @@ let RunExecution = class RunExecution {
|
|
|
156
157
|
.selectFrom("conversations")
|
|
157
158
|
.select("deleted_at")
|
|
158
159
|
.where("id", "=", claim.rootId)
|
|
160
|
+
.where("org_id", "=", claim.orgId)
|
|
159
161
|
.forNoKeyUpdate()
|
|
160
162
|
.executeTakeFirst();
|
|
161
163
|
if (!root || !isLive(root.deleted_at))
|
|
@@ -84,6 +84,8 @@ let RunFinish = class RunFinish {
|
|
|
84
84
|
* approval and input request rows, the run row; they never deadlock with each other.
|
|
85
85
|
* 调用方在提交后对非 null 的返回值调用 {@link notifyFinished}。
|
|
86
86
|
*/
|
|
87
|
+
// org-filter: ends a run by its kernel-resolved run and conversation ids (worker claim, stop and
|
|
88
|
+
// decision paths that checked the org); the conversation's own org is read here
|
|
87
89
|
async finishIn(a) {
|
|
88
90
|
const t = this.kdb.db;
|
|
89
91
|
const conv = await t
|
|
@@ -178,6 +180,7 @@ let RunFinish = class RunFinish {
|
|
|
178
180
|
.selectFrom("conversations")
|
|
179
181
|
.select("id")
|
|
180
182
|
.where("parent_conversation_id", "=", a.conversationId)
|
|
183
|
+
.where("org_id", "=", orgId)
|
|
181
184
|
.where("kind", "=", "subagent")
|
|
182
185
|
.limit(1)
|
|
183
186
|
.executeTakeFirst()) !== undefined;
|
package/dist/runtime/run-jobs.js
CHANGED
|
@@ -38,6 +38,8 @@ export { TERMINAL_STATUSES } from "./run-status.js";
|
|
|
38
38
|
* that writes them (conversation, decided rows, run; ruling R19), so a stop, a run's end, a decision
|
|
39
39
|
* and a timeout never deadlock. Returns whether any of them is still pending.
|
|
40
40
|
*/
|
|
41
|
+
// org-filter: locks the wait rows of a run the caller already holds (its conversation row is
|
|
42
|
+
// locked first); run ids are kernel-resolved, never request input
|
|
41
43
|
export async function lockWaitRowsIn(t, runId) {
|
|
42
44
|
const approvals = await t
|
|
43
45
|
.selectFrom("approvals")
|
|
@@ -253,6 +255,7 @@ let RunResume = class RunResume {
|
|
|
253
255
|
.executeTakeFirst();
|
|
254
256
|
if (!row)
|
|
255
257
|
return "other-wait-pending";
|
|
258
|
+
// org-filter: the conversation of the run row just resumed above; reads its own org
|
|
256
259
|
const conv = await t
|
|
257
260
|
.selectFrom("conversations")
|
|
258
261
|
.select(["kind", "org_id"])
|
|
@@ -92,6 +92,8 @@ export async function orphanCandidates(db, statuses, minAgeMs, limit, after) {
|
|
|
92
92
|
}
|
|
93
93
|
/** Whether delivery is still owed by a pending outbox row; dead copies are not active work.
|
|
94
94
|
*/
|
|
95
|
+
// org-filter: outbox rows looked up by queue and deterministic kernel job id (unique across the
|
|
96
|
+
// deployment) in the deployment-wide orphan check; outbox.org_id is nullable
|
|
95
97
|
export async function jobInOutbox(db, queue, jobId) {
|
|
96
98
|
const row = await db
|
|
97
99
|
.selectFrom("outbox")
|
|
@@ -266,6 +268,8 @@ let RunOrphanCheck = class RunOrphanCheck {
|
|
|
266
268
|
.onConflict((oc) => oc.column("name").doUpdateSet(values))
|
|
267
269
|
.execute();
|
|
268
270
|
}
|
|
271
|
+
// org-filter: outbox rows looked up by queue and deterministic kernel job id (unique across the
|
|
272
|
+
// deployment) in the deployment-wide orphan check; outbox.org_id is nullable
|
|
269
273
|
async hasDeadDelivery(c) {
|
|
270
274
|
return ((await this.db
|
|
271
275
|
.selectFrom("outbox")
|
|
@@ -321,6 +325,8 @@ let RunOrphanCheck = class RunOrphanCheck {
|
|
|
321
325
|
if (deliveryFailed) {
|
|
322
326
|
// Lock dead rows against admin retry. A pending retry always takes precedence over a
|
|
323
327
|
// historical dead copy. Producers of replacement jobs also hold this conversation lock.
|
|
328
|
+
// org-filter: outbox rows by queue and deterministic kernel job id (unique across the
|
|
329
|
+
// deployment); outbox.org_id is nullable
|
|
324
330
|
const deliveries = await this.db
|
|
325
331
|
.selectFrom("outbox")
|
|
326
332
|
.select("dead_at")
|
|
@@ -370,6 +376,7 @@ let RunOrphanCheck = class RunOrphanCheck {
|
|
|
370
376
|
.selectFrom("conversations")
|
|
371
377
|
.select("id")
|
|
372
378
|
.where("id", "=", c.conversationId)
|
|
379
|
+
.where("org_id", "=", c.orgId)
|
|
373
380
|
.forUpdate()
|
|
374
381
|
.executeTakeFirst();
|
|
375
382
|
const r = await this.db
|
|
@@ -133,6 +133,8 @@ let RunQueue = class RunQueue {
|
|
|
133
133
|
return this.startCompactionIn(conversationId, accountId);
|
|
134
134
|
}
|
|
135
135
|
/** {@link startCompaction}'s transaction: the active-run check, the run row and its owed job. */
|
|
136
|
+
// org-filter: the only caller (ConversationsService.compact) checked writable(orgId, ...) first;
|
|
137
|
+
// the conversation's own org is read under its row lock
|
|
136
138
|
async startCompactionIn(conversationId, accountId) {
|
|
137
139
|
const t = this.db;
|
|
138
140
|
const conv = await t
|
|
@@ -166,6 +168,7 @@ let RunQueue = class RunQueue {
|
|
|
166
168
|
.selectFrom("agents")
|
|
167
169
|
.select(["current_version", "deleted_at"])
|
|
168
170
|
.where("id", "=", conv.agent_id)
|
|
171
|
+
.where("org_id", "=", conv.org_id)
|
|
169
172
|
.executeTakeFirst();
|
|
170
173
|
if (!agent || agent.deleted_at !== null) {
|
|
171
174
|
throw new ApiError("conversation.not_found", "Conversation not found");
|
|
@@ -193,6 +196,8 @@ let RunQueue = class RunQueue {
|
|
|
193
196
|
return runId;
|
|
194
197
|
}
|
|
195
198
|
/** {@link ensureRun}'s transaction: what it decided goes back through `st`. */
|
|
199
|
+
// org-filter: ensure-run is keyed by a kernel-resolved conversation id (after a write that checked
|
|
200
|
+
// the org, or an owed outbox job); the conversation's own org is read under its row lock
|
|
196
201
|
async ensureRunIn(conversationId, st) {
|
|
197
202
|
const t = this.db;
|
|
198
203
|
const conv = await t
|
|
@@ -248,6 +253,7 @@ let RunQueue = class RunQueue {
|
|
|
248
253
|
.selectFrom("agents")
|
|
249
254
|
.select("deleted_at")
|
|
250
255
|
.where("id", "=", conv.agent_id)
|
|
256
|
+
.where("org_id", "=", conv.org_id)
|
|
251
257
|
.executeTakeFirstOrThrow();
|
|
252
258
|
if (owner.deleted_at !== null)
|
|
253
259
|
return null;
|
|
@@ -322,6 +328,7 @@ let RunQueue = class RunQueue {
|
|
|
322
328
|
.selectFrom("agents")
|
|
323
329
|
.select(["current_version", "deleted_at"])
|
|
324
330
|
.where("id", "=", conv.agent_id)
|
|
331
|
+
.where("org_id", "=", conv.org_id)
|
|
325
332
|
.executeTakeFirstOrThrow();
|
|
326
333
|
// agent 已软删除:会话对任何人都不可见,不再为它起运行。
|
|
327
334
|
if (agent.deleted_at !== null)
|
|
@@ -358,6 +365,7 @@ let RunQueue = class RunQueue {
|
|
|
358
365
|
.updateTable("conversations")
|
|
359
366
|
.set({ tree_stopped_at: null })
|
|
360
367
|
.where("id", "=", conversationId)
|
|
368
|
+
.where("org_id", "=", conv.org_id)
|
|
361
369
|
.execute();
|
|
362
370
|
}
|
|
363
371
|
return runId;
|
|
@@ -437,7 +445,7 @@ let RunQueue = class RunQueue {
|
|
|
437
445
|
// with nothing running (or one whose report raced the stop) is not woken by a late finish
|
|
438
446
|
if (await treeStopped(t, rootId))
|
|
439
447
|
return null;
|
|
440
|
-
const wake = (await this.pendingMessageIn(conversationId, Number(conv.consumed_seq), rootId)) ??
|
|
448
|
+
const wake = (await this.pendingMessageIn(conversationId, Number(conv.consumed_seq), rootId, conv.org_id)) ??
|
|
441
449
|
(await wakeDecisionIn(t, { id: conversationId, orgId: conv.org_id, rootId }, Number(conv.consumed_seq), this.config.get().runtime.wakeOnBackgroundTask, (accountId) => authorCanSend(t, rootId, accountId)));
|
|
442
450
|
if (wake?.kind === "later") {
|
|
443
451
|
await this.jobs.oweBgWake(conversationId, wake, st.wakeRetry, conv.org_id);
|
|
@@ -449,6 +457,7 @@ let RunQueue = class RunQueue {
|
|
|
449
457
|
.selectFrom("agents")
|
|
450
458
|
.select(["current_version", "deleted_at"])
|
|
451
459
|
.where("id", "=", conv.agent_id)
|
|
460
|
+
.where("org_id", "=", conv.org_id)
|
|
452
461
|
.executeTakeFirstOrThrow();
|
|
453
462
|
if (agent.deleted_at !== null)
|
|
454
463
|
return null;
|
|
@@ -489,7 +498,7 @@ let RunQueue = class RunQueue {
|
|
|
489
498
|
* `aborted`): a message that reached it while running and then stopped is parked, and the next
|
|
490
499
|
* run its parent starts absorbs it. Called under the sub-agent's row lock.
|
|
491
500
|
*/
|
|
492
|
-
async pendingMessageIn(conversationId, consumed, rootId) {
|
|
501
|
+
async pendingMessageIn(conversationId, consumed, rootId, orgId) {
|
|
493
502
|
const t = this.db;
|
|
494
503
|
const message = await t
|
|
495
504
|
.selectFrom("conversation_events")
|
|
@@ -506,6 +515,7 @@ let RunQueue = class RunQueue {
|
|
|
506
515
|
.selectFrom("conversations")
|
|
507
516
|
.select(["queue_paused", "deleted_at"])
|
|
508
517
|
.where("id", "=", rootId)
|
|
518
|
+
.where("org_id", "=", orgId)
|
|
509
519
|
.executeTakeFirst();
|
|
510
520
|
if (!root || root.queue_paused || !isLive(root.deleted_at))
|
|
511
521
|
return null;
|
|
@@ -538,6 +548,8 @@ let RunQueue = class RunQueue {
|
|
|
538
548
|
* before that call leaves no held wake behind. A root whose queue is still paused (or that is
|
|
539
549
|
* deleted) releases nothing and owes nothing.
|
|
540
550
|
*/
|
|
551
|
+
// org-filter: every caller (QueueService resume / remove / sendNow) checked
|
|
552
|
+
// writable(orgId, rootId, ...) first
|
|
541
553
|
async oweHeldTreeIn(rootId) {
|
|
542
554
|
const root = await this.db
|
|
543
555
|
.selectFrom("conversations")
|
|
@@ -555,6 +567,7 @@ let RunQueue = class RunQueue {
|
|
|
555
567
|
* unconsumed wake event (a finished background task, a delivery) or message, and no active run;
|
|
556
568
|
* with their org and newest seq. Reads only (no row locks).
|
|
557
569
|
*/
|
|
570
|
+
// org-filter: the sub-agents below a root the caller checked; each row's own org is returned
|
|
558
571
|
async heldTree(rootId) {
|
|
559
572
|
const ids = (await conversationTree(this.db, rootId))
|
|
560
573
|
.filter((c) => c.level > 0)
|
|
@@ -606,6 +619,8 @@ let RunQueue = class RunQueue {
|
|
|
606
619
|
await this.dropCheckpoints(runId);
|
|
607
620
|
return true;
|
|
608
621
|
}
|
|
622
|
+
// org-filter: callers checked the conversation in the org (ConversationsService.abort via get),
|
|
623
|
+
// stop a tree's kernel-resolved descendants, or pass an org offboarding job's kernel-written id
|
|
609
624
|
async abortOrphanIn(conversationId, runId, byAccountId, detail) {
|
|
610
625
|
const t = this.db;
|
|
611
626
|
const conv = await t
|
|
@@ -653,6 +668,8 @@ let RunQueue = class RunQueue {
|
|
|
653
668
|
await this.dropCheckpoints(runId);
|
|
654
669
|
return true;
|
|
655
670
|
}
|
|
671
|
+
// org-filter: callers checked the conversation in the org (ConversationsService.abort via get) or
|
|
672
|
+
// pass the kernel-written id of an org offboarding job
|
|
656
673
|
async abortQueuedIn(conversationId, runId, byAccountId) {
|
|
657
674
|
const t = this.db;
|
|
658
675
|
const conv = await t
|
|
@@ -766,6 +783,7 @@ async function authorCanSend(t, conversationId, accountId) {
|
|
|
766
783
|
.selectFrom("agents")
|
|
767
784
|
.select(sql `1`.as("one"))
|
|
768
785
|
.whereRef("agents.id", "=", "conversations.agent_id")
|
|
786
|
+
.whereRef("agents.org_id", "=", "conversations.org_id")
|
|
769
787
|
.where("agents.deleted_at", "is", null)
|
|
770
788
|
.where(visibleTo(accountId))),
|
|
771
789
|
]))
|
|
@@ -776,6 +794,7 @@ async function authorCanSend(t, conversationId, accountId) {
|
|
|
776
794
|
* Whether a person's stop of the root conversation holds its tree (`tree_stopped_at`, agent map
|
|
777
795
|
* spec §6): set by the stop, cleared when the root next starts a run.
|
|
778
796
|
*/
|
|
797
|
+
// org-filter: rootId is rootConversationOf a conversation the caller holds the row lock of
|
|
779
798
|
async function treeStopped(t, rootId) {
|
|
780
799
|
const root = await t
|
|
781
800
|
.selectFrom("conversations")
|
|
@@ -427,6 +427,7 @@ let RunWorker = class RunWorker {
|
|
|
427
427
|
if (run.status === "waiting")
|
|
428
428
|
return;
|
|
429
429
|
await this.hooks?.afterRunRead?.(runId, conversationId);
|
|
430
|
+
// org-filter: the run job's kernel-written conversation id; reads the conversation's own org
|
|
430
431
|
const conv = await this.db
|
|
431
432
|
.selectFrom("conversations")
|
|
432
433
|
.select(["org_id", "agent_id", "kind", "subagent_depth", "source", "account_id"])
|
|
@@ -799,6 +800,7 @@ let RunWorker = class RunWorker {
|
|
|
799
800
|
.selectFrom("conversations")
|
|
800
801
|
.select("consumed_seq")
|
|
801
802
|
.where("id", "=", conversationId)
|
|
803
|
+
.where("org_id", "=", conv.org_id)
|
|
802
804
|
.executeTakeFirstOrThrow();
|
|
803
805
|
const startConsumed = Number(consumed_seq);
|
|
804
806
|
let absorbed = startConsumed;
|
|
@@ -974,6 +976,7 @@ let RunWorker = class RunWorker {
|
|
|
974
976
|
.selectFrom("conversations")
|
|
975
977
|
.select("consumed_seq")
|
|
976
978
|
.where("id", "=", conversationId)
|
|
979
|
+
.where("org_id", "=", conv.org_id)
|
|
977
980
|
.executeTakeFirstOrThrow();
|
|
978
981
|
const ac = new AbortController();
|
|
979
982
|
let abortedBy;
|
|
@@ -1110,6 +1113,7 @@ let RunWorker = class RunWorker {
|
|
|
1110
1113
|
* (conversation, then run, as `RunFinish.finishIn`): the job read its status before taking the
|
|
1111
1114
|
* conversation lock, and a stop may have ended it since.
|
|
1112
1115
|
*/
|
|
1116
|
+
// org-filter: locks the conversation of the run this worker holds (kernel-written job id)
|
|
1113
1117
|
async endedUnderLocks(conversationId, runId) {
|
|
1114
1118
|
await this.db
|
|
1115
1119
|
.selectFrom("conversations")
|
|
@@ -1180,6 +1184,7 @@ let RunWorker = class RunWorker {
|
|
|
1180
1184
|
return { toSeq: ev?.seq, agent };
|
|
1181
1185
|
}
|
|
1182
1186
|
/** {@link fallBackIfUnavailable}'s write: null when the person switched again meanwhile. */
|
|
1187
|
+
// org-filter: the conversation of the run this worker holds (kernel-written job id)
|
|
1183
1188
|
async fallBackIn(conversationId, runId, sel) {
|
|
1184
1189
|
const t = this.db;
|
|
1185
1190
|
// re-check under the row lock: a person who switched again since the read above wins
|
package/dist/runtime/step-log.js
CHANGED
|
@@ -64,6 +64,7 @@ let StepLog = class StepLog {
|
|
|
64
64
|
async appendCounted(conversationId, counter, events) {
|
|
65
65
|
const t = this.kdb.db;
|
|
66
66
|
// the conversation row lock the append takes anyway, taken first to read the seq before it
|
|
67
|
+
// org-filter: a sub-agent run's own conversation (kernel-resolved by the run worker)
|
|
67
68
|
const before = await t
|
|
68
69
|
.selectFrom("conversations")
|
|
69
70
|
.select("last_seq")
|
|
@@ -79,6 +79,8 @@ export async function dispatchOfCall(db, runId, callId) {
|
|
|
79
79
|
* conversation without a parent); just `[conversationId]` for a root or an unknown id. Walks at
|
|
80
80
|
* most 16 levels, far above `subagents.maxDepth`'s bound of 5.
|
|
81
81
|
*/
|
|
82
|
+
// org-filter: walks parent links of a kernel-resolved conversation (a run's); a sub-agent
|
|
83
|
+
// conversation is always created in its parent's org
|
|
82
84
|
async function ancestryOf(db, conversationId) {
|
|
83
85
|
const chain = [conversationId];
|
|
84
86
|
for (let i = 0; i < 16; i++) {
|
|
@@ -66,6 +66,7 @@ let SubagentDeliveries = class SubagentDeliveries {
|
|
|
66
66
|
* the commit: the log's notify and `subagent.delivered`; the parent's ensure-run backstop is
|
|
67
67
|
* owed in the transaction. Returns the new event's seq.
|
|
68
68
|
*/
|
|
69
|
+
// org-filter: the dispatch row is kernel-written; its parent conversation's own org is read here
|
|
69
70
|
async deliverIn(row, d, opts = {}) {
|
|
70
71
|
const idemKey = opts.idemKey ?? (d.kind === "finished" ? finishedDeliveryIdemKey(row.childRunId) : undefined);
|
|
71
72
|
if (idemKey === undefined)
|
|
@@ -176,6 +177,7 @@ let SubagentDeliveries = class SubagentDeliveries {
|
|
|
176
177
|
* notify after the commit. No `subagent.delivered`: nothing model-visible arrived, so no wake.
|
|
177
178
|
* True when this call wrote it.
|
|
178
179
|
*/
|
|
180
|
+
// org-filter: locks the parent conversation of a kernel-written dispatch row
|
|
179
181
|
async finishSilentlyIn(row, finished) {
|
|
180
182
|
const parent = row.parentConversationId;
|
|
181
183
|
const event = finishedEvent(row, finished);
|
|
@@ -211,6 +213,7 @@ let SubagentDeliveries = class SubagentDeliveries {
|
|
|
211
213
|
const dispatched = await this.eventLog.findByIdem(row.parentConversationId, dispatchedIdemKey(row.parentRunId, row.parentCallId));
|
|
212
214
|
if (dispatched?.type === "subagent_dispatched")
|
|
213
215
|
return dispatched.payload.description;
|
|
216
|
+
// org-filter: the child conversation of a kernel-written dispatch row
|
|
214
217
|
const conv = await this.db
|
|
215
218
|
.selectFrom("conversations")
|
|
216
219
|
.select("title")
|
|
@@ -121,6 +121,7 @@ export async function dispatchSubagent(d, a) {
|
|
|
121
121
|
.selectFrom("conversations")
|
|
122
122
|
.select("account_id")
|
|
123
123
|
.where("id", "=", ctx.conversationId)
|
|
124
|
+
.where("org_id", "=", ctx.orgId)
|
|
124
125
|
.executeTakeFirstOrThrow();
|
|
125
126
|
await t
|
|
126
127
|
.insertInto("conversations")
|
|
@@ -185,7 +186,7 @@ export async function dispatchSubagent(d, a) {
|
|
|
185
186
|
*/
|
|
186
187
|
export async function orgAgentGates(db, a, agentId, agentType, resumed) {
|
|
187
188
|
const { ctx } = a;
|
|
188
|
-
const parentDefinition = (await currentAgentDefinition(db, ctx.agentId)) ?? {};
|
|
189
|
+
const parentDefinition = (await currentAgentDefinition(db, ctx.orgId, ctx.agentId)) ?? {};
|
|
189
190
|
const check = await checkOrgAgent(db, {
|
|
190
191
|
orgId: ctx.orgId,
|
|
191
192
|
parentDefinition,
|
|
@@ -276,6 +277,7 @@ export async function commitDispatchIn(d, a, plan, child) {
|
|
|
276
277
|
.selectFrom("conversations")
|
|
277
278
|
.select("id")
|
|
278
279
|
.where("id", "=", ctx.conversationId)
|
|
280
|
+
.where("org_id", "=", ctx.orgId)
|
|
279
281
|
.forUpdate()
|
|
280
282
|
.executeTakeFirst();
|
|
281
283
|
const parent = await t
|
|
@@ -353,6 +355,7 @@ export async function commitDispatchIn(d, a, plan, child) {
|
|
|
353
355
|
.selectFrom("agents")
|
|
354
356
|
.select("id")
|
|
355
357
|
.where("id", "in", [ctx.agentId, plan.agentId])
|
|
358
|
+
.where("org_id", "=", ctx.orgId)
|
|
356
359
|
.orderBy("id")
|
|
357
360
|
.forShare()
|
|
358
361
|
.execute();
|
|
@@ -545,6 +548,7 @@ async function limitRefusal(t, d, ctx, budgetRunId, tokensUsed, texts) {
|
|
|
545
548
|
.selectFrom("conversations as c")
|
|
546
549
|
.select(sql `count(*)`.as("n"))
|
|
547
550
|
.where("c.parent_conversation_id", "=", ctx.conversationId)
|
|
551
|
+
.where("c.org_id", "=", ctx.orgId)
|
|
548
552
|
.where("c.kind", "=", "subagent")
|
|
549
553
|
.where("c.deleted_at", "is", null)
|
|
550
554
|
.where(({ exists, selectFrom }) => exists(selectFrom("runs as cr")
|
|
@@ -202,6 +202,7 @@ let SubagentMessages = class SubagentMessages {
|
|
|
202
202
|
.selectFrom("conversations")
|
|
203
203
|
.select("id")
|
|
204
204
|
.where("id", "=", childId)
|
|
205
|
+
.where("org_id", "=", ctx.orgId)
|
|
205
206
|
.forUpdate()
|
|
206
207
|
.executeTakeFirst();
|
|
207
208
|
if ((await this.activeRunOf(childId)) === undefined)
|
|
@@ -254,6 +255,7 @@ let SubagentMessages = class SubagentMessages {
|
|
|
254
255
|
.selectFrom("conversations")
|
|
255
256
|
.select("id")
|
|
256
257
|
.where("id", "=", plan.childConversationId)
|
|
258
|
+
.where("org_id", "=", ctx.orgId)
|
|
257
259
|
.forUpdate()
|
|
258
260
|
.executeTakeFirst();
|
|
259
261
|
if (await activeRun())
|
|
@@ -32,7 +32,7 @@ export declare function checkOrgAgent(db: KernelSchemaDb, a: {
|
|
|
32
32
|
* The parent agent's current definition (the allowlist gate reads it, not the run's version), or
|
|
33
33
|
* null when the agent no longer exists or is deleted.
|
|
34
34
|
*/
|
|
35
|
-
export declare function currentAgentDefinition(db: KernelSchemaDb, agentId: string): Promise<AgentDefinition | null>;
|
|
35
|
+
export declare function currentAgentDefinition(db: KernelSchemaDb, orgId: string, agentId: string): Promise<AgentDefinition | null>;
|
|
36
36
|
/**
|
|
37
37
|
* Audits a refused org agent dispatch (`subagent.refused`, spec §5.5): actor the person who
|
|
38
38
|
* started the parent run, target the refused agent, so its owner can see attempts to use it.
|
|
@@ -35,7 +35,7 @@ export async function checkOrgAgent(db, a) {
|
|
|
35
35
|
* The parent agent's current definition (the allowlist gate reads it, not the run's version), or
|
|
36
36
|
* null when the agent no longer exists or is deleted.
|
|
37
37
|
*/
|
|
38
|
-
export async function currentAgentDefinition(db, agentId) {
|
|
38
|
+
export async function currentAgentDefinition(db, orgId, agentId) {
|
|
39
39
|
const row = await db
|
|
40
40
|
.selectFrom("agents")
|
|
41
41
|
.innerJoin("agent_versions", (j) => j
|
|
@@ -43,6 +43,7 @@ export async function currentAgentDefinition(db, agentId) {
|
|
|
43
43
|
.onRef("agent_versions.version", "=", "agents.current_version"))
|
|
44
44
|
.select("agent_versions.definition")
|
|
45
45
|
.where("agents.id", "=", agentId)
|
|
46
|
+
.where("agents.org_id", "=", orgId)
|
|
46
47
|
// a deleted parent agent's running run allowlists nothing (batch 9 review M2)
|
|
47
48
|
.where("agents.deleted_at", "is", null)
|
|
48
49
|
.executeTakeFirst();
|
|
@@ -51,6 +51,7 @@ let UsageReportJobs = class UsageReportJobs {
|
|
|
51
51
|
const usage = events.filter((e) => e.type === "usage");
|
|
52
52
|
if (usage.length === 0 || !(await this.subscribers.any()))
|
|
53
53
|
return;
|
|
54
|
+
// org-filter: reads the org of the conversation whose log this transaction just wrote
|
|
54
55
|
const conv = await this.kdb.db
|
|
55
56
|
.selectFrom("conversations")
|
|
56
57
|
.select("org_id")
|
|
@@ -238,6 +238,7 @@ let UsageReporter = class UsageReporter {
|
|
|
238
238
|
* and `usage.outputImages` when it produced any), else `embedding`; the calling extension, no
|
|
239
239
|
* conversation fields; `eventId` is the row id. Null when the row no longer exists.
|
|
240
240
|
*/
|
|
241
|
+
// org-filter: the usage job's kernel-written model_usage id; the row's own org is reported
|
|
241
242
|
async payloadOfUsage(id) {
|
|
242
243
|
const row = await this.db
|
|
243
244
|
.selectFrom("model_usage")
|
|
@@ -278,6 +279,7 @@ let UsageReporter = class UsageReporter {
|
|
|
278
279
|
};
|
|
279
280
|
}
|
|
280
281
|
/** A `model_usage` job is done (delivered, or nothing left to deliver to): marks the row. */
|
|
282
|
+
// org-filter: marks the model_usage row of a kernel-written usage job id
|
|
281
283
|
async markReported(data) {
|
|
282
284
|
if (data.usageId === undefined)
|
|
283
285
|
return;
|
|
@@ -289,6 +291,7 @@ let UsageReporter = class UsageReporter {
|
|
|
289
291
|
.execute();
|
|
290
292
|
}
|
|
291
293
|
/** A `model_usage` job gave up after its last attempt: the row records it. */
|
|
294
|
+
// org-filter: marks the model_usage row of a kernel-written usage job id
|
|
292
295
|
async markFailed(data) {
|
|
293
296
|
if (data.usageId === undefined)
|
|
294
297
|
return;
|
package/dist/runtime/waits.js
CHANGED
|
@@ -185,6 +185,8 @@ let Waits = class Waits {
|
|
|
185
185
|
* Not a run of a sub-agent, or a `subagents` wait: nothing. Display only: a failure is logged,
|
|
186
186
|
* the wait goes on.
|
|
187
187
|
*/
|
|
188
|
+
// org-filter: the wait's approval / question id was written by this run's own suspend (kernel
|
|
189
|
+
// state, not caller input)
|
|
188
190
|
async surfaceInRoot(runId, conversationId, waitingFor) {
|
|
189
191
|
if (waitingFor.kind === "subagents")
|
|
190
192
|
return;
|
|
@@ -308,6 +310,8 @@ let Waits = class Waits {
|
|
|
308
310
|
return true;
|
|
309
311
|
}
|
|
310
312
|
/** {@link abortWaiting}'s transaction; the open `Agent` calls it wrote go back through `st`. */
|
|
313
|
+
// org-filter: stops a run by kernel-resolved ids (ConversationsService.abort checked the org, or
|
|
314
|
+
// a tree stop / timeout / offboarding job); wait rows are read by that run's id
|
|
311
315
|
async abortWaitingIn(conversationId, runId, byAccountId, detail, st) {
|
|
312
316
|
const t = this.db;
|
|
313
317
|
await t
|
|
@@ -428,6 +432,7 @@ let Waits = class Waits {
|
|
|
428
432
|
* Whether the wait is over: an approval or input request is no longer pending (decided, expired
|
|
429
433
|
* or cancelled); `subagents`: the run's fork invocation child is no longer active.
|
|
430
434
|
*/
|
|
435
|
+
// org-filter: the wait's approval / question id was written by this run's own suspend
|
|
431
436
|
async isSettled(w, runId) {
|
|
432
437
|
if (w.kind === "subagents") {
|
|
433
438
|
const active = await this.db
|
|
@@ -175,6 +175,8 @@ let CloudPermissionSnapshots = class CloudPermissionSnapshots {
|
|
|
175
175
|
}
|
|
176
176
|
/** {@link reconcile} by device id alone (after a file reset); nothing for an unknown device. */
|
|
177
177
|
async reconcileDevice(deviceId) {
|
|
178
|
+
// org-filter: reads the device's own org to scope the reconcile; the id comes from the
|
|
179
|
+
// kernel-enqueued reset-files job, not caller input
|
|
178
180
|
const row = await this.db
|
|
179
181
|
.selectFrom("devices")
|
|
180
182
|
.select(["org_id", "permission_reconcile_required"])
|
|
@@ -210,7 +212,7 @@ let CloudPermissionSnapshots = class CloudPermissionSnapshots {
|
|
|
210
212
|
]);
|
|
211
213
|
// the OLD algorithm on the old inputs: the snapshot columns are still empty here
|
|
212
214
|
const old = effectiveDevicePolicy(deployment, settings, cloudChosenMode(device));
|
|
213
|
-
const instance = await this.lockedInstance(deviceId);
|
|
215
|
+
const instance = await this.lockedInstance(orgId, deviceId);
|
|
214
216
|
const rec = instance === null ? null : readInstanceLimits(instance.instance_limits);
|
|
215
217
|
// what the instance really runs narrows the snapshot even when a newer value is pending
|
|
216
218
|
const known = rec?.applied ?? null;
|
|
@@ -237,6 +239,7 @@ let CloudPermissionSnapshots = class CloudPermissionSnapshots {
|
|
|
237
239
|
permission_reconcile_required: state === "reconcile-required",
|
|
238
240
|
})
|
|
239
241
|
.where("id", "=", deviceId)
|
|
242
|
+
.where("org_id", "=", orgId)
|
|
240
243
|
.execute();
|
|
241
244
|
// A snapshot narrowed by what the instance really runs changes the device's authority: it
|
|
242
245
|
// goes through the device ceiling writer (epoch, Full consent, exact revocation) in this
|
|
@@ -284,7 +287,7 @@ let CloudPermissionSnapshots = class CloudPermissionSnapshots {
|
|
|
284
287
|
return { state: "skipped" };
|
|
285
288
|
if (!device.permission_reconcile_required)
|
|
286
289
|
return { state: "existing" };
|
|
287
|
-
const instance = await this.lockedInstance(deviceId);
|
|
290
|
+
const instance = await this.lockedInstance(orgId, deviceId);
|
|
288
291
|
let state = "unprobed";
|
|
289
292
|
let target;
|
|
290
293
|
if (instance !== null) {
|
|
@@ -310,6 +313,7 @@ let CloudPermissionSnapshots = class CloudPermissionSnapshots {
|
|
|
310
313
|
...ownNetworkOf(narrowed.outerNetwork),
|
|
311
314
|
})
|
|
312
315
|
.where("id", "=", deviceId)
|
|
316
|
+
.where("org_id", "=", orgId)
|
|
313
317
|
.execute();
|
|
314
318
|
await this.publishNarrowing(orgId, deviceId, narrowed, fullNarrowed);
|
|
315
319
|
}
|
|
@@ -326,6 +330,7 @@ let CloudPermissionSnapshots = class CloudPermissionSnapshots {
|
|
|
326
330
|
.updateTable("devices")
|
|
327
331
|
.set({ permission_reconcile_required: false })
|
|
328
332
|
.where("id", "=", deviceId)
|
|
333
|
+
.where("org_id", "=", orgId)
|
|
329
334
|
.execute();
|
|
330
335
|
return state === "reconcile-required"
|
|
331
336
|
? { state, action: "reset-files", ...(target !== undefined && { target }) }
|
|
@@ -374,11 +379,12 @@ let CloudPermissionSnapshots = class CloudPermissionSnapshots {
|
|
|
374
379
|
* The device's instance row when an instance or a file system exists (their limits are in
|
|
375
380
|
* force); null when neither does (the next create applies the desired limits exactly).
|
|
376
381
|
*/
|
|
377
|
-
async lockedInstance(deviceId) {
|
|
382
|
+
async lockedInstance(orgId, deviceId) {
|
|
378
383
|
const row = await this.db
|
|
379
384
|
.selectFrom("device_instances")
|
|
380
385
|
.select(["handle", "status", "fs_status", "instance_limits", "generation"])
|
|
381
386
|
.where("device_id", "=", deviceId)
|
|
387
|
+
.where("org_id", "=", orgId)
|
|
382
388
|
.forUpdate()
|
|
383
389
|
.executeTakeFirst();
|
|
384
390
|
if (row === undefined)
|