@opengeni/db 0.36.0 → 1.0.1
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/dist/canonical-human-identities.js +3 -3
- package/dist/{chunk-P3RE4D2B.js → chunk-4SR4HKKA.js} +2 -2
- package/dist/{chunk-5KTIEDX7.js → chunk-6ZYKCRFO.js} +124 -16
- package/dist/chunk-6ZYKCRFO.js.map +1 -0
- package/dist/{chunk-CQZ4QSP5.js → chunk-CUPM3FGB.js} +3 -3
- package/dist/{chunk-TAUTWOS5.js → chunk-LTG3S6ZY.js} +2 -2
- package/dist/{chunk-VKLB2ZGI.js → chunk-NXAFLCQX.js} +81 -2
- package/dist/chunk-NXAFLCQX.js.map +1 -0
- package/dist/{chunk-F32YT7MP.js → chunk-WD5ROSLL.js} +2 -2
- package/dist/{chunk-JC5QPLUM.js → chunk-ZWREYEWA.js} +48 -3
- package/dist/chunk-ZWREYEWA.js.map +1 -0
- package/dist/editable-artifact-durable-export.d.ts +10 -0
- package/dist/editable-artifact-durable-export.js +18 -3
- package/dist/editable-artifact-durable-export.js.map +1 -1
- package/dist/editable-artifacts.js +3 -3
- package/dist/index.d.ts +69 -8
- package/dist/index.js +869 -75
- package/dist/index.js.map +1 -1
- package/dist/knowledge-source-sync-schema.d.ts +730 -0
- package/dist/knowledge-source-sync.d.ts +60 -0
- package/dist/persistence-errors.d.ts +8 -0
- package/dist/provision-roles.js +1 -1
- package/dist/runtime-posture.d.ts +3 -3
- package/dist/schema.d.ts +21 -4
- package/dist/schema.js +5 -1
- package/dist/session-queue-commands.d.ts +1 -1
- package/dist/session-realtime-ledger.d.ts +1 -0
- package/dist/session-tenancy.js +3 -3
- package/dist/video-generation.js +3 -3
- package/drizzle/0238_recover_unclaimed_session_turns.sql +307 -0
- package/drizzle/0240_model_context_user_messages.sql +204 -0
- package/drizzle/0243_google_drive_object_acl_authority.sql +554 -0
- package/package.json +5 -5
- package/src/editable-artifact-durable-export.ts +27 -0
- package/src/index.ts +680 -30
- package/src/knowledge-source-sync-schema.ts +83 -0
- package/src/knowledge-source-sync.ts +530 -0
- package/src/persistence-errors.ts +60 -1
- package/src/provision-roles.ts +36 -0
- package/src/runtime-posture.ts +49 -1
- package/src/schema.ts +30 -7
- package/src/session-queue-commands.ts +13 -14
- package/src/session-realtime-context.ts +16 -0
- package/src/session-realtime-ledger.ts +53 -1
- package/dist/chunk-5KTIEDX7.js.map +0 -1
- package/dist/chunk-JC5QPLUM.js.map +0 -1
- package/dist/chunk-VKLB2ZGI.js.map +0 -1
- /package/dist/{chunk-P3RE4D2B.js.map → chunk-4SR4HKKA.js.map} +0 -0
- /package/dist/{chunk-CQZ4QSP5.js.map → chunk-CUPM3FGB.js.map} +0 -0
- /package/dist/{chunk-TAUTWOS5.js.map → chunk-LTG3S6ZY.js.map} +0 -0
- /package/dist/{chunk-F32YT7MP.js.map → chunk-WD5ROSLL.js.map} +0 -0
|
@@ -30,6 +30,38 @@ export type KnowledgeSourceSyncObservationFence = {
|
|
|
30
30
|
executionCheckpointGeneration: number;
|
|
31
31
|
observations: KnowledgeSourceSyncObservationFloor[];
|
|
32
32
|
};
|
|
33
|
+
export type GoogleDriveObjectAclPrincipal = {
|
|
34
|
+
type: "user" | "group" | "domain" | "anyone";
|
|
35
|
+
permissionId?: string | null;
|
|
36
|
+
emailAddress?: string | null;
|
|
37
|
+
domain?: string | null;
|
|
38
|
+
role: "owner" | "organizer" | "fileOrganizer" | "writer" | "commenter" | "reader";
|
|
39
|
+
inherited?: boolean;
|
|
40
|
+
allowFileDiscovery?: boolean | null;
|
|
41
|
+
expirationTime?: string | null;
|
|
42
|
+
};
|
|
43
|
+
export type GoogleDriveObjectAclEvidenceInput = {
|
|
44
|
+
accountId: string;
|
|
45
|
+
workspaceId: string;
|
|
46
|
+
obligationId: string;
|
|
47
|
+
connectionId: string;
|
|
48
|
+
connectionVersion: number;
|
|
49
|
+
sourceGooglePermissionId: string;
|
|
50
|
+
sourceSyncGeneration: number;
|
|
51
|
+
sourceConfigGeneration: number;
|
|
52
|
+
sourceLifecycleGeneration: number;
|
|
53
|
+
objectLifecycleGeneration: number;
|
|
54
|
+
objectVersionGeneration: number;
|
|
55
|
+
providerRevision: string | null;
|
|
56
|
+
driveId: string | null;
|
|
57
|
+
aclRevision: string;
|
|
58
|
+
eligibility: "eligible" | "denied";
|
|
59
|
+
observedAt: string;
|
|
60
|
+
expiresAt: string;
|
|
61
|
+
citationLocator: Record<string, unknown>;
|
|
62
|
+
operationId: string;
|
|
63
|
+
principals: GoogleDriveObjectAclPrincipal[];
|
|
64
|
+
};
|
|
33
65
|
export type KnowledgeSourceSyncObjectObservationResult = KnowledgeSourceSyncObservationFloor & {
|
|
34
66
|
disposition: "accepted" | "replayed" | "stale" | "conflict";
|
|
35
67
|
currentVersion: {
|
|
@@ -241,6 +273,34 @@ export declare function recordKnowledgeSourceSyncAclEvidence(db: Database, input
|
|
|
241
273
|
eligibility: "eligible" | "denied";
|
|
242
274
|
evidence: Record<string, unknown>;
|
|
243
275
|
}): Promise<void>;
|
|
276
|
+
/**
|
|
277
|
+
* Persist one append-only Google Drive object ACL observation and atomically
|
|
278
|
+
* make it the current authorization pointer for the exact index obligation.
|
|
279
|
+
* Raw provider principals never enter storage: only domain-separated hashes
|
|
280
|
+
* are retained. Denial deletes chunks in the same transaction so stale vector
|
|
281
|
+
* or keyword rows cannot survive permission loss.
|
|
282
|
+
*/
|
|
283
|
+
export declare function recordGoogleDriveObjectAclEvidence(db: Database, input: GoogleDriveObjectAclEvidenceInput): Promise<{
|
|
284
|
+
evidenceId: string;
|
|
285
|
+
aclHash: string;
|
|
286
|
+
}>;
|
|
287
|
+
/**
|
|
288
|
+
* Clear the current Drive authorization pointer before provider I/O without
|
|
289
|
+
* destroying an otherwise valid index. All read surfaces immediately deny
|
|
290
|
+
* because agent_access is false and the current evidence pointer is null. A
|
|
291
|
+
* successful refresh can restore access without re-embedding; a final denied
|
|
292
|
+
* observation uses recordGoogleDriveObjectAclEvidence and deletes chunks.
|
|
293
|
+
*/
|
|
294
|
+
export declare function beginGoogleDriveObjectAclRefresh(db: Database, input: {
|
|
295
|
+
accountId: string;
|
|
296
|
+
workspaceId: string;
|
|
297
|
+
obligationId: string;
|
|
298
|
+
sourceSyncGeneration: number;
|
|
299
|
+
sourceConfigGeneration: number;
|
|
300
|
+
sourceLifecycleGeneration: number;
|
|
301
|
+
objectLifecycleGeneration: number;
|
|
302
|
+
objectVersionGeneration: number;
|
|
303
|
+
}): Promise<void>;
|
|
244
304
|
/** Bounded retention hook. Callers choose policy and cadence; pending index or
|
|
245
305
|
* ACL obligations are never deleted by age alone. */
|
|
246
306
|
export declare function pruneKnowledgeSourceSyncEvidence(db: Database, input: {
|
|
@@ -23,6 +23,14 @@ export type PersistenceFailureDetails = {
|
|
|
23
23
|
export declare function nestedPostgresSqlState(error: unknown): string | null;
|
|
24
24
|
export declare function databaseFailureCode(sqlState: string | null): DatabaseFailureCode;
|
|
25
25
|
export declare function isRetryablePersistenceSqlState(sqlState: string | null): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Recognize only explicit postgres.js/Node transport codes, including nested
|
|
28
|
+
* driver causes. These failures can arrive as plain Errors with no SQLSTATE or
|
|
29
|
+
* database diagnostic fields when the connection dies before PostgreSQL can
|
|
30
|
+
* answer. Messages are intentionally ignored: they are unstable and may
|
|
31
|
+
* contain connection detail.
|
|
32
|
+
*/
|
|
33
|
+
export declare function isRetryableDatabaseTransportFailure(error: unknown): boolean;
|
|
26
34
|
/**
|
|
27
35
|
* Distinguish database/ORM failures from expected domain exceptions when a
|
|
28
36
|
* driver omitted SQLSTATE. This checks shape only; callers retain the original
|
package/dist/provision-roles.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { Database, RlsStrategy } from "./database.js";
|
|
2
|
-
export declare const RUNTIME_TARGET_SCHEMA_CAPABILITY_ROUTINES: readonly ["fork_session_content(uuid, uuid, uuid, text, uuid, text, text, text)", "xai_subscription_authority_live(uuid, uuid, text, uuid, text, uuid, uuid, bigint)", "create_xai_subscription_credential(uuid, uuid, text, text, text, text, text, text, text, timestamp with time zone)", "disconnect_xai_subscription_credential(uuid, uuid, text, uuid, jsonb)", "knowledge_source_sync_lock_authority(uuid, uuid, uuid)", "ensure_managed_human_personal_workspace(uuid, text, uuid)", "ensure_canonical_human_identity(text, text)", "validate_canonical_human_session(text, text, boolean)", "get_canonical_human_identity_projection(text)", "apply_canonical_human_identity_operation(uuid, text, bigint, text, uuid, text, text, text)", "session_private_actor_visible(uuid, uuid, uuid, text)", "session_reference_visible(uuid, uuid, uuid)", "transition_session_visibility(uuid, uuid, uuid, text, text, integer, text, text)", "xai_subscription_pool_visible(uuid, uuid, text, text, uuid)", "resolve_xai_authority_pool(uuid, uuid, text, jsonb)", "revalidate_xai_subscription_authority(uuid, text, uuid, jsonb)", "xai_provider_account_authority_snapshot_v1_valid(jsonb)"];
|
|
2
|
+
export declare const RUNTIME_TARGET_SCHEMA_CAPABILITY_ROUTINES: readonly ["fork_session_content(uuid, uuid, uuid, text, uuid, text, text, text)", "xai_subscription_authority_live(uuid, uuid, text, uuid, text, uuid, uuid, bigint)", "create_xai_subscription_credential(uuid, uuid, text, text, text, text, text, text, text, timestamp with time zone)", "disconnect_xai_subscription_credential(uuid, uuid, text, uuid, jsonb)", "google_drive_document_citation(uuid, uuid, text, uuid, uuid)", "google_drive_file_authorized(uuid, uuid, text, uuid)", "knowledge_source_sync_lock_authority(uuid, uuid, uuid)", "ensure_managed_human_personal_workspace(uuid, text, uuid)", "ensure_canonical_human_identity(text, text)", "validate_canonical_human_session(text, text, boolean)", "get_canonical_human_identity_projection(text)", "apply_canonical_human_identity_operation(uuid, text, bigint, text, uuid, text, text, text)", "session_private_actor_visible(uuid, uuid, uuid, text)", "session_reference_visible(uuid, uuid, uuid)", "transition_session_visibility(uuid, uuid, uuid, text, text, integer, text, text)", "xai_subscription_pool_visible(uuid, uuid, text, text, uuid)", "resolve_xai_authority_pool(uuid, uuid, text, jsonb)", "revalidate_xai_subscription_authority(uuid, text, uuid, jsonb)", "xai_provider_account_authority_snapshot_v1_valid(jsonb)"];
|
|
3
3
|
export declare const RUNTIME_TARGET_SCHEMA_INVOKER_ROUTINES: readonly ["session_reference_visible(uuid, uuid, uuid)", "xai_provider_account_authority_snapshot_v1_valid(jsonb)"];
|
|
4
4
|
/**
|
|
5
5
|
* The complete standalone tenant-table contract. Adding or removing a
|
|
6
6
|
* FORCE-RLS table is an architectural change: update this list in the same
|
|
7
7
|
* commit as the migration so startup cannot silently accept an unreviewed gap.
|
|
8
8
|
*/
|
|
9
|
-
export declare const FORCE_RLS_TABLES: readonly ["agent_run_states", "api_keys", "attached_browser_devices", "attached_browser_inventories", "audit_events", "auth_runs", "billing_customers", "browser_identities", "browser_revision_components", "browser_revisions", "browser_session_associations", "browser_sessions", "browser_state_artifacts", "browser_state_uploads", "canonical_human_identities", "canonical_human_identity_operations", "canonical_human_identity_subjects", "canonical_human_login_bindings", "capability_api_facets", "capability_catalog_items", "capability_component_owners", "capability_facet_installations", "capability_facets", "capability_installations", "capability_integration_facets", "capability_mcp_facets", "capability_operations", "capability_plugin_installations", "capability_plugin_versions", "capability_plugins", "capability_skill_facets", "capability_skill_files", "channels", "codex_apps_settings", "codex_capacity_waiters", "codex_credential_leases", "codex_reset_redemption_attempts", "codex_rotation_settings", "codex_subscription_credentials", "company_profile_activation_events", "company_profile_heads", "company_profile_revisions", "company_profile_snapshots", "composer_drafts", "computer_session_associations", "computer_sessions", "connection_disconnect_operations", "connections", "connector_action_policies", "connector_action_requests", "credit_ledger_entries", "device_enrollment_requests", "document_bases", "document_chunks", "documents", "editable_artifact_blob_refs", "editable_artifact_idempotency_receipts", "editable_artifact_live_outbox", "editable_artifact_live_tickets", "editable_artifact_materialization_jobs", "editable_artifact_materialization_results", "editable_artifact_operations", "editable_artifact_replica_leases", "editable_artifact_scope_authorization_heads", "editable_artifact_sequence_checkpoints", "editable_artifact_session_links", "editable_artifact_snapshots", "editable_artifact_transactions", "editable_artifact_undo_claims", "editable_artifact_versions", "editable_artifacts", "enrollments", "file_uploads", "files", "generated_image_artifacts", "generated_video_artifacts", "github_installation_repositories", "github_installations", "host_export_config", "host_export_consumers", "host_export_cursor_state", "host_export_dead_letters", "host_export_outbox", "image_generation_operations", "import_batches", "integration_facet_binding_owners", "integration_facet_bindings", "integration_facet_definitions", "integration_oauth_state_nonces", "integration_spec_revisions", "integration_tools", "interaction_interventions", "interaction_operations", "interaction_resource_operations", "knowledge_change_proposals", "knowledge_claim_evidence", "knowledge_claim_relations", "knowledge_claim_reviews", "knowledge_claims", "knowledge_document_versions", "knowledge_entities", "knowledge_entity_aliases", "knowledge_facts", "knowledge_lifecycle_events", "knowledge_memories", "knowledge_memory_lifecycle_events", "knowledge_memory_relationships", "knowledge_operation_receipts", "knowledge_providers", "knowledge_source_acl_versions", "knowledge_source_objects", "knowledge_source_sync_index_obligations", "knowledge_source_sync_item_outcomes", "knowledge_source_sync_object_observations", "knowledge_source_sync_states", "knowledge_source_sync_wakes", "knowledge_sources", "knowledge_sync_runs", "machine_metrics_latest", "machine_metrics_series", "machine_removal_operations", "memory_slack_publication_configurations", "memory_slack_publication_receipts", "memory_slack_publications", "model_call_facts", "network_routes", "new_session_drafts", "organization_memberships", "organization_user_resource_authorities", "organization_user_resource_grants", "organization_user_retention_policies", "pack_installation_components", "pack_installations", "preference_registry_events", "preference_registry_preferences", "preference_registry_revisions", "preference_registry_snapshots", "retained_screenshot_artifacts", "rig_changes", "rig_versions", "rigs", "sandbox_checkpoint_artifacts", "sandbox_lease_holders", "sandbox_leases", "sandbox_pty_sessions", "sandbox_retained_processes", "sandbox_session_envelopes", "sandbox_workspace_mutation_admissions", "sandboxes", "scheduled_task_runs", "scheduled_tasks", "session_attempt_codemode_calls", "session_attempt_interruptions", "session_attempt_tool_catalogs", "session_command_receipts", "session_events", "session_goal_revisions", "session_goals", "session_history_items", "session_human_input_requests", "session_list_snapshots", "session_mcp_servers", "session_pending_tool_calls", "session_pins", "session_realtime_connections", "session_realtime_context_projections", "session_realtime_entries", "session_realtime_modes", "session_recordings", "session_spawn_denials", "session_stream_acknowledgments", "session_system_update_outbox", "session_system_updates", "session_turn_attempts", "session_turns", "session_visibility_write_capabilities", "session_workflow_wake_outbox", "sessions", "site_auth_connections", "slack_bot_delete_operations", "slack_bot_post_operations", "slack_bot_update_operations", "slack_bot_user_links", "slack_installation_bindings", "slack_interaction_action_handles", "slack_interaction_inbox", "slack_interaction_progress_deliveries", "slack_interactions", "slack_shared_task_origins", "slack_task_policy_activation_events", "slack_task_policy_heads", "slack_task_policy_revisions", "slack_user_link_access_request_operations", "slack_user_link_access_requests", "social_connections", "social_posts", "task_note_events", "task_note_write_capabilities", "task_notes", "temporal_schedule_cleanup_outbox", "transcription_recording_chunks", "transcription_recording_objects", "transcription_recording_segments", "transcription_recordings", "usage_events", "video_generation_operations", "video_generation_references", "workspace_artifact_events", "workspace_artifact_versions", "workspace_artifacts", "workspace_captures", "workspace_control_events", "workspace_inference_controls", "workspace_instruction_policy_activation_events", "workspace_instruction_policy_heads", "workspace_instruction_policy_onboarding_proposals", "workspace_instruction_policy_revisions", "workspace_instruction_policy_snapshots", "workspace_interaction_revisions", "workspace_learning_policy_activation_events", "workspace_learning_policy_heads", "workspace_learning_policy_revisions", "workspace_learning_policy_snapshots", "workspace_model_policies", "workspace_packs", "workspace_screenshot_quotas", "workspace_session_activity_revisions", "workspace_variable_set_variables", "workspace_variable_sets", "workspace_video_generation_policies", "workspace_video_generation_quotas", "xai_capacity_waiters", "xai_credential_leases", "xai_rotation_settings", "xai_session_account_pins", "xai_subscription_credentials"];
|
|
9
|
+
export declare const FORCE_RLS_TABLES: readonly ["agent_run_states", "api_keys", "attached_browser_devices", "attached_browser_inventories", "audit_events", "auth_runs", "billing_customers", "browser_identities", "browser_revision_components", "browser_revisions", "browser_session_associations", "browser_sessions", "browser_state_artifacts", "browser_state_uploads", "canonical_human_identities", "canonical_human_identity_operations", "canonical_human_identity_subjects", "canonical_human_login_bindings", "capability_api_facets", "capability_catalog_items", "capability_component_owners", "capability_facet_installations", "capability_facets", "capability_installations", "capability_integration_facets", "capability_mcp_facets", "capability_operations", "capability_plugin_installations", "capability_plugin_versions", "capability_plugins", "capability_skill_facets", "capability_skill_files", "channels", "codex_apps_settings", "codex_capacity_waiters", "codex_credential_leases", "codex_reset_redemption_attempts", "codex_rotation_settings", "codex_subscription_credentials", "company_profile_activation_events", "company_profile_heads", "company_profile_revisions", "company_profile_snapshots", "composer_drafts", "computer_session_associations", "computer_sessions", "connection_disconnect_operations", "connections", "connector_action_policies", "connector_action_requests", "credit_ledger_entries", "device_enrollment_requests", "document_bases", "document_chunks", "documents", "editable_artifact_blob_refs", "editable_artifact_idempotency_receipts", "editable_artifact_live_outbox", "editable_artifact_live_tickets", "editable_artifact_materialization_jobs", "editable_artifact_materialization_results", "editable_artifact_operations", "editable_artifact_replica_leases", "editable_artifact_scope_authorization_heads", "editable_artifact_sequence_checkpoints", "editable_artifact_session_links", "editable_artifact_snapshots", "editable_artifact_transactions", "editable_artifact_undo_claims", "editable_artifact_versions", "editable_artifacts", "enrollments", "file_uploads", "files", "generated_image_artifacts", "generated_video_artifacts", "github_installation_repositories", "github_installations", "google_drive_object_acl_evidence", "google_drive_object_acl_principals", "host_export_config", "host_export_consumers", "host_export_cursor_state", "host_export_dead_letters", "host_export_outbox", "image_generation_operations", "import_batches", "integration_facet_binding_owners", "integration_facet_bindings", "integration_facet_definitions", "integration_oauth_state_nonces", "integration_spec_revisions", "integration_tools", "interaction_interventions", "interaction_operations", "interaction_resource_operations", "knowledge_change_proposals", "knowledge_claim_evidence", "knowledge_claim_relations", "knowledge_claim_reviews", "knowledge_claims", "knowledge_document_versions", "knowledge_entities", "knowledge_entity_aliases", "knowledge_facts", "knowledge_lifecycle_events", "knowledge_memories", "knowledge_memory_lifecycle_events", "knowledge_memory_relationships", "knowledge_operation_receipts", "knowledge_providers", "knowledge_source_acl_versions", "knowledge_source_objects", "knowledge_source_sync_index_obligations", "knowledge_source_sync_item_outcomes", "knowledge_source_sync_object_observations", "knowledge_source_sync_states", "knowledge_source_sync_wakes", "knowledge_sources", "knowledge_sync_runs", "machine_metrics_latest", "machine_metrics_series", "machine_removal_operations", "memory_slack_publication_configurations", "memory_slack_publication_receipts", "memory_slack_publications", "model_call_facts", "network_routes", "new_session_drafts", "organization_memberships", "organization_user_resource_authorities", "organization_user_resource_grants", "organization_user_retention_policies", "pack_installation_components", "pack_installations", "preference_registry_events", "preference_registry_preferences", "preference_registry_revisions", "preference_registry_snapshots", "retained_screenshot_artifacts", "rig_changes", "rig_versions", "rigs", "sandbox_checkpoint_artifacts", "sandbox_lease_holders", "sandbox_leases", "sandbox_pty_sessions", "sandbox_retained_processes", "sandbox_session_envelopes", "sandbox_workspace_mutation_admissions", "sandboxes", "scheduled_task_runs", "scheduled_tasks", "session_attempt_codemode_calls", "session_attempt_interruptions", "session_attempt_tool_catalogs", "session_command_receipts", "session_events", "session_goal_revisions", "session_goals", "session_history_items", "session_human_input_requests", "session_list_snapshots", "session_mcp_servers", "session_pending_tool_calls", "session_pins", "session_realtime_connections", "session_realtime_context_projections", "session_realtime_entries", "session_realtime_modes", "session_recordings", "session_spawn_denials", "session_stream_acknowledgments", "session_system_update_outbox", "session_system_updates", "session_turn_attempts", "session_turns", "session_visibility_write_capabilities", "session_workflow_wake_outbox", "sessions", "site_auth_connections", "slack_bot_delete_operations", "slack_bot_post_operations", "slack_bot_update_operations", "slack_bot_user_links", "slack_installation_bindings", "slack_interaction_action_handles", "slack_interaction_inbox", "slack_interaction_progress_deliveries", "slack_interactions", "slack_shared_task_origins", "slack_task_policy_activation_events", "slack_task_policy_heads", "slack_task_policy_revisions", "slack_user_link_access_request_operations", "slack_user_link_access_requests", "social_connections", "social_posts", "task_note_events", "task_note_write_capabilities", "task_notes", "temporal_schedule_cleanup_outbox", "transcription_recording_chunks", "transcription_recording_objects", "transcription_recording_segments", "transcription_recordings", "usage_events", "video_generation_operations", "video_generation_references", "workspace_artifact_events", "workspace_artifact_versions", "workspace_artifacts", "workspace_captures", "workspace_control_events", "workspace_inference_controls", "workspace_instruction_policy_activation_events", "workspace_instruction_policy_heads", "workspace_instruction_policy_onboarding_proposals", "workspace_instruction_policy_revisions", "workspace_instruction_policy_snapshots", "workspace_interaction_revisions", "workspace_learning_policy_activation_events", "workspace_learning_policy_heads", "workspace_learning_policy_revisions", "workspace_learning_policy_snapshots", "workspace_model_policies", "workspace_packs", "workspace_screenshot_quotas", "workspace_session_activity_revisions", "workspace_variable_set_variables", "workspace_variable_sets", "workspace_video_generation_policies", "workspace_video_generation_quotas", "xai_capacity_waiters", "xai_credential_leases", "xai_rotation_settings", "xai_session_account_pins", "xai_subscription_credentials"];
|
|
10
10
|
/**
|
|
11
11
|
* Deployment-global and authentication tables used by ordinary API/worker
|
|
12
12
|
* traffic. They intentionally do not carry workspace RLS: their access model
|
|
@@ -24,7 +24,7 @@ export declare const RUNTIME_READ_ONLY_TABLES: readonly ["company_profile_activa
|
|
|
24
24
|
/** Existing runtime authorities that may be observed and advanced, never created or deleted. */
|
|
25
25
|
export declare const RUNTIME_READ_UPDATE_TABLES: readonly ["workspace_session_activity_revisions"];
|
|
26
26
|
/** Append-only evidence/revision tables are insertable and queryable, never mutable. */
|
|
27
|
-
export declare const RUNTIME_READ_INSERT_TABLES: readonly ["browser_revision_components", "browser_revisions", "company_profile_revisions", "editable_artifact_blob_refs", "editable_artifact_idempotency_receipts", "editable_artifact_live_outbox", "editable_artifact_materialization_jobs", "editable_artifact_materialization_results", "editable_artifact_operations", "editable_artifact_sequence_checkpoints", "editable_artifact_snapshots", "editable_artifact_transactions", "editable_artifact_undo_claims", "editable_artifact_versions", "knowledge_change_proposals", "knowledge_claim_evidence", "knowledge_claim_relations", "knowledge_claim_reviews", "knowledge_claims", "knowledge_document_versions", "knowledge_entities", "knowledge_entity_aliases", "knowledge_facts", "knowledge_operation_receipts", "knowledge_providers", "knowledge_source_acl_versions", "knowledge_source_objects", "knowledge_sources", "knowledge_sync_runs", "preference_registry_preferences", "preference_registry_revisions", "session_attempt_tool_catalogs", "session_goal_revisions", "session_spawn_denials", "slack_shared_task_origins", "slack_user_link_access_request_operations", "temporal_schedule_cleanup_outbox", "workspace_artifact_events", "workspace_artifact_versions", "workspace_instruction_policy_activation_events", "workspace_instruction_policy_onboarding_proposals", "workspace_instruction_policy_revisions", "workspace_learning_policy_revisions"];
|
|
27
|
+
export declare const RUNTIME_READ_INSERT_TABLES: readonly ["browser_revision_components", "browser_revisions", "company_profile_revisions", "editable_artifact_blob_refs", "editable_artifact_idempotency_receipts", "editable_artifact_live_outbox", "editable_artifact_materialization_jobs", "editable_artifact_materialization_results", "editable_artifact_operations", "editable_artifact_sequence_checkpoints", "editable_artifact_snapshots", "editable_artifact_transactions", "editable_artifact_undo_claims", "editable_artifact_versions", "google_drive_object_acl_evidence", "google_drive_object_acl_principals", "knowledge_change_proposals", "knowledge_claim_evidence", "knowledge_claim_relations", "knowledge_claim_reviews", "knowledge_claims", "knowledge_document_versions", "knowledge_entities", "knowledge_entity_aliases", "knowledge_facts", "knowledge_operation_receipts", "knowledge_providers", "knowledge_source_acl_versions", "knowledge_source_objects", "knowledge_sources", "knowledge_sync_runs", "preference_registry_preferences", "preference_registry_revisions", "session_attempt_tool_catalogs", "session_goal_revisions", "session_spawn_denials", "slack_shared_task_origins", "slack_user_link_access_request_operations", "temporal_schedule_cleanup_outbox", "workspace_artifact_events", "workspace_artifact_versions", "workspace_instruction_policy_activation_events", "workspace_instruction_policy_onboarding_proposals", "workspace_instruction_policy_revisions", "workspace_learning_policy_revisions"];
|
|
28
28
|
/** Durable operation journals are append/read plus claim/settle updates, never deletes. */
|
|
29
29
|
export declare const RUNTIME_READ_INSERT_UPDATE_TABLES: readonly ["attached_browser_devices", "attached_browser_inventories", "auth_runs", "browser_identities", "browser_sessions", "browser_state_artifacts", "browser_state_uploads", "capability_api_facets", "capability_facets", "capability_integration_facets", "capability_mcp_facets", "capability_plugin_versions", "capability_plugins", "capability_skill_facets", "capability_skill_files", "computer_sessions", "editable_artifact_session_links", "editable_artifacts", "integration_facet_definitions", "integration_spec_revisions", "integration_tools", "interaction_interventions", "interaction_operations", "interaction_resource_operations", "network_routes", "session_attempt_codemode_calls", "site_auth_connections", "slack_user_link_access_requests", "workspace_interaction_revisions"];
|
|
30
30
|
/**
|
package/dist/schema.d.ts
CHANGED
|
@@ -10929,8 +10929,8 @@ export declare const sessions: import("drizzle-orm/pg-core").PgTableWithColumns<
|
|
|
10929
10929
|
identity: undefined;
|
|
10930
10930
|
generated: undefined;
|
|
10931
10931
|
}, {}, {}>;
|
|
10932
|
-
|
|
10933
|
-
name: "
|
|
10932
|
+
initialModelContext: import("drizzle-orm/pg-core").PgColumn<{
|
|
10933
|
+
name: "initial_model_context";
|
|
10934
10934
|
tableName: "sessions";
|
|
10935
10935
|
dataType: "string";
|
|
10936
10936
|
columnType: "PgText";
|
|
@@ -13498,6 +13498,23 @@ export declare const sessionRealtimeEntries: import("drizzle-orm/pg-core").PgTab
|
|
|
13498
13498
|
identity: undefined;
|
|
13499
13499
|
generated: undefined;
|
|
13500
13500
|
}, {}, {}>;
|
|
13501
|
+
modelContext: import("drizzle-orm/pg-core").PgColumn<{
|
|
13502
|
+
name: "model_context";
|
|
13503
|
+
tableName: "session_realtime_entries";
|
|
13504
|
+
dataType: "string";
|
|
13505
|
+
columnType: "PgText";
|
|
13506
|
+
data: string;
|
|
13507
|
+
driverParam: string;
|
|
13508
|
+
notNull: false;
|
|
13509
|
+
hasDefault: false;
|
|
13510
|
+
isPrimaryKey: false;
|
|
13511
|
+
isAutoincrement: false;
|
|
13512
|
+
hasRuntimeDefault: false;
|
|
13513
|
+
enumValues: [string, ...string[]];
|
|
13514
|
+
baseColumn: never;
|
|
13515
|
+
identity: undefined;
|
|
13516
|
+
generated: undefined;
|
|
13517
|
+
}, {}, {}>;
|
|
13501
13518
|
clientAckedAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
13502
13519
|
name: "client_acked_at";
|
|
13503
13520
|
tableName: "session_realtime_entries";
|
|
@@ -19703,8 +19720,8 @@ export declare const sessionTurns: import("drizzle-orm/pg-core").PgTableWithColu
|
|
|
19703
19720
|
ordinal: number;
|
|
19704
19721
|
}[];
|
|
19705
19722
|
}>;
|
|
19706
|
-
|
|
19707
|
-
name: "
|
|
19723
|
+
modelContext: import("drizzle-orm/pg-core").PgColumn<{
|
|
19724
|
+
name: "model_context";
|
|
19708
19725
|
tableName: "session_turns";
|
|
19709
19726
|
dataType: "string";
|
|
19710
19727
|
columnType: "PgText";
|
package/dist/schema.js
CHANGED
|
@@ -76,6 +76,8 @@ import {
|
|
|
76
76
|
generatedVideoArtifacts,
|
|
77
77
|
githubInstallationRepositories,
|
|
78
78
|
githubInstallations,
|
|
79
|
+
googleDriveObjectAclEvidence,
|
|
80
|
+
googleDriveObjectAclPrincipals,
|
|
79
81
|
hostExportConfig,
|
|
80
82
|
hostExportConsumers,
|
|
81
83
|
hostExportCursorState,
|
|
@@ -255,7 +257,7 @@ import {
|
|
|
255
257
|
xaiRotationSettings,
|
|
256
258
|
xaiSessionAccountPins,
|
|
257
259
|
xaiSubscriptionCredentials
|
|
258
|
-
} from "./chunk-
|
|
260
|
+
} from "./chunk-6ZYKCRFO.js";
|
|
259
261
|
import "./chunk-PZ5AY32C.js";
|
|
260
262
|
export {
|
|
261
263
|
agentRunStates,
|
|
@@ -335,6 +337,8 @@ export {
|
|
|
335
337
|
generatedVideoArtifacts,
|
|
336
338
|
githubInstallationRepositories,
|
|
337
339
|
githubInstallations,
|
|
340
|
+
googleDriveObjectAclEvidence,
|
|
341
|
+
googleDriveObjectAclPrincipals,
|
|
338
342
|
hostExportConfig,
|
|
339
343
|
hostExportConsumers,
|
|
340
344
|
hostExportCursorState,
|
|
@@ -155,7 +155,7 @@ export declare function submitHumanPromptInTransaction(db: SessionActivityDataba
|
|
|
155
155
|
expectedDraftRevision?: number | null;
|
|
156
156
|
text: string;
|
|
157
157
|
annotations?: TimelineAnnotation[];
|
|
158
|
-
|
|
158
|
+
modelContext?: string | null;
|
|
159
159
|
resources: ResourceRef[];
|
|
160
160
|
model?: string | null;
|
|
161
161
|
reasoningEffort?: ReasoningEffort | null;
|
|
@@ -102,6 +102,7 @@ export type SessionRealtimeInboundEntryInput = {
|
|
|
102
102
|
delegationItemId?: string | null | undefined;
|
|
103
103
|
text?: string | null | undefined;
|
|
104
104
|
payload?: Record<string, unknown> | undefined;
|
|
105
|
+
modelContext?: string | undefined;
|
|
105
106
|
};
|
|
106
107
|
export type SyncSessionRealtimeLedgerInput = AssertSessionRealtimeOwnerInput & {
|
|
107
108
|
connectionId: string;
|
package/dist/session-tenancy.js
CHANGED
|
@@ -3,9 +3,9 @@ import {
|
|
|
3
3
|
canonicalSessionVisibilityTransitionHash,
|
|
4
4
|
forkSessionContent,
|
|
5
5
|
transitionSessionVisibility
|
|
6
|
-
} from "./chunk-
|
|
7
|
-
import "./chunk-
|
|
8
|
-
import "./chunk-
|
|
6
|
+
} from "./chunk-WD5ROSLL.js";
|
|
7
|
+
import "./chunk-ZWREYEWA.js";
|
|
8
|
+
import "./chunk-6ZYKCRFO.js";
|
|
9
9
|
import "./chunk-PZ5AY32C.js";
|
|
10
10
|
export {
|
|
11
11
|
canonicalSessionForkHash,
|
package/dist/video-generation.js
CHANGED
|
@@ -29,9 +29,9 @@ import {
|
|
|
29
29
|
settleVideoGenerationFailure,
|
|
30
30
|
settleVideoGenerationReady,
|
|
31
31
|
updateWorkspaceVideoGenerationPolicy
|
|
32
|
-
} from "./chunk-
|
|
33
|
-
import "./chunk-
|
|
34
|
-
import "./chunk-
|
|
32
|
+
} from "./chunk-CUPM3FGB.js";
|
|
33
|
+
import "./chunk-ZWREYEWA.js";
|
|
34
|
+
import "./chunk-6ZYKCRFO.js";
|
|
35
35
|
import "./chunk-PZ5AY32C.js";
|
|
36
36
|
export {
|
|
37
37
|
ACTIVE_VIDEO_GENERATION_STATUSES,
|
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
-- deployment-mode: rolling
|
|
2
|
+
-- A turn activity could previously exhaust a transient attempt-claim failure,
|
|
3
|
+
-- leave durable work with no active attempt, and then let its Temporal workflow
|
|
4
|
+
-- complete. This includes queued/recovering turns, a resumed approval, a
|
|
5
|
+
-- released capacity wait, manual compaction, and pending internal updates. Seed
|
|
6
|
+
-- one delayed durable wake for those exact admitted rows; current workflows may
|
|
7
|
+
-- consume it as an idempotent hint, while closed workflows are restarted by the
|
|
8
|
+
-- ordinary outbox dispatcher. A normal queued turn with an undelivered wake is
|
|
9
|
+
-- healthy and must remain untouched.
|
|
10
|
+
|
|
11
|
+
SET LOCAL lock_timeout = '5s';
|
|
12
|
+
SET LOCAL statement_timeout = '10min';
|
|
13
|
+
|
|
14
|
+
WITH RECURSIVE candidates AS MATERIALIZED (
|
|
15
|
+
SELECT
|
|
16
|
+
session_row.id AS session_id,
|
|
17
|
+
session_row.account_id,
|
|
18
|
+
session_row.workspace_id,
|
|
19
|
+
coalesce(
|
|
20
|
+
session_row.temporal_workflow_id,
|
|
21
|
+
'session-' || session_row.id::text
|
|
22
|
+
) AS temporal_workflow_id
|
|
23
|
+
FROM sessions session_row
|
|
24
|
+
WHERE session_row.status NOT IN ('failed', 'cancelled')
|
|
25
|
+
AND NOT EXISTS (
|
|
26
|
+
SELECT 1
|
|
27
|
+
FROM session_turn_attempts live_attempt
|
|
28
|
+
WHERE live_attempt.workspace_id = session_row.workspace_id
|
|
29
|
+
AND live_attempt.session_id = session_row.id
|
|
30
|
+
AND live_attempt.state IN ('claimed', 'running')
|
|
31
|
+
)
|
|
32
|
+
AND (
|
|
33
|
+
(
|
|
34
|
+
session_row.status = 'recovering'
|
|
35
|
+
AND EXISTS (
|
|
36
|
+
SELECT 1
|
|
37
|
+
FROM session_turns turn_row
|
|
38
|
+
WHERE turn_row.workspace_id = session_row.workspace_id
|
|
39
|
+
AND turn_row.session_id = session_row.id
|
|
40
|
+
AND turn_row.id = session_row.active_turn_id
|
|
41
|
+
AND turn_row.status = 'recovering'
|
|
42
|
+
AND turn_row.active_attempt_id IS NULL
|
|
43
|
+
)
|
|
44
|
+
)
|
|
45
|
+
OR (
|
|
46
|
+
EXISTS (
|
|
47
|
+
SELECT 1
|
|
48
|
+
FROM session_workflow_wake_outbox wake_row
|
|
49
|
+
WHERE wake_row.session_id = session_row.id
|
|
50
|
+
AND wake_row.wake_revision > 0
|
|
51
|
+
AND wake_row.wake_revision = wake_row.delivered_revision
|
|
52
|
+
)
|
|
53
|
+
AND (
|
|
54
|
+
(
|
|
55
|
+
session_row.status = 'queued'
|
|
56
|
+
AND session_row.active_turn_id IS NULL
|
|
57
|
+
AND EXISTS (
|
|
58
|
+
SELECT 1
|
|
59
|
+
FROM session_turns turn_row
|
|
60
|
+
WHERE turn_row.workspace_id = session_row.workspace_id
|
|
61
|
+
AND turn_row.session_id = session_row.id
|
|
62
|
+
AND turn_row.status = 'queued'
|
|
63
|
+
AND turn_row.source IN ('user', 'api')
|
|
64
|
+
AND turn_row.active_attempt_id IS NULL
|
|
65
|
+
)
|
|
66
|
+
)
|
|
67
|
+
OR (
|
|
68
|
+
session_row.status = 'waiting_capacity'
|
|
69
|
+
AND EXISTS (
|
|
70
|
+
SELECT 1
|
|
71
|
+
FROM session_turns turn_row
|
|
72
|
+
WHERE turn_row.workspace_id = session_row.workspace_id
|
|
73
|
+
AND turn_row.session_id = session_row.id
|
|
74
|
+
AND turn_row.id = session_row.active_turn_id
|
|
75
|
+
AND turn_row.status = 'waiting_capacity'
|
|
76
|
+
AND turn_row.active_attempt_id IS NULL
|
|
77
|
+
)
|
|
78
|
+
AND NOT EXISTS (
|
|
79
|
+
SELECT 1
|
|
80
|
+
FROM codex_capacity_waiters waiter
|
|
81
|
+
WHERE waiter.workspace_id = session_row.workspace_id
|
|
82
|
+
AND waiter.session_id = session_row.id
|
|
83
|
+
AND waiter.status = 'waiting'
|
|
84
|
+
)
|
|
85
|
+
AND NOT EXISTS (
|
|
86
|
+
SELECT 1
|
|
87
|
+
FROM xai_capacity_waiters waiter
|
|
88
|
+
WHERE waiter.workspace_id = session_row.workspace_id
|
|
89
|
+
AND waiter.session_id = session_row.id
|
|
90
|
+
AND waiter.status = 'waiting'
|
|
91
|
+
)
|
|
92
|
+
)
|
|
93
|
+
OR (
|
|
94
|
+
session_row.status = 'requires_action'
|
|
95
|
+
AND EXISTS (
|
|
96
|
+
SELECT 1
|
|
97
|
+
FROM session_turns turn_row
|
|
98
|
+
JOIN session_events trigger_event
|
|
99
|
+
ON trigger_event.workspace_id = turn_row.workspace_id
|
|
100
|
+
AND trigger_event.session_id = turn_row.session_id
|
|
101
|
+
AND trigger_event.id = turn_row.trigger_event_id
|
|
102
|
+
WHERE turn_row.workspace_id = session_row.workspace_id
|
|
103
|
+
AND turn_row.session_id = session_row.id
|
|
104
|
+
AND turn_row.id = session_row.active_turn_id
|
|
105
|
+
AND turn_row.status = 'requires_action'
|
|
106
|
+
AND turn_row.active_attempt_id IS NULL
|
|
107
|
+
AND EXISTS (
|
|
108
|
+
SELECT 1
|
|
109
|
+
FROM session_events response_event
|
|
110
|
+
WHERE response_event.workspace_id = session_row.workspace_id
|
|
111
|
+
AND response_event.session_id = session_row.id
|
|
112
|
+
AND response_event.type IN (
|
|
113
|
+
'user.approvalDecision',
|
|
114
|
+
'user.humanInputResponse'
|
|
115
|
+
)
|
|
116
|
+
AND response_event.sequence > trigger_event.sequence
|
|
117
|
+
)
|
|
118
|
+
)
|
|
119
|
+
)
|
|
120
|
+
OR (
|
|
121
|
+
session_row.active_turn_id IS NULL
|
|
122
|
+
AND session_row.status IN ('queued', 'idle')
|
|
123
|
+
AND session_row.compact_requested
|
|
124
|
+
)
|
|
125
|
+
OR (
|
|
126
|
+
session_row.active_turn_id IS NULL
|
|
127
|
+
AND session_row.status IN ('queued', 'idle')
|
|
128
|
+
AND EXISTS (
|
|
129
|
+
SELECT 1
|
|
130
|
+
FROM session_system_updates update_row
|
|
131
|
+
WHERE update_row.workspace_id = session_row.workspace_id
|
|
132
|
+
AND update_row.session_id = session_row.id
|
|
133
|
+
AND update_row.state = 'pending'
|
|
134
|
+
)
|
|
135
|
+
AND (
|
|
136
|
+
EXISTS (
|
|
137
|
+
SELECT 1
|
|
138
|
+
FROM session_system_updates update_row
|
|
139
|
+
WHERE update_row.workspace_id = session_row.workspace_id
|
|
140
|
+
AND update_row.session_id = session_row.id
|
|
141
|
+
AND update_row.state = 'pending'
|
|
142
|
+
AND update_row.kind = 'agent_steer_instruction'
|
|
143
|
+
)
|
|
144
|
+
OR NOT EXISTS (
|
|
145
|
+
SELECT 1
|
|
146
|
+
FROM session_turns failed_turn
|
|
147
|
+
JOIN session_events failure_event
|
|
148
|
+
ON failure_event.workspace_id = failed_turn.workspace_id
|
|
149
|
+
AND failure_event.session_id = failed_turn.session_id
|
|
150
|
+
AND failure_event.turn_id = failed_turn.id
|
|
151
|
+
AND failure_event.type = 'turn.failed'
|
|
152
|
+
AND failure_event.payload ->> 'code' = 'context_compaction_failed'
|
|
153
|
+
WHERE failed_turn.workspace_id = session_row.workspace_id
|
|
154
|
+
AND failed_turn.session_id = session_row.id
|
|
155
|
+
AND failed_turn.finished_at IS NOT NULL
|
|
156
|
+
AND failed_turn.id = (
|
|
157
|
+
SELECT latest_turn.id
|
|
158
|
+
FROM session_turns latest_turn
|
|
159
|
+
WHERE latest_turn.workspace_id = session_row.workspace_id
|
|
160
|
+
AND latest_turn.session_id = session_row.id
|
|
161
|
+
AND latest_turn.finished_at IS NOT NULL
|
|
162
|
+
ORDER BY
|
|
163
|
+
latest_turn.position DESC,
|
|
164
|
+
latest_turn.created_at DESC
|
|
165
|
+
LIMIT 1
|
|
166
|
+
)
|
|
167
|
+
)
|
|
168
|
+
)
|
|
169
|
+
)
|
|
170
|
+
)
|
|
171
|
+
)
|
|
172
|
+
)
|
|
173
|
+
), ancestry AS (
|
|
174
|
+
SELECT
|
|
175
|
+
candidate.session_id AS candidate_session_id,
|
|
176
|
+
session_row.workspace_id,
|
|
177
|
+
session_row.id AS session_id,
|
|
178
|
+
session_row.parent_session_id,
|
|
179
|
+
session_row.direct_control_state,
|
|
180
|
+
session_row.direct_pause_revision,
|
|
181
|
+
session_row.subtree_run_override_revision,
|
|
182
|
+
0::integer AS depth,
|
|
183
|
+
ARRAY[session_row.id]::uuid[] AS path,
|
|
184
|
+
false AS cycle
|
|
185
|
+
FROM candidates candidate
|
|
186
|
+
JOIN sessions session_row
|
|
187
|
+
ON session_row.workspace_id = candidate.workspace_id
|
|
188
|
+
AND session_row.id = candidate.session_id
|
|
189
|
+
UNION ALL
|
|
190
|
+
SELECT
|
|
191
|
+
child.candidate_session_id,
|
|
192
|
+
parent.workspace_id,
|
|
193
|
+
parent.id,
|
|
194
|
+
parent.parent_session_id,
|
|
195
|
+
parent.direct_control_state,
|
|
196
|
+
parent.direct_pause_revision,
|
|
197
|
+
parent.subtree_run_override_revision,
|
|
198
|
+
child.depth + 1,
|
|
199
|
+
child.path || parent.id,
|
|
200
|
+
parent.id = ANY(child.path)
|
|
201
|
+
FROM ancestry child
|
|
202
|
+
JOIN sessions parent
|
|
203
|
+
ON parent.workspace_id = child.workspace_id
|
|
204
|
+
AND parent.id = child.parent_session_id
|
|
205
|
+
WHERE child.parent_session_id IS NOT NULL
|
|
206
|
+
AND NOT child.cycle
|
|
207
|
+
AND child.depth < 10000
|
|
208
|
+
), orphaned AS (
|
|
209
|
+
SELECT candidate.*
|
|
210
|
+
FROM candidates candidate
|
|
211
|
+
JOIN workspace_inference_controls control_row
|
|
212
|
+
ON control_row.workspace_id = candidate.workspace_id
|
|
213
|
+
WHERE EXISTS (
|
|
214
|
+
SELECT 1
|
|
215
|
+
FROM ancestry root
|
|
216
|
+
WHERE root.candidate_session_id = candidate.session_id
|
|
217
|
+
AND root.parent_session_id IS NULL
|
|
218
|
+
AND NOT root.cycle
|
|
219
|
+
)
|
|
220
|
+
AND NOT EXISTS (
|
|
221
|
+
SELECT 1
|
|
222
|
+
FROM ancestry invalid
|
|
223
|
+
WHERE invalid.candidate_session_id = candidate.session_id
|
|
224
|
+
AND invalid.cycle
|
|
225
|
+
)
|
|
226
|
+
AND NOT EXISTS (
|
|
227
|
+
SELECT 1
|
|
228
|
+
FROM ancestry pause
|
|
229
|
+
WHERE pause.candidate_session_id = candidate.session_id
|
|
230
|
+
AND pause.direct_control_state = 'paused'
|
|
231
|
+
AND NOT EXISTS (
|
|
232
|
+
SELECT 1
|
|
233
|
+
FROM ancestry override_row
|
|
234
|
+
WHERE override_row.candidate_session_id = candidate.session_id
|
|
235
|
+
AND override_row.depth < pause.depth
|
|
236
|
+
AND override_row.subtree_run_override_revision > pause.direct_pause_revision
|
|
237
|
+
)
|
|
238
|
+
)
|
|
239
|
+
AND (
|
|
240
|
+
control_row.workspace_state = 'active'
|
|
241
|
+
OR (
|
|
242
|
+
control_row.workspace_state = 'paused'
|
|
243
|
+
AND EXISTS (
|
|
244
|
+
SELECT 1
|
|
245
|
+
FROM ancestry override_row
|
|
246
|
+
WHERE override_row.candidate_session_id = candidate.session_id
|
|
247
|
+
AND override_row.subtree_run_override_revision
|
|
248
|
+
> control_row.workspace_pause_revision
|
|
249
|
+
)
|
|
250
|
+
)
|
|
251
|
+
)
|
|
252
|
+
), seeded AS (
|
|
253
|
+
INSERT INTO session_workflow_wake_outbox (
|
|
254
|
+
session_id,
|
|
255
|
+
account_id,
|
|
256
|
+
workspace_id,
|
|
257
|
+
temporal_workflow_id,
|
|
258
|
+
reason,
|
|
259
|
+
next_attempt_at
|
|
260
|
+
)
|
|
261
|
+
SELECT
|
|
262
|
+
orphaned.session_id,
|
|
263
|
+
orphaned.account_id,
|
|
264
|
+
orphaned.workspace_id,
|
|
265
|
+
orphaned.temporal_workflow_id,
|
|
266
|
+
'unclaimed_attempt_recovery_cutover',
|
|
267
|
+
now() + interval '60 seconds'
|
|
268
|
+
FROM orphaned
|
|
269
|
+
ON CONFLICT (session_id) DO UPDATE SET
|
|
270
|
+
wake_revision = session_workflow_wake_outbox.wake_revision + 1,
|
|
271
|
+
temporal_workflow_id = excluded.temporal_workflow_id,
|
|
272
|
+
reason = excluded.reason,
|
|
273
|
+
attempts = 0,
|
|
274
|
+
next_attempt_at = CASE
|
|
275
|
+
WHEN session_workflow_wake_outbox.wake_revision
|
|
276
|
+
> session_workflow_wake_outbox.delivered_revision
|
|
277
|
+
THEN least(
|
|
278
|
+
session_workflow_wake_outbox.next_attempt_at,
|
|
279
|
+
excluded.next_attempt_at
|
|
280
|
+
)
|
|
281
|
+
ELSE excluded.next_attempt_at
|
|
282
|
+
END,
|
|
283
|
+
last_error = NULL,
|
|
284
|
+
updated_at = now()
|
|
285
|
+
RETURNING account_id, workspace_id, session_id, wake_revision, reason
|
|
286
|
+
)
|
|
287
|
+
INSERT INTO audit_events (
|
|
288
|
+
account_id,
|
|
289
|
+
workspace_id,
|
|
290
|
+
subject_id,
|
|
291
|
+
action,
|
|
292
|
+
target_type,
|
|
293
|
+
target_id,
|
|
294
|
+
metadata
|
|
295
|
+
)
|
|
296
|
+
SELECT
|
|
297
|
+
seeded.account_id,
|
|
298
|
+
seeded.workspace_id,
|
|
299
|
+
'session-recovery-migration',
|
|
300
|
+
'session.workflow.unclaimed_attempt_wake_seeded',
|
|
301
|
+
'session',
|
|
302
|
+
seeded.session_id::text,
|
|
303
|
+
jsonb_build_object(
|
|
304
|
+
'wakeRevision', seeded.wake_revision,
|
|
305
|
+
'reason', seeded.reason
|
|
306
|
+
)
|
|
307
|
+
FROM seeded;
|