agentengine-sdk-python 0.8.6__py3-none-any.whl → 0.8.8__py3-none-any.whl
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.
- {agentengine_sdk_python-0.8.6.dist-info → agentengine_sdk_python-0.8.8.dist-info}/METADATA +41 -18
- {agentengine_sdk_python-0.8.6.dist-info → agentengine_sdk_python-0.8.8.dist-info}/RECORD +710 -526
- {agentengine_sdk_python-0.8.6.dist-info → agentengine_sdk_python-0.8.8.dist-info}/WHEEL +1 -1
- ksadk/__init__.py +2 -1
- ksadk/_build_provenance.json +1 -1
- ksadk/_mcp_compat.py +305 -0
- ksadk/a2a/_invocation_state.py +1 -1
- ksadk/a2a/adk_invocation_context.py +2 -1
- ksadk/a2a/adk_tools.py +19 -9
- ksadk/a2a/bootstrap.py +7 -6
- ksadk/a2a/codex.py +2 -1
- ksadk/a2a/control_plane.py +119 -2
- ksadk/a2a/executor.py +24 -7
- ksadk/a2a/invocation_service.py +198 -7
- ksadk/a2a/kernel_task_adapter.py +60 -9
- ksadk/a2a/langgraph_invocation_context.py +3 -2
- ksadk/a2a/langgraph_managed.py +17 -1
- ksadk/a2a/langgraph_recovery.py +43 -5
- ksadk/a2a/langgraph_tool_runtime.py +8 -6
- ksadk/a2a/langgraph_tools.py +13 -1
- ksadk/a2a/platform.py +8 -2
- ksadk/a2a/runtime_approval.py +6 -21
- ksadk/a2a/runtime_input.py +3 -2
- ksadk/a2a/timeouts.py +37 -0
- ksadk/a2a/tool_outcomes.py +73 -0
- ksadk/a2a/workload_tokens.py +21 -134
- ksadk/a2ui/__init__.py +4 -0
- ksadk/a2ui/assets/basic-v0_9_1.json +1383 -0
- ksadk/a2ui/assets/common-types-v0_9.json +305 -0
- ksadk/a2ui/assets/legacy-seven-components.json +230 -0
- ksadk/a2ui/assets/manifest.json +86 -0
- ksadk/a2ui/budget.py +54 -0
- ksadk/a2ui/catalog.py +64 -0
- ksadk/a2ui/generation.py +71 -0
- ksadk/a2ui/legacy.py +88 -0
- ksadk/a2ui/linking.py +115 -0
- ksadk/a2ui/payload.py +46 -0
- ksadk/a2ui/presentation.py +79 -0
- ksadk/a2ui/registry.py +166 -0
- ksadk/a2ui/wire.py +110 -0
- ksadk/agent.py +29 -0
- ksadk/agui/_agent_helpers.py +16 -1
- ksadk/agui/_agent_kernel.py +515 -0
- ksadk/agui/_agent_projection.py +379 -0
- ksadk/agui/_agent_resume.py +279 -0
- ksadk/agui/_agent_types.py +67 -0
- ksadk/agui/a2ui_projection.py +3 -1
- ksadk/agui/agent.py +184 -571
- ksadk/agui/config.py +19 -5
- ksadk/agui/hosted.py +343 -0
- ksadk/agui/request_identity.py +11 -0
- ksadk/agui/routes.py +79 -2
- ksadk/api/client.py +158 -7
- ksadk/builders/code_builder.py +174 -52
- ksadk/builders/container_builder.py +28 -7
- ksadk/builders/framework_requirements.py +5 -4
- ksadk/builders/mcp_builder.py +145 -1
- ksadk/builders/project_imports.py +66 -0
- ksadk/cli/cmd_deploy.py +5 -0
- ksadk/cli/cmd_invoke.py +57 -2
- ksadk/cli/cmd_mcp.py +1 -1
- ksadk/cli/cmd_run.py +2 -4
- ksadk/cli/cmd_studio.py +19 -3
- ksadk/cli/cmd_web.py +28 -56
- ksadk/cli/hosted_command_events.py +148 -0
- ksadk/cli/hosted_invoke.py +66 -14
- ksadk/cli/runtime_bootstrap.py +5 -1
- ksadk/codex/async_client.py +354 -12
- ksadk/codex/runtime.py +17 -2
- ksadk/common/cloud_headers.py +33 -6
- ksadk/common/diagnostics.py +15 -0
- ksadk/compat/adk_compat.py +2 -0
- ksadk/compat/adk_stream.py +35 -0
- ksadk/compat/copilotkit_a2ui.py +85 -21
- ksadk/configs/env_registry.py +102 -19
- ksadk/configs/env_registry_a2a.py +42 -0
- ksadk/conversations/a2ui_projection.py +50 -0
- ksadk/conversations/context.py +12 -0
- ksadk/conversations/message_projection.py +106 -60
- ksadk/conversations/message_projection_blocks.py +75 -3
- ksadk/conversations/message_projection_outcomes.py +81 -0
- ksadk/conversations/projector.py +35 -0
- ksadk/conversations/runtime_invocation.py +3 -0
- ksadk/conversations/runtime_observability.py +1 -0
- ksadk/conversations/runtime_projection.py +23 -1
- ksadk/conversations/runtime_stream_events.py +11 -7
- ksadk/conversations/runtime_streaming.py +21 -17
- ksadk/deployment/mcp.py +93 -0
- ksadk/deployment/providers/serverless.py +130 -4
- ksadk/detection/mcp_detector.py +80 -22
- ksadk/events/_v1_compat/projection.py +2 -0
- ksadk/events/adapters/_langgraph_custom.py +195 -0
- ksadk/events/adapters/_langgraph_model_tasks.py +59 -0
- ksadk/events/adapters/_langgraph_support.py +80 -29
- ksadk/events/adapters/_langgraph_tool_outcomes.py +71 -0
- ksadk/events/adapters/_langgraph_usage_origin.py +86 -0
- ksadk/events/adapters/adk.py +11 -0
- ksadk/events/adapters/langgraph.py +188 -20
- ksadk/events/canonical.py +23 -1
- ksadk/events/canonical_store.py +133 -4
- ksadk/events/cold_recovery.py +2 -1
- ksadk/events/native_checkpoint.py +10 -0
- ksadk/events/reducer.py +9 -9
- ksadk/events/run_authority.py +15 -0
- ksadk/events/session_event.py +61 -0
- ksadk/events/sse_heartbeat.py +50 -0
- ksadk/events/usage.py +50 -0
- ksadk/harness/__init__.py +3 -0
- ksadk/harness/app.py +1 -1
- ksadk/harness/artifact_adapters/native_catalog.py +92 -0
- ksadk/harness/artifact_adapters/native_tool.py +16 -0
- ksadk/harness/browser_adapters/native_playwright.py +3 -1
- ksadk/harness/browser_adapters/native_vision.py +2 -1
- ksadk/harness/engine/postgres_checkpointer.py +170 -29
- ksadk/harness/model_adapters/native_openai.py +3 -1
- ksadk/harness/native/artifact_catalog_contract.py +26 -0
- ksadk/harness/native/artifact_partial_read_capacity.py +6 -3
- ksadk/harness/native/artifact_read_capacity.py +15 -87
- ksadk/harness/native/artifact_runtime.py +44 -1
- ksadk/harness/native/artifact_search_capacity.py +20 -119
- ksadk/harness/native/artifact_single_read_capacity.py +7 -6
- ksadk/harness/native/background_command_contract.py +40 -0
- ksadk/harness/native/background_commands.py +101 -0
- ksadk/harness/native/call_budget.py +24 -0
- ksadk/harness/native/child_budget.py +6 -6
- ksadk/harness/native/child_interruption.py +3 -2
- ksadk/harness/native/child_media.py +105 -0
- ksadk/harness/native/context.py +44 -0
- ksadk/harness/native/context_compaction_projection.py +38 -2
- ksadk/harness/native/context_continuation.py +54 -0
- ksadk/harness/native/context_contributions.py +2 -1
- ksadk/harness/native/context_directory_progress.py +117 -0
- ksadk/harness/native/context_driver.py +136 -11
- ksadk/harness/native/context_partial_summary.py +2 -0
- ksadk/harness/native/context_partition.py +37 -1
- ksadk/harness/native/context_replay.py +2 -1
- ksadk/harness/native/context_request_projection.py +59 -6
- ksadk/harness/native/context_runtime.py +211 -16
- ksadk/harness/native/context_runtime_contracts.py +123 -1
- ksadk/harness/native/context_session_history.py +96 -0
- ksadk/harness/native/context_source_progress.py +164 -5
- ksadk/harness/native/context_summary_planning.py +63 -15
- ksadk/harness/native/context_summary_prompt.py +72 -0
- ksadk/harness/native/context_summary_recovery.py +3 -1
- ksadk/harness/native/delivery_artifacts.py +58 -0
- ksadk/harness/native/delivery_context.py +64 -0
- ksadk/harness/native/delivery_feedback.py +95 -0
- ksadk/harness/native/delivery_review.py +10 -10
- ksadk/harness/native/effect_control.py +45 -1
- ksadk/harness/native/effect_receipts.py +50 -3
- ksadk/harness/native/effect_runtime.py +10 -1
- ksadk/harness/native/engine.py +601 -16
- ksadk/harness/native/execution_budget.py +88 -0
- ksadk/harness/native/history.py +1 -0
- ksadk/harness/native/machine.py +44 -7
- ksadk/harness/native/model.py +17 -3
- ksadk/harness/native/model_runtime.py +192 -12
- ksadk/harness/native/model_takeover.py +4 -2
- ksadk/harness/native/notification_admission.py +183 -0
- ksadk/harness/native/ports.py +54 -6
- ksadk/harness/native/run_clock.py +13 -6
- ksadk/harness/native/state.py +100 -1
- ksadk/harness/native/stream_display_buffer.py +198 -0
- ksadk/harness/native/subagents.py +21 -0
- ksadk/harness/native/task_policy.py +8 -3
- ksadk/harness/native/tool_batch_capacity.py +152 -0
- ksadk/harness/native/tool_budget.py +38 -9
- ksadk/harness/native/tool_error_recovery.py +241 -0
- ksadk/harness/native/tool_error_streak.py +10 -1
- ksadk/harness/native/tool_progress.py +1 -0
- ksadk/harness/native/tool_scheduling.py +9 -10
- ksadk/harness/native/turn_control.py +21 -2
- ksadk/harness/native/verification_runtime.py +2 -1
- ksadk/harness/native_facade.py +180 -9
- ksadk/harness/native_projection.py +18 -8
- ksadk/harness/native_runtime.py +208 -3
- ksadk/harness/provider_thinking.py +63 -0
- ksadk/harness/public_activity.py +3 -0
- ksadk/harness/service_presentation.py +44 -0
- ksadk/harness/service_runtime.py +1038 -0
- ksadk/harness/skill_adapters/native_disclosure.py +13 -1
- ksadk/harness/skill_adapters/native_metadata.py +40 -0
- ksadk/harness/spec.py +6 -0
- ksadk/harness/stores/native_commit_history.py +373 -0
- ksadk/harness/stores/native_contract.py +205 -1
- ksadk/harness/stores/native_memory.py +363 -1
- ksadk/harness/stores/native_sqlite.py +572 -14
- ksadk/harness/stores/native_sqlite_migration.py +34 -7
- ksadk/harness/subagent.py +6 -1
- ksadk/harness/subagent_adapters/native_background_child.py +8 -7
- ksadk/harness/subagent_adapters/native_child.py +87 -8
- ksadk/harness/tool_display.py +113 -2
- ksadk/harness/tool_display_contract.py +34 -1
- ksadk/interaction/contracts.py +19 -4
- ksadk/interaction/display_values.py +140 -0
- ksadk/interaction/form_values.py +130 -0
- ksadk/interaction/langgraph.py +53 -0
- ksadk/interaction/langgraph_approval.py +59 -0
- ksadk/interaction/langgraph_interrupt.py +129 -0
- ksadk/interaction/langgraph_observer.py +125 -0
- ksadk/interaction/ledger.py +32 -5
- ksadk/interaction/native_events.py +29 -0
- ksadk/interaction/providers/harness.py +9 -4
- ksadk/interaction/providers/langgraph.py +19 -8
- ksadk/interaction/resolution.py +43 -0
- ksadk/interaction/schema.py +168 -0
- ksadk/interaction/submission.py +184 -0
- ksadk/kernel/admission_cursor.py +19 -0
- ksadk/kernel/bootstrap.py +344 -228
- ksadk/kernel/contract_fingerprints.py +5 -0
- ksadk/kernel/contracts.py +1 -0
- ksadk/kernel/control.py +67 -0
- ksadk/kernel/conversation_input.py +39 -0
- ksadk/kernel/execution_host_ingress.py +6 -3
- ksadk/kernel/history_projection.py +85 -4
- ksadk/kernel/ingress.py +89 -27
- ksadk/kernel/interactions_memory.py +447 -0
- ksadk/kernel/interactions_postgres.py +500 -0
- ksadk/kernel/interactions_sqlite.py +684 -0
- ksadk/kernel/legacy_postgres_repair.py +113 -0
- ksadk/kernel/local_interactions.py +172 -0
- ksadk/kernel/memory_store.py +137 -366
- ksadk/kernel/native_confirmation.py +109 -0
- ksadk/kernel/postgres_locks.py +23 -0
- ksadk/kernel/postgres_store.py +573 -511
- ksadk/kernel/postgres_time.py +12 -0
- ksadk/kernel/recovery.py +26 -1
- ksadk/kernel/runtime_config.py +72 -0
- ksadk/kernel/runtime_environment.py +301 -0
- ksadk/kernel/session_storage.py +144 -0
- ksadk/kernel/sql/002_session_retirement.sql +86 -0
- ksadk/kernel/sql/003_legacy_repair_queue.sql +49 -0
- ksadk/kernel/sql/backfill_session_namespaces.sql +59 -0
- ksadk/kernel/sqlite_session_cleanup.py +84 -0
- ksadk/kernel/sqlite_store.py +232 -622
- ksadk/kernel/store.py +6 -0
- ksadk/kernel/submission_postgres.py +99 -0
- ksadk/kernel/submission_sqlite.py +107 -0
- ksadk/kernel/teams_effects.py +3 -4
- ksadk/kernel/teams_execution_context.py +3 -4
- ksadk/kernel/worker.py +91 -202
- ksadk/kernel/worker_controls.py +112 -27
- ksadk/kernel/worker_identity.py +15 -8
- ksadk/kernel/worker_interactions.py +343 -47
- ksadk/knowledge_base/__init__.py +1 -1
- ksadk/knowledge_base/client.py +138 -17
- ksadk/knowledge_base/openclaw_bridge.py +58 -0
- ksadk/knowledge_base/service.py +2 -0
- ksadk/mcp_runtime/__init__.py +34 -15
- ksadk/mcp_runtime/_adk.py +14 -0
- ksadk/mcp_runtime/oauth/__init__.py +6 -0
- ksadk/mcp_runtime/oauth/_agent.py +215 -0
- ksadk/mcp_runtime/oauth/_durable_tools.py +208 -0
- ksadk/mcp_runtime/oauth/bootstrap.py +69 -0
- ksadk/mcp_runtime/oauth/client.py +200 -0
- ksadk/mcp_runtime/oauth/code_config.py +90 -0
- ksadk/mcp_runtime/oauth/contract.json +32 -0
- ksadk/mcp_runtime/oauth/contract.py +6 -0
- ksadk/mcp_runtime/oauth/declarations.py +106 -0
- ksadk/mcp_runtime/oauth/http.py +63 -0
- ksadk/mcp_runtime/oauth/kernel.py +717 -0
- ksadk/mcp_runtime/oauth/langgraph.py +434 -0
- ksadk/mcp_runtime/oauth/local/__init__.py +1 -0
- ksadk/mcp_runtime/oauth/local/broker.py +491 -0
- ksadk/mcp_runtime/oauth/local/checkpoint.py +17 -0
- ksadk/mcp_runtime/oauth/local/persistence.py +227 -0
- ksadk/mcp_runtime/oauth/local/protocol.py +390 -0
- ksadk/mcp_runtime/oauth/local/runtime.py +413 -0
- ksadk/mcp_runtime/oauth/local/transport.py +79 -0
- ksadk/mcp_runtime/oauth/runtime_io.py +43 -0
- ksadk/mcp_runtime/oauth/security.py +73 -0
- ksadk/mcp_runtime/oauth/tools.py +434 -0
- ksadk/mcp_runtime/oauth/transport.py +109 -0
- ksadk/memory/adk/backends/sdk_ltm_backend.py +21 -12
- ksadk/memory/adk/long_term_memory.py +1 -2
- ksadk/memory/openclaw_bridge.py +115 -0
- ksadk/memory/providers/local_postgres.py +247 -55
- ksadk/memory/scope_ids.py +49 -0
- ksadk/memory/service.py +29 -3
- ksadk/model_gateway/client.py +1 -1
- ksadk/model_proxy/compat.py +22 -0
- ksadk/model_proxy/transform.py +3 -4
- ksadk/plugins/providers/codex.py +37 -2
- ksadk/plugins/providers/harness.py +65 -28
- ksadk/plugins/providers/harness_service.py +198 -0
- ksadk/plugins/providers/harness_service_context.py +175 -0
- ksadk/plugins/providers/harness_service_hooks.py +168 -0
- ksadk/plugins/providers/harness_service_memory.py +479 -0
- ksadk/plugins/providers/harness_tools.py +39 -2
- ksadk/plugins/providers/platform_resources.py +2 -2
- ksadk/resource_runtime/contracts.py +8 -3
- ksadk/resource_runtime/knowledge.py +1 -1
- ksadk/resource_runtime/langgraph.py +7 -3
- ksadk/resource_runtime/managed_projection.py +24 -9
- ksadk/resource_runtime/mcp_server.py +3 -3
- ksadk/resource_runtime/worker.py +24 -5
- ksadk/runners/_adk_a2a_stream.py +10 -0
- ksadk/runners/_adk_canonical_stream.py +38 -10
- ksadk/runners/_adk_tunnel_history.py +96 -0
- ksadk/runners/_langgraph_answer_contract.py +47 -0
- ksadk/runners/_langgraph_canonical_stream.py +657 -0
- ksadk/runners/_langgraph_checkpoint_binding.py +89 -0
- ksadk/runners/_langgraph_factory.py +79 -0
- ksadk/runners/_langgraph_final_answer.py +91 -0
- ksadk/runners/_langgraph_fresh_turn.py +67 -0
- ksadk/runners/_langgraph_interactions.py +199 -0
- ksadk/runners/_langgraph_output.py +69 -0
- ksadk/runners/_langgraph_runner_streams.py +38 -75
- ksadk/runners/_langgraph_state_reader.py +5 -0
- ksadk/runners/_langgraph_wait_cancellation.py +49 -0
- ksadk/runners/_session_identity.py +30 -4
- ksadk/runners/adk_runner.py +108 -22
- ksadk/runners/base_runner.py +21 -0
- ksadk/runners/langgraph_runner.py +122 -108
- ksadk/runners/patch_langchain.py +4 -2
- ksadk/runtime/_langgraph_interaction_adapter.py +333 -0
- ksadk/runtime/_runner_adapter/a2ui_surface.py +194 -22
- ksadk/runtime/_runner_adapter/chunk_mapping.py +688 -0
- ksadk/runtime/_runner_adapter/resume_context.py +64 -0
- ksadk/runtime/_runner_adapter/stream_mapping.py +29 -597
- ksadk/runtime/conversation_execution.py +61 -32
- ksadk/runtime/executor.py +34 -1
- ksadk/runtime/factory.py +17 -5
- ksadk/runtime/framework_adapters.py +37 -2
- ksadk/runtime/langgraph_checkpoint_view.py +168 -0
- ksadk/runtime/launch.py +2 -0
- ksadk/runtime/preprocessing.py +9 -1
- ksadk/runtime/runner_adapter.py +77 -37
- ksadk/runtime/session_storage.py +71 -0
- ksadk/sandbox/backends/e2b.py +95 -13
- ksadk/sandbox/backends/local_process.py +68 -4
- ksadk/sandbox/base.py +1 -1
- ksadk/sandbox/diagnostics.py +31 -0
- ksadk/sandbox/e2b_background.py +1768 -0
- ksadk/sandbox/e2b_errors.py +26 -0
- ksadk/sandbox/local_background.py +406 -0
- ksadk/sandbox/local_controls.py +8 -1
- ksadk/server/database_access.py +369 -0
- ksadk/server/database_access_contract.py +222 -0
- ksadk/server/factory.py +180 -3
- ksadk/server/history_deadline.py +20 -4
- ksadk/server/history_page_cache.py +8 -2
- ksadk/server/routes/common.py +13 -1
- ksadk/server/routes/control.py +2 -1
- ksadk/server/routes/database_access.py +17 -0
- ksadk/server/routes/dependencies.py +28 -0
- ksadk/server/routes/harness_service_view.py +38 -0
- ksadk/server/routes/interactions.py +106 -0
- ksadk/server/routes/kernel_ingress.py +19 -1
- ksadk/server/routes/local_kernel_control.py +80 -0
- ksadk/server/routes/openai_compat.py +6 -0
- ksadk/server/routes/projection.py +159 -2
- ksadk/server/routes/routers.py +6 -0
- ksadk/server/routes/run.py +30 -1
- ksadk/server/routes/session_identity.py +130 -0
- ksadk/server/routes/sessions.py +326 -312
- ksadk/server/routes/streaming.py +3 -2
- ksadk/server/routes/ui_bootstrap.py +265 -0
- ksadk/server/routes/workspace.py +7 -0
- ksadk/server/static/a2ui/basic-v0_9_1.json +1383 -0
- ksadk/server/static/a2ui/common-types-v0_9.json +305 -0
- ksadk/server/static/a2ui/legacy-seven-components.json +230 -0
- ksadk/server/static/a2ui/manifest.json +86 -0
- ksadk/server/static/a2ui/material-icons-OFL-1.1.txt +93 -0
- ksadk/server/static/assets/{ArtifactsPanel-CILaW-fC.js → ArtifactsPanel-Cdr5C_vM.js} +1 -1
- ksadk/server/static/assets/{CodeBlock-BVrNVtJC.js → CodeBlock-BWRafud9.js} +6 -6
- ksadk/server/static/assets/{MathMessageMarkdown-Dp7c4wWD.js → MathMessageMarkdown-CFKeJIvy.js} +7 -7
- ksadk/server/static/assets/{MermaidBlock-Dxop8Rd7.js → MermaidBlock-BneAGUOd.js} +9 -9
- ksadk/server/static/assets/NativeTerminalPanel-BHI85zDO.js +1 -0
- ksadk/server/static/assets/OfficialA2uiRenderer-BOmT36lJ.js +16 -0
- ksadk/server/static/assets/{abnfDiagram-VCTEODGH-ckWDmOzw.js → abnfDiagram-VCTEODGH-DQvlOsBI.js} +1 -1
- ksadk/server/static/assets/{arc-DqxJede-.js → arc-CGx0e4pN.js} +1 -1
- ksadk/server/static/assets/architecture-7GRP2DOG-CFWjFkDL.js +1 -0
- ksadk/server/static/assets/{architectureDiagram-5GKGNRK7-SEQA4bVi.js → architectureDiagram-5GKGNRK7-WyybcNKX.js} +1 -1
- ksadk/server/static/assets/{blockDiagram-NRAW4CY4-pM0B-6NJ.js → blockDiagram-NRAW4CY4-C9Cx_GVs.js} +1 -1
- ksadk/server/static/assets/{c4Diagram-UCG6FXSJ-m2tuCNVq.js → c4Diagram-UCG6FXSJ-Bh7X3bGr.js} +1 -1
- ksadk/server/static/assets/channel-D6Dp_l74.js +1 -0
- ksadk/server/static/assets/chunk-2Q5K7J3B-CwmjhFYK.js +1 -0
- ksadk/server/static/assets/{chunk-5VM5RSS4-GJHDr9Ww.js → chunk-5VM5RSS4-cP9XupZj.js} +1 -1
- ksadk/server/static/assets/{chunk-F27PBJKO-CbAN45AV.js → chunk-F27PBJKO-Bm77fvR9.js} +1 -1
- ksadk/server/static/assets/{chunk-G27WJ6UU-D5ngbbzF.js → chunk-G27WJ6UU-DDKNPesQ.js} +1 -1
- ksadk/server/static/assets/{chunk-JWPE2WC7-Cc5IwuYC.js → chunk-JWPE2WC7-BqiUDB7s.js} +1 -1
- ksadk/server/static/assets/{chunk-LCL6LL3I-CprgDDdJ.js → chunk-LCL6LL3I-C528mMZy.js} +1 -1
- ksadk/server/static/assets/{chunk-POPQ4Y6H-CDZhSy82.js → chunk-POPQ4Y6H-CzZ9g_Uf.js} +1 -1
- ksadk/server/static/assets/{chunk-RHFEMEQ7-CZchUNro.js → chunk-RHFEMEQ7-CXj4tUZ-.js} +1 -1
- ksadk/server/static/assets/{chunk-SVP7TREG-BVruqk6T.js → chunk-SVP7TREG-BHyd85pS.js} +1 -1
- ksadk/server/static/assets/{chunk-XXDRQBXY-4ld9SxPN.js → chunk-XXDRQBXY-Qe29PHGe.js} +1 -1
- ksadk/server/static/assets/classDiagram-DTDB5LWJ-DsbvkCAV.js +1 -0
- ksadk/server/static/assets/classDiagram-v2-JRS7N3AN-DsbvkCAV.js +1 -0
- ksadk/server/static/assets/{cose-bilkent-JH36ORCC-Dmyyk_Vp.js → cose-bilkent-JH36ORCC-maRKgeec.js} +1 -1
- ksadk/server/static/assets/cynefin-OW5HDTMX-CBZRVuc4.js +1 -0
- ksadk/server/static/assets/{cynefinDiagram-5FMLGOSQ-BIyq3EJb.js → cynefinDiagram-5FMLGOSQ-CoD0bEvn.js} +1 -1
- ksadk/server/static/assets/{dagre-3AP2YEHR-eBw08Qdk.js → dagre-3AP2YEHR-BkpgQqyW.js} +1 -1
- ksadk/server/static/assets/{dagre-DfvnEf45.js → dagre-BUaTFrYa.js} +1 -1
- ksadk/server/static/assets/{diagram-S7CK7UJ4-CUSrE3Mg.js → diagram-S7CK7UJ4-25HdTbjE.js} +1 -1
- ksadk/server/static/assets/{diagram-UQ7AKVKN-Dq5Zw2gy.js → diagram-UQ7AKVKN-KO-WqOIg.js} +1 -1
- ksadk/server/static/assets/{diagram-VSXAHHWV-DyUHfNwT.js → diagram-VSXAHHWV-B360BkDQ.js} +1 -1
- ksadk/server/static/assets/{diagram-VX7I27RA-CREmM89O.js → diagram-VX7I27RA-COr1Oqsg.js} +1 -1
- ksadk/server/static/assets/{diagram-Z3DM3KII-Dw9zhHUK.js → diagram-Z3DM3KII-CgaKrIwB.js} +1 -1
- ksadk/server/static/assets/{dist-AEv-vXf-.js → dist--HftQyp9.js} +1 -1
- ksadk/server/static/assets/{dist-pq-nD33R.js → dist-B3Jp5r1e.js} +1 -1
- ksadk/server/static/assets/{dist-cxTGfdqx.js → dist-BEbS8Bag.js} +1 -1
- ksadk/server/static/assets/{dist-BX_-FENW.js → dist-BQ116UdZ.js} +1 -1
- ksadk/server/static/assets/{dist-DDSyLEOX.js → dist-BoRn8a_t.js} +1 -1
- ksadk/server/static/assets/{dist-BBsYarrI.js → dist-Brbrdmff.js} +1 -1
- ksadk/server/static/assets/{dist-B8Myiet9.js → dist-Bsuusoi0.js} +1 -1
- ksadk/server/static/assets/{dist-DUxO0R99.js → dist-Bxcu8Ca0.js} +1 -1
- ksadk/server/static/assets/{dist-CVPau3tn.js → dist-By-MVndb.js} +1 -1
- ksadk/server/static/assets/{dist-lOy23y43.js → dist-C9BTMVwS.js} +1 -1
- ksadk/server/static/assets/{dist-C_qdxcSH.js → dist-CBo9AHUv.js} +1 -1
- ksadk/server/static/assets/{dist-bupkyEBZ.js → dist-CR61WJFC.js} +1 -1
- ksadk/server/static/assets/{dist-CHpW1BHj.js → dist-CwnkOyDn.js} +1 -1
- ksadk/server/static/assets/{dist-0uJ4tdx6.js → dist-CxIl4t92.js} +1 -1
- ksadk/server/static/assets/{dist-Cp2PaOMY.js → dist-DKG0OYnk.js} +1 -1
- ksadk/server/static/assets/{dist-BQMrUwdI.js → dist-DSw5Ju6-.js} +1 -1
- ksadk/server/static/assets/{dist-hL5p1til.js → dist-DXOlCAay.js} +1 -1
- ksadk/server/static/assets/{dist-CD4L6ymH.js → dist-DgJ57sRe.js} +1 -1
- ksadk/server/static/assets/{dist-CuR5Bgme.js → dist-DmWw0IXB.js} +1 -1
- ksadk/server/static/assets/{dist-Co68Apq4.js → dist-DzdXSBJb.js} +1 -1
- ksadk/server/static/assets/{dist-B49GzZDb.js → dist-HHvdjADB.js} +1 -1
- ksadk/server/static/assets/{dist-QzbGrED_.js → dist-_0Xgu_07.js} +1 -1
- ksadk/server/static/assets/{ebnfDiagram-PWID7BFC-BS5LdNoR.js → ebnfDiagram-PWID7BFC-DogDP2db.js} +1 -1
- ksadk/server/static/assets/{erDiagram-SSCWMZ5O-Bv1QtiY-.js → erDiagram-SSCWMZ5O-CeBDnUjR.js} +1 -1
- ksadk/server/static/assets/eventmodeling-NTZA5JFV-vXZWMkpn.js +1 -0
- ksadk/server/static/assets/flowDiagram-A5DVABFB-5LRgzKLv.js +1 -0
- ksadk/server/static/assets/{ganttDiagram-EL5Y4UJY-musi-e0G.js → ganttDiagram-EL5Y4UJY-oIQL3MCp.js} +1 -1
- ksadk/server/static/assets/gitGraph-4MIJSDKK-BUWSkncI.js +1 -0
- ksadk/server/static/assets/{gitGraphDiagram-WWUBYQGX-DH37EGkG.js → gitGraphDiagram-WWUBYQGX-B7qz0cmZ.js} +1 -1
- ksadk/server/static/assets/index-4g1ndaxW.js +1132 -0
- ksadk/server/static/assets/index-DEVfafsU.css +2 -0
- ksadk/server/static/assets/info-A6RAGUB7-CzJ_YrOs.js +1 -0
- ksadk/server/static/assets/{infoDiagram-RXCK75RN-C1kEtv2y.js → infoDiagram-RXCK75RN-yQRC41Ya.js} +1 -1
- ksadk/server/static/assets/{ishikawaDiagram-5VMMS53U-BCNPyMka.js → ishikawaDiagram-5VMMS53U-BCu4HiwL.js} +1 -1
- ksadk/server/static/assets/{journeyDiagram-EYS64GPL--cDbKnjP.js → journeyDiagram-EYS64GPL-JaqmO73K.js} +1 -1
- ksadk/server/static/assets/{kanban-definition-3QL26DDD-R1rAVw2f.js → kanban-definition-3QL26DDD-DQo4X8NO.js} +1 -1
- ksadk/server/static/assets/{katex-BT-X-V7U.js → katex-t_DWylQw.js} +1 -1
- ksadk/server/static/assets/{linear-DTR631iG.js → linear-DWdnI35B.js} +1 -1
- ksadk/server/static/assets/material-icons-latin-400-normal-kAwBdRge.woff2 +0 -0
- ksadk/server/static/assets/{mermaid-parser.core-DfFzJhX8.js → mermaid-parser.core-BHrT2Pfe.js} +2 -2
- ksadk/server/static/assets/{mindmap-definition-FBJOCRG2-D4by_rmk.js → mindmap-definition-FBJOCRG2-PBVAhZYV.js} +1 -1
- ksadk/server/static/assets/packet-AYTQ26CC-CXoos6fx.js +1 -0
- ksadk/server/static/assets/{pegDiagram-XKGWAZYB-xWXPEh0c.js → pegDiagram-XKGWAZYB-CU_cLfow.js} +1 -1
- ksadk/server/static/assets/pie-WAS4IAKB-CjF9NoIt.js +1 -0
- ksadk/server/static/assets/{pieDiagram-E7YTZNPT-BudBDlCI.js → pieDiagram-E7YTZNPT-B1h0-_pW.js} +1 -1
- ksadk/server/static/assets/{quadrantDiagram-AXDQQJYC-DXZ0PCJF.js → quadrantDiagram-AXDQQJYC-DEMoGo5a.js} +1 -1
- ksadk/server/static/assets/radar-RG4KPBEZ-BQGWs9nw.js +1 -0
- ksadk/server/static/assets/railroad-74A4TZTK-B6znvLUK.js +1 -0
- ksadk/server/static/assets/railroad-abnf-HS5TGJTU-Bzquz0As.js +1 -0
- ksadk/server/static/assets/railroad-ebnf-LZEXJU2U-1IikGkb5.js +1 -0
- ksadk/server/static/assets/railroad-peg-WCYAUIDC-BKKgHzdc.js +1 -0
- ksadk/server/static/assets/{railroadDiagram-O6MQD6OU-BdAYRYB8.js → railroadDiagram-O6MQD6OU-BTAob2wg.js} +1 -1
- ksadk/server/static/assets/{requirementDiagram-EFPCY7ZU-CBBmaL70.js → requirementDiagram-EFPCY7ZU-Dl0Q2SuO.js} +1 -1
- ksadk/server/static/assets/{sankeyDiagram-P5KCCOFB-Doc3rdwp.js → sankeyDiagram-P5KCCOFB-DeaTWkur.js} +1 -1
- ksadk/server/static/assets/{sequenceDiagram-WJ2MYXX4-0J8R8hWW.js → sequenceDiagram-WJ2MYXX4-gFQYrsOd.js} +1 -1
- ksadk/server/static/assets/{sizeCapture-X5ZJPWSS-CfFLlWsK.js → sizeCapture-X5ZJPWSS-pGQzddMB.js} +1 -1
- ksadk/server/static/assets/{stateDiagram-HBIQ2CUA-jBwkjtTy.js → stateDiagram-HBIQ2CUA-DmpYOZt1.js} +1 -1
- ksadk/server/static/assets/stateDiagram-v2-4QOOHH4V-Dolxgkw3.js +1 -0
- ksadk/server/static/assets/{swimlanes-XN3QIQJK-B0WxTQf8.js → swimlanes-XN3QIQJK-BfuSAsrr.js} +1 -1
- ksadk/server/static/assets/swimlanesDiagram-VK2B7HYN-BuI1erYj.js +8 -0
- ksadk/server/static/assets/{timeline-definition-24CTP7MA-BfCT_75A.js → timeline-definition-24CTP7MA-CgJwrrxf.js} +1 -1
- ksadk/server/static/assets/treeView-Q6P3EWNA-DtMdDH8N.js +1 -0
- ksadk/server/static/assets/treemap-WGGIJYW6-VoU8QtLZ.js +1 -0
- ksadk/server/static/assets/{vennDiagram-4TSXK5OY-9gX1VMDC.js → vennDiagram-4TSXK5OY-CBSAgXDd.js} +1 -1
- ksadk/server/static/assets/wardley-WFR3VGLG-YWSRB0Zm.js +1 -0
- ksadk/server/static/assets/{wardleyDiagram-VM6X3IG4-sEs_BP6O.js → wardleyDiagram-VM6X3IG4-013TZ2JZ.js} +1 -1
- ksadk/server/static/assets/{xychartDiagram-S5SC5T6Z-Ll4jvUN9.js → xychartDiagram-S5SC5T6Z-u6Frp8xp.js} +1 -1
- ksadk/server/static/index.html +2 -2
- ksadk/server/static/ui-source.json +11 -0
- ksadk/sessions/_local_service_sync.py +146 -5
- ksadk/sessions/_postgres_schema.py +17 -0
- ksadk/sessions/base.py +3 -0
- ksadk/sessions/continuity.py +7 -1
- ksadk/sessions/db_budget.py +14 -12
- ksadk/sessions/history_budget.py +7 -0
- ksadk/sessions/in_memory.py +113 -4
- ksadk/sessions/persistence.py +73 -7
- ksadk/sessions/postgres_service.py +948 -8
- ksadk/sessions/resilience.py +16 -0
- ksadk/sessions/resilient.py +601 -5
- ksadk/sessions/topology.py +9 -2
- ksadk/skills/mcp_server/register.py +471 -415
- ksadk/skills/mcp_server/server.py +239 -217
- ksadk/skills/request_connection.py +188 -0
- ksadk/skills/runtime/backends/e2b.py +52 -12
- ksadk/skills/service_client.py +104 -45
- ksadk/studio/api.py +413 -11
- ksadk/studio/api_contracts.py +7 -3
- ksadk/studio/api_plugin_routes.py +13 -6
- ksadk/studio/authoring_coordinator.py +6 -1
- ksadk/studio/background_output.py +72 -0
- ksadk/studio/build_resolution.py +28 -4
- ksadk/studio/cloud.py +516 -7
- ksadk/studio/cloud_history.py +149 -0
- ksadk/studio/cloud_shared_web.py +32 -3
- ksadk/studio/compiler.py +93 -4
- ksadk/studio/contracts.py +376 -9
- ksadk/studio/dsh_application.py +17 -4
- ksadk/studio/execution_host.py +10 -5
- ksadk/studio/interaction_submission.py +7 -2
- ksadk/studio/mcp_runtime.py +23 -8
- ksadk/studio/model_chat_tools.py +22 -10
- ksadk/studio/model_client.py +41 -11
- ksadk/studio/model_wire_identity.py +24 -0
- ksadk/studio/native_background_command_port.py +97 -0
- ksadk/studio/native_background_connection.py +230 -0
- ksadk/studio/native_background_locator.py +272 -0
- ksadk/studio/native_background_ownership.py +255 -0
- ksadk/studio/native_background_wakeup.py +686 -0
- ksadk/studio/native_browser_port.py +9 -3
- ksadk/studio/native_child_skills.py +4 -0
- ksadk/studio/native_coding_template.py +287 -0
- ksadk/studio/native_command_policy.py +23 -0
- ksadk/studio/native_context_evidence.py +81 -0
- ksadk/studio/native_context_port.py +13 -2
- ksadk/studio/native_directory_observation.py +177 -0
- ksadk/studio/native_final_shape.py +148 -19
- ksadk/studio/native_mcp_disclosure.py +8 -6
- ksadk/studio/native_mcp_tool_port.py +3 -1
- ksadk/studio/native_memory_context.py +10 -8
- ksadk/studio/native_model_port.py +201 -43
- ksadk/studio/native_planning.py +43 -2
- ksadk/studio/native_product.py +237 -12
- ksadk/studio/native_project_instructions.py +267 -0
- ksadk/studio/native_read_budget.py +21 -3
- ksadk/studio/native_subagent_port.py +125 -2
- ksadk/studio/native_tool_port.py +255 -14
- ksadk/studio/native_verification_presentation.py +13 -3
- ksadk/studio/plugin_composition.py +8 -1
- ksadk/studio/plugin_kernel_adapter.py +13 -0
- ksadk/studio/plugin_native_activation.py +6 -4
- ksadk/studio/plugin_runtime.py +9 -0
- ksadk/studio/presentation.py +12 -0
- ksadk/studio/project_instruction_trust.py +54 -0
- ksadk/studio/repository.py +1 -1
- ksadk/studio/resource_catalog.py +4 -1
- ksadk/studio/run_activity.py +8 -0
- ksadk/studio/run_service.py +496 -40
- ksadk/studio/scheduler_assistant.py +3 -1
- ksadk/studio/service.py +101 -2
- ksadk/studio/shared_web.py +38 -12
- ksadk/studio/shared_web_response_events.py +32 -5
- ksadk/studio/static/assets/ChannelsPage-Do_mRmVu.js +8 -0
- ksadk/studio/static/assets/{CodeBlock-DMIf4h33-CkufcPYo.js → CodeBlock-DMIf4h33-CsO7rJKv.js} +3 -3
- ksadk/studio/static/assets/{ExecutionTree-v3HexvPo-Bk8wzGSy.js → ExecutionTree-v3HexvPo-BeWoMqA-.js} +1 -1
- ksadk/studio/static/assets/{MathMessageMarkdown-BesSeCYl-DYG1Wzbx.js → MathMessageMarkdown-BesSeCYl-CiB60plG.js} +1 -1
- ksadk/studio/static/assets/{MermaidBlock-H_0qzQDf-BdXtxug_.js → MermaidBlock-H_0qzQDf-oRTZUNRr.js} +3 -3
- ksadk/studio/static/assets/{MessageMarkdown-CwMTvgFj-BeyLyQHu.js → MessageMarkdown-CwMTvgFj-BzEmQkHH.js} +5 -5
- ksadk/studio/static/assets/OfficialA2uiRenderer-DI49Kpxu-BBxfdj3P.js +16 -0
- ksadk/studio/static/assets/{PrismRenderer-5pK6tUdb.js → PrismRenderer-CcrOV6Lf.js} +1 -1
- ksadk/studio/static/assets/TeamsPage-qNVYpcox.js +4 -0
- ksadk/studio/static/assets/{abnfDiagram-VCTEODGH-Bnb1O3tA.js → abnfDiagram-VCTEODGH-BdEjkX5G.js} +1 -1
- ksadk/studio/static/assets/{arc-Pry-7G1_.js → arc-4LNeT6Qr.js} +1 -1
- ksadk/studio/static/assets/architecture-7GRP2DOG-C6BmiLXs.js +1 -0
- ksadk/studio/static/assets/{architectureDiagram-5GKGNRK7-5Zn1gqJv.js → architectureDiagram-5GKGNRK7-nKXkceF2.js} +3 -3
- ksadk/studio/static/assets/{blockDiagram-I7D4REHJ-CLB4L11u.js → blockDiagram-I7D4REHJ-pSawBX0F.js} +1 -1
- ksadk/studio/static/assets/{c4Diagram-7LVT6UL2-BOma_Z_F.js → c4Diagram-7LVT6UL2-D3DGtCIa.js} +1 -1
- ksadk/studio/static/assets/channel-CwBcaXYb.js +1 -0
- ksadk/studio/static/assets/{chunk-2E4U76K2-BFf_huql.js → chunk-2E4U76K2-CfUBZPB8.js} +2 -2
- ksadk/studio/static/assets/chunk-2Q5K7J3B-B9fZb2AW.js +1 -0
- ksadk/studio/static/assets/{chunk-2ZTRR5NV-C2qZJila.js → chunk-2ZTRR5NV-63jTqPgP.js} +1 -1
- ksadk/studio/static/assets/{chunk-3Z5EZCMW-DMniOlPd.js → chunk-3Z5EZCMW-CLzTC-ds.js} +1 -1
- ksadk/studio/static/assets/{chunk-4HAMMTFA-DVtDP4rm.js → chunk-4HAMMTFA--k1euiK8.js} +3 -3
- ksadk/studio/static/assets/{chunk-5V3GS4D5-i-ZDOEnP.js → chunk-5V3GS4D5--NT8dMSC.js} +1 -1
- ksadk/studio/static/assets/{chunk-5VM5RSS4-ZNzvKenW.js → chunk-5VM5RSS4-B4EX-xPG.js} +2 -2
- ksadk/studio/static/assets/{chunk-6AZGARVD-BB6FqMl-.js → chunk-6AZGARVD-BxyCuIKr.js} +1 -1
- ksadk/studio/static/assets/{chunk-6EIED4P4-DdUJkP0f.js → chunk-6EIED4P4-BqAnqs6L.js} +1 -1
- ksadk/studio/static/assets/{chunk-6K3QC6MW-CqVsVn-y.js → chunk-6K3QC6MW-DqKCc1_c.js} +1 -1
- ksadk/studio/static/assets/{chunk-6TQVIW2G-DKlLbNIP.js → chunk-6TQVIW2G-NQp6TssR.js} +1 -1
- ksadk/studio/static/assets/{chunk-747NJXEK-BFkZPlab.js → chunk-747NJXEK-CFf3ol0D.js} +1 -1
- ksadk/studio/static/assets/{chunk-75Z2AOVW-BZNhM4vB.js → chunk-75Z2AOVW-DpzsVI3p.js} +1 -1
- ksadk/studio/static/assets/chunk-CLGD4ZFX-BiEFihjn.js +1 -0
- ksadk/studio/static/assets/{chunk-DU6HZSFF-CpEZCUgg.js → chunk-DU6HZSFF-HbWKkMwX.js} +3 -3
- ksadk/studio/static/assets/{chunk-F27PBJKO-D7pvKf0C.js → chunk-F27PBJKO-BY9pwz0W.js} +1 -1
- ksadk/studio/static/assets/{chunk-FOHPRMQF-DHwB1DNv.js → chunk-FOHPRMQF-BAABtQ6R.js} +5 -5
- ksadk/studio/static/assets/{chunk-GMAD6QVW-DE_8H717.js → chunk-GMAD6QVW-C-Lw1ag9.js} +1 -1
- ksadk/studio/static/assets/{chunk-GVQU2GXP-BfEB0lNv.js → chunk-GVQU2GXP-CCUMaVF8.js} +1 -1
- ksadk/studio/static/assets/{chunk-I5DQTOEV-Hm2LfiYI.js → chunk-I5DQTOEV-DpUJ7zEH.js} +1 -1
- ksadk/studio/static/assets/{chunk-ICYGCRZG-749o-pGJ.js → chunk-ICYGCRZG-CknVx2uG.js} +1 -1
- ksadk/studio/static/assets/{chunk-IH6LHLGP-CC6I9F3i.js → chunk-IH6LHLGP-BJ6nT6RF.js} +1 -1
- ksadk/studio/static/assets/{chunk-IMKFNOWR-D38axYOR.js → chunk-IMKFNOWR-CTelL5KO.js} +1 -1
- ksadk/studio/static/assets/{chunk-JWPE2WC7-DVXcaiue.js → chunk-JWPE2WC7-CMg2kMrr.js} +1 -1
- ksadk/studio/static/assets/{chunk-KI3K4JFJ-Rma-0k_M.js → chunk-KI3K4JFJ-B1SKa0PC.js} +1 -1
- ksadk/studio/static/assets/{chunk-L3NEJ4N5-Dq5xn7aL.js → chunk-L3NEJ4N5-C8A22muD.js} +1 -1
- ksadk/studio/static/assets/{chunk-LNGE3PJU-DWpGwHrW.js → chunk-LNGE3PJU-D_NJe87O.js} +1 -1
- ksadk/studio/static/assets/{chunk-OSK3NFVY-DiCQjx9b.js → chunk-OSK3NFVY-DFHvKoNt.js} +1 -1
- ksadk/studio/static/assets/{chunk-OUJLGHUK-D0j2JRSg.js → chunk-OUJLGHUK-DkHSrVKj.js} +1 -1
- ksadk/studio/static/assets/{chunk-P2QGCYS3-VdhKmfYq.js → chunk-P2QGCYS3-C3nH7MEr.js} +1 -1
- ksadk/studio/static/assets/{chunk-POPQ4Y6H-C1_rzO5M.js → chunk-POPQ4Y6H-CLm6A2JW.js} +1 -1
- ksadk/studio/static/assets/{chunk-PWAF6VOD-B45HvflI.js → chunk-PWAF6VOD-BmVQq92D.js} +1 -1
- ksadk/studio/static/assets/{chunk-SHT3W25Y-DsCFnRVE.js → chunk-SHT3W25Y-cETj_Yg7.js} +1 -1
- ksadk/studio/static/assets/{chunk-SVP7TREG-DljApgRX.js → chunk-SVP7TREG-hm4Ur8KN.js} +1 -1
- ksadk/studio/static/assets/{chunk-TICWLB2K-DWqRtyqa.js → chunk-TICWLB2K-BuVjFGjc.js} +1 -1
- ksadk/studio/static/assets/{chunk-TLUHSLCS-DUeGgnD5.js → chunk-TLUHSLCS-7mZ4xr0q.js} +2 -2
- ksadk/studio/static/assets/{chunk-UY3FDG6J-CnmaAkG5.js → chunk-UY3FDG6J-2nV2i5mW.js} +1 -1
- ksadk/studio/static/assets/{chunk-XHIXRSVI-BFQ6B8BE.js → chunk-XHIXRSVI-BIR36bKX.js} +1 -1
- ksadk/studio/static/assets/chunk-XXDRQBXY-rafYnJzG.js +1 -0
- ksadk/studio/static/assets/classDiagram-ZZMXUADV-DdyoXyMk.js +1 -0
- ksadk/studio/static/assets/classDiagram-v2-VYDZK3BY-DdyoXyMk.js +1 -0
- ksadk/studio/static/assets/{cose-bilkent-JH36ORCC-om8AY0Mc.js → cose-bilkent-JH36ORCC-B9Ubz7rk.js} +1 -1
- ksadk/studio/static/assets/{createLucideIcon-DR0LGTP5.js → createLucideIcon-CTD6_IjT.js} +1 -1
- ksadk/studio/static/assets/cynefin-OW5HDTMX-BVS4hy6V.js +1 -0
- ksadk/studio/static/assets/{cynefinDiagram-5FMLGOSQ-6BrmK52S.js → cynefinDiagram-5FMLGOSQ-CKrgw1wI.js} +1 -1
- ksadk/studio/static/assets/{cytoscape.esm-CGd-uY3x.js → cytoscape.esm-Jip0ihto.js} +16 -16
- ksadk/studio/static/assets/{dagre-GXQ25YYZ-buZBRlwz.js → dagre-GXQ25YYZ-NjDjs3Kl.js} +1 -1
- ksadk/studio/static/assets/{dagre-PrKaheQc.js → dagre-YnTFOVV4.js} +1 -1
- ksadk/studio/static/assets/{diagram-S7CK7UJ4-C6aH78c4.js → diagram-S7CK7UJ4-C6X87QRZ.js} +1 -1
- ksadk/studio/static/assets/{diagram-UQ7AKVKN-DY_tQ6C_.js → diagram-UQ7AKVKN-Xf2JVuyK.js} +1 -1
- ksadk/studio/static/assets/{diagram-VSXAHHWV-DX9p5cQT.js → diagram-VSXAHHWV-CUZlU7Dr.js} +1 -1
- ksadk/studio/static/assets/{diagram-VX7I27RA-DB2WSH8X.js → diagram-VX7I27RA-BOcfFxfe.js} +1 -1
- ksadk/studio/static/assets/{diagram-Z3DM3KII-Ce1BJwHE.js → diagram-Z3DM3KII-1zrr7ezR.js} +1 -1
- ksadk/studio/static/assets/{dist-v5Q1xZ2K.js → dist-Brlz61T5.js} +1 -1
- ksadk/studio/static/assets/{ebnfDiagram-PWID7BFC-Daukxwqf.js → ebnfDiagram-PWID7BFC-C1LymnKg.js} +1 -1
- ksadk/studio/static/assets/{erDiagram-RLTQ6QDP-CGthTMmJ.js → erDiagram-RLTQ6QDP-Dm0YWPea.js} +1 -1
- ksadk/studio/static/assets/eventmodeling-NTZA5JFV-D9gMNzTL.js +1 -0
- ksadk/studio/static/assets/flowDiagram-HODETNUW-NYJgBJQu.js +1 -0
- ksadk/studio/static/assets/{ganttDiagram-EL5Y4UJY-BfoAZW9X.js → ganttDiagram-EL5Y4UJY-uJ27IKEw.js} +1 -1
- ksadk/studio/static/assets/gitGraph-4MIJSDKK-DQVCMicu.js +1 -0
- ksadk/studio/static/assets/{gitGraphDiagram-WWUBYQGX-S985OIJF.js → gitGraphDiagram-WWUBYQGX-mtpvi7ne.js} +3 -3
- ksadk/studio/static/assets/index-Cp9Unfkn.css +2 -0
- ksadk/studio/static/assets/index-HepnaEeR.js +1152 -0
- ksadk/studio/static/assets/{index.dom-BQenBtFm.js → index.dom-DSf_jcX2.js} +1 -1
- ksadk/studio/static/assets/info-A6RAGUB7-CMrsF9SP.js +1 -0
- ksadk/studio/static/assets/{infoDiagram-27XIBGKW-CO3W8tFn.js → infoDiagram-27XIBGKW-Hqrd2vbU.js} +1 -1
- ksadk/studio/static/assets/{ishikawaDiagram-5VMMS53U-BUGEl8cO.js → ishikawaDiagram-5VMMS53U-BB7nm3Dk.js} +1 -1
- ksadk/studio/static/assets/{journeyDiagram-3NMN7TZE-Ch2ZYxvr.js → journeyDiagram-3NMN7TZE-BXbRt7Ps.js} +1 -1
- ksadk/studio/static/assets/{kanban-definition-UXKFOSKX-Da-Fp4vC.js → kanban-definition-UXKFOSKX-2EtAxRbw.js} +1 -1
- ksadk/studio/static/assets/{katex-DhON-x74.js → katex-K_8DQ5UN.js} +1 -1
- ksadk/studio/static/assets/{line-BDaeq300.js → line-C4h80pWP.js} +1 -1
- ksadk/studio/static/assets/{linear-DmucvK78.js → linear-DCteYK3U.js} +1 -1
- ksadk/studio/static/assets/{mermaid-parser.core-Cj5mYdBi.js → mermaid-parser.core-TWhr-wg2.js} +2 -2
- ksadk/studio/static/assets/{mindmap-definition-YA3MSWOX-CvlsVQ38.js → mindmap-definition-YA3MSWOX-BC7jpEOt.js} +1 -1
- ksadk/studio/static/assets/{ordinal-BDEzSJ7C.js → ordinal-BXUrfsNY.js} +1 -1
- ksadk/studio/static/assets/packet-AYTQ26CC-BdMfjW7Z.js +1 -0
- ksadk/studio/static/assets/{pegDiagram-XKGWAZYB-BuHuNgT5.js → pegDiagram-XKGWAZYB-C-ZzWopk.js} +1 -1
- ksadk/studio/static/assets/pie-WAS4IAKB-B06bKgAM.js +1 -0
- ksadk/studio/static/assets/{pieDiagram-E7YTZNPT-DlrWiSOv.js → pieDiagram-E7YTZNPT-DGDL1XJp.js} +1 -1
- ksadk/studio/static/assets/{quadrantDiagram-AXDQQJYC-BA3hpUZM.js → quadrantDiagram-AXDQQJYC-DAPa64vy.js} +1 -1
- ksadk/studio/static/assets/radar-RG4KPBEZ-4lhecdYg.js +1 -0
- ksadk/studio/static/assets/railroad-74A4TZTK-CBTdV2Xq.js +1 -0
- ksadk/studio/static/assets/railroad-abnf-HS5TGJTU-D4HzgxJY.js +1 -0
- ksadk/studio/static/assets/railroad-ebnf-LZEXJU2U-D-qRzoh8.js +1 -0
- ksadk/studio/static/assets/railroad-peg-WCYAUIDC-DYA99dLv.js +1 -0
- ksadk/studio/static/assets/{railroadDiagram-O6MQD6OU-BxpAazym.js → railroadDiagram-O6MQD6OU-CkH0b7UT.js} +1 -1
- ksadk/studio/static/assets/{react-vendor-BNmTiJ-I.js → react-vendor-CTyAWUMQ.js} +1 -1
- ksadk/studio/static/assets/{requirementDiagram-BXWQKSXE-E-Ge0FcV.js → requirementDiagram-BXWQKSXE-BgZ0H8ni.js} +2 -2
- ksadk/studio/static/assets/rolldown-runtime-cO0ylGnt.js +1 -0
- ksadk/studio/static/assets/{sankeyDiagram-P5KCCOFB-CA6YKhQ3.js → sankeyDiagram-P5KCCOFB-BgqqGK6v.js} +1 -1
- ksadk/studio/static/assets/{sequenceDiagram-WJ2MYXX4-CcElXGg4.js → sequenceDiagram-WJ2MYXX4-CbQE1ava.js} +1 -1
- ksadk/studio/static/assets/{sizeCapture-INFHLROL-B0uUizjq.js → sizeCapture-INFHLROL-BtEJ4_JN.js} +1 -1
- ksadk/studio/static/assets/{src-B6xuSHsQ.js → src-DSHesKRm.js} +1 -1
- ksadk/studio/static/assets/{stateDiagram-D77RDMKH-DdXZOFqY.js → stateDiagram-D77RDMKH-D9uG2y8U.js} +1 -1
- ksadk/studio/static/assets/stateDiagram-v2-MP3YSRHH-2pITMnQn.js +1 -0
- ksadk/studio/static/assets/{swimlanes-42K2YHIH-NtgEEHLY.js → swimlanes-42K2YHIH-B0QgwqLd.js} +1 -1
- ksadk/studio/static/assets/swimlanesDiagram-VR7AAH4N-TXD08-JZ.js +8 -0
- ksadk/studio/static/assets/{timeline-definition-24CTP7MA-CIuYhNy3.js → timeline-definition-24CTP7MA-tbRyDWb4.js} +1 -1
- ksadk/studio/static/assets/treeView-Q6P3EWNA-NawrivXx.js +1 -0
- ksadk/studio/static/assets/treemap-WGGIJYW6-DabVcIU4.js +1 -0
- ksadk/studio/static/assets/{vennDiagram-4TSXK5OY-7HbApbrv.js → vennDiagram-4TSXK5OY-Xjhys4e4.js} +1 -1
- ksadk/studio/static/assets/wardley-WFR3VGLG-BrU5uhdd.js +1 -0
- ksadk/studio/static/assets/{wardleyDiagram-VM6X3IG4-CMJiaedy.js → wardleyDiagram-VM6X3IG4--sd605zd.js} +1 -1
- ksadk/studio/static/assets/{xychartDiagram-S5SC5T6Z-BdgtMvW2.js → xychartDiagram-S5SC5T6Z-B3XzcsnZ.js} +1 -1
- ksadk/studio/static/index.html +9 -9
- ksadk/studio/static/ui-source.json +11 -0
- ksadk/studio/teams_installation.py +1 -1
- ksadk/studio/templates.py +33 -3
- ksadk/toolsets/__init__.py +14 -1
- ksadk/toolsets/sandbox.py +303 -7
- ksadk/toolsets/workspace.py +17 -10
- ksadk/toolsets/workspace_editing.py +40 -0
- ksadk/toolsets/workspace_model_observation.py +6 -1
- ksadk/tracing/__init__.py +10 -1
- ksadk/tracing/routed.py +416 -0
- ksadk/tracing/setup.py +111 -6
- ksadk/tunnel/__init__.py +37 -0
- ksadk/tunnel/connector.py +384 -0
- ksadk/tunnel/discovery.py +107 -0
- ksadk/tunnel/failure.py +168 -0
- ksadk/tunnel/http_tools.py +100 -0
- ksadk/tunnel/langgraph.py +125 -0
- ksadk/tunnel/middleware.py +28 -0
- ksadk/tunnel/peers.py +872 -0
- ksadk/tunnel/protocol.py +97 -0
- ksadk/tunnel/registry.py +306 -0
- ksadk/tunnel/runtime.py +147 -0
- ksadk/tunnel/server.py +201 -0
- ksadk/tunnel/services.py +366 -0
- ksadk/tunnel/toolset.py +78 -0
- ksadk/version.py +1 -1
- ksadk_runtime_common/memory_backend/manifest.py +1 -1
- ksadk_runtime_common/memory_backend/providers/ksmem.py +60 -0
- ksadk_runtime_common/memory_backend/providers/lancedb.py +1 -2
- ksadk_runtime_common/memory_backend/providers/mem0.py +21 -0
- ksadk_runtime_common/memory_backend/registry.py +2 -0
- ksadk_runtime_common/memory_backend/render.py +1 -1
- ksadk_runtime_common/schemas/memory_backend_manifest.schema.json +37 -12
- ksadk_runtime_common/schemas/runtime_event_v2.json +2 -1
- ksadk/server/static/assets/NativeTerminalPanel-Cjjz8B30.js +0 -1
- ksadk/server/static/assets/architecture-7GRP2DOG-pn_DuLy6.js +0 -1
- ksadk/server/static/assets/channel-fySsnkft.js +0 -1
- ksadk/server/static/assets/chunk-2Q5K7J3B-BheGxKRQ.js +0 -1
- ksadk/server/static/assets/classDiagram-DTDB5LWJ-DSfLtNYm.js +0 -1
- ksadk/server/static/assets/classDiagram-v2-JRS7N3AN-DSfLtNYm.js +0 -1
- ksadk/server/static/assets/cynefin-OW5HDTMX-PFWIGtvA.js +0 -1
- ksadk/server/static/assets/eventmodeling-NTZA5JFV-DsM4upQX.js +0 -1
- ksadk/server/static/assets/flowDiagram-A5DVABFB-D5NA16k9.js +0 -1
- ksadk/server/static/assets/gitGraph-4MIJSDKK-DUCVz-ih.js +0 -1
- ksadk/server/static/assets/index-CZdkAvsv.js +0 -244
- ksadk/server/static/assets/index-CvXdHgF3.css +0 -2
- ksadk/server/static/assets/info-A6RAGUB7-rw0ZNHZp.js +0 -1
- ksadk/server/static/assets/packet-AYTQ26CC-Ca4Hvki9.js +0 -1
- ksadk/server/static/assets/pie-WAS4IAKB-hwiz6fbw.js +0 -1
- ksadk/server/static/assets/radar-RG4KPBEZ-BR1oZXLM.js +0 -1
- ksadk/server/static/assets/railroad-74A4TZTK-DfgEISfX.js +0 -1
- ksadk/server/static/assets/railroad-abnf-HS5TGJTU-CWOC3rdk.js +0 -1
- ksadk/server/static/assets/railroad-ebnf-LZEXJU2U-CiRvHCLY.js +0 -1
- ksadk/server/static/assets/railroad-peg-WCYAUIDC-DSDDyJ2f.js +0 -1
- ksadk/server/static/assets/stateDiagram-v2-4QOOHH4V-Cw1fPb5w.js +0 -1
- ksadk/server/static/assets/swimlanesDiagram-VK2B7HYN-Cc3JMBAF.js +0 -8
- ksadk/server/static/assets/treeView-Q6P3EWNA-C05SJHxo.js +0 -1
- ksadk/server/static/assets/treemap-WGGIJYW6-BqNLAhc3.js +0 -1
- ksadk/server/static/assets/wardley-WFR3VGLG-DokNktqB.js +0 -1
- ksadk/studio/static/assets/ChannelsPage-xX5HlMId.js +0 -8
- ksadk/studio/static/assets/TeamsPage-CCaaGaVp.js +0 -3
- ksadk/studio/static/assets/architecture-7GRP2DOG-BMOPAkUC.js +0 -1
- ksadk/studio/static/assets/channel-r8itPEik.js +0 -1
- ksadk/studio/static/assets/chunk-2Q5K7J3B-C1jixKkw.js +0 -1
- ksadk/studio/static/assets/chunk-CLGD4ZFX-D-GTtyKs.js +0 -1
- ksadk/studio/static/assets/chunk-XXDRQBXY-DqAYeljN.js +0 -1
- ksadk/studio/static/assets/classDiagram-ZZMXUADV-DjeMNJmu.js +0 -1
- ksadk/studio/static/assets/classDiagram-v2-VYDZK3BY-DjeMNJmu.js +0 -1
- ksadk/studio/static/assets/cynefin-OW5HDTMX-7tP7QfM3.js +0 -1
- ksadk/studio/static/assets/eventmodeling-NTZA5JFV-BR2FzK4R.js +0 -1
- ksadk/studio/static/assets/flowDiagram-HODETNUW-CZ1tEenp.js +0 -1
- ksadk/studio/static/assets/gitGraph-4MIJSDKK-DYlXv_yJ.js +0 -1
- ksadk/studio/static/assets/index-C7DNDik2.css +0 -2
- ksadk/studio/static/assets/index-Cy68gTlH.js +0 -265
- ksadk/studio/static/assets/info-A6RAGUB7-BlU-8_xu.js +0 -1
- ksadk/studio/static/assets/packet-AYTQ26CC-BSJEH9Lb.js +0 -1
- ksadk/studio/static/assets/pie-WAS4IAKB-qxv01Y8W.js +0 -1
- ksadk/studio/static/assets/radar-RG4KPBEZ-B6h6pWOs.js +0 -1
- ksadk/studio/static/assets/railroad-74A4TZTK-CGtTWdGc.js +0 -1
- ksadk/studio/static/assets/railroad-abnf-HS5TGJTU-Cq7y22IA.js +0 -1
- ksadk/studio/static/assets/railroad-ebnf-LZEXJU2U-V0aQVv9m.js +0 -1
- ksadk/studio/static/assets/railroad-peg-WCYAUIDC-BQiIsX_p.js +0 -1
- ksadk/studio/static/assets/rolldown-runtime-hePW80VL.js +0 -1
- ksadk/studio/static/assets/stateDiagram-v2-MP3YSRHH-CJbOM-QK.js +0 -1
- ksadk/studio/static/assets/swimlanesDiagram-VR7AAH4N-D-AVlW8B.js +0 -8
- ksadk/studio/static/assets/treeView-Q6P3EWNA-BTTYcvrF.js +0 -1
- ksadk/studio/static/assets/treemap-WGGIJYW6-Cg7tyfH8.js +0 -1
- ksadk/studio/static/assets/wardley-WFR3VGLG-C6N1rULY.js +0 -1
- {agentengine_sdk_python-0.8.6.dist-info → agentengine_sdk_python-0.8.8.dist-info}/entry_points.txt +0 -0
- {agentengine_sdk_python-0.8.6.dist-info → agentengine_sdk_python-0.8.8.dist-info}/licenses/LICENSE +0 -0
- {agentengine_sdk_python-0.8.6.dist-info → agentengine_sdk_python-0.8.8.dist-info}/top_level.txt +0 -0
- /ksadk/studio/static/assets/{array-BifhSqXX.js → array-mTkv7xdZ.js} +0 -0
- /ksadk/studio/static/assets/{chunk-Y2CYZVJY-DsF7k-Jl.js → chunk-Y2CYZVJY-C72YQVBQ.js} +0 -0
- /ksadk/studio/static/assets/{clsx-DB0hHKMi.js → clsx-BE-4uLAX.js} +0 -0
- /ksadk/studio/static/assets/{defaultLocale-BFoDCU3G.js → defaultLocale-YBltSZ3l.js} +0 -0
- /ksadk/studio/static/assets/{graphlib-DS17s2tU.js → graphlib-CYZB3_li.js} +0 -0
- /ksadk/studio/static/assets/{init-C-OQMol4.js → init-Ccnd9r3c.js} +0 -0
- /ksadk/studio/static/assets/{path-fybaL0A-.js → path-BfzAkHoX.js} +0 -0
- /ksadk/studio/static/assets/{preload-helper-CO68xz6u.js → preload-helper-2TpOpXko.js} +0 -0
- /ksadk/studio/static/assets/{presentation-yYw7xK60-BmcZriri.js → presentation-yYw7xK60-B7PYgYAE.js} +0 -0
- /ksadk/studio/static/assets/{rolldown-runtime-Dy4uBu1J-DK3Fl9T5.js → rolldown-runtime-Dy4uBu1J-CmRlGT1x.js} +0 -0
- /ksadk/studio/static/assets/{rough.esm-Dy-Kn_BL.js → rough.esm-BF6Sy8cM.js} +0 -0
ksadk/kernel/postgres_store.py
CHANGED
|
@@ -17,7 +17,10 @@
|
|
|
17
17
|
|
|
18
18
|
from __future__ import annotations
|
|
19
19
|
|
|
20
|
+
import asyncio
|
|
20
21
|
import json
|
|
22
|
+
import logging
|
|
23
|
+
import math
|
|
21
24
|
from contextlib import asynccontextmanager, nullcontext
|
|
22
25
|
from datetime import datetime, timezone
|
|
23
26
|
from pathlib import Path
|
|
@@ -30,22 +33,6 @@ from ksadk.events.session_event import (
|
|
|
30
33
|
session_event_to_envelope,
|
|
31
34
|
validate_write_guard,
|
|
32
35
|
)
|
|
33
|
-
from ksadk.interaction.contracts import (
|
|
34
|
-
InteractionReceipt,
|
|
35
|
-
InteractionRecord,
|
|
36
|
-
InteractionSubmission,
|
|
37
|
-
is_terminal,
|
|
38
|
-
)
|
|
39
|
-
from ksadk.interaction.ledger import (
|
|
40
|
-
ALREADY_RESOLVED,
|
|
41
|
-
REQUEST_CONFLICT,
|
|
42
|
-
REVISION_MISMATCH,
|
|
43
|
-
interaction_event,
|
|
44
|
-
request_digest,
|
|
45
|
-
requested_event_payload,
|
|
46
|
-
resolve_outcome,
|
|
47
|
-
submission_digest,
|
|
48
|
-
)
|
|
49
36
|
from ksadk.kernel.contracts import (
|
|
50
37
|
ActivationLease,
|
|
51
38
|
ActivationWriteGuard,
|
|
@@ -75,15 +62,17 @@ from ksadk.kernel.store import (
|
|
|
75
62
|
now_iso,
|
|
76
63
|
)
|
|
77
64
|
from ksadk.sessions._postgres_tables import (
|
|
65
|
+
_PG_SCHEMA_ADVISORY_LOCK_KEY,
|
|
78
66
|
KSADK_PG_EVENTS_TABLE,
|
|
79
67
|
KSADK_PG_SESSIONS_TABLE,
|
|
80
68
|
)
|
|
81
69
|
from ksadk.sessions.db_budget import budgeted_pool_connection, session_db_budget
|
|
82
70
|
from ksadk.sessions.history_budget import CURRENT_HISTORY_READ_BUDGET
|
|
83
71
|
|
|
84
|
-
from ksadk.kernel.postgres_event_log import PostgresKernelEventLog
|
|
85
|
-
|
|
86
72
|
SCHEMA_PATH = Path(__file__).parent / "sql" / "001_agent_kernel.sql"
|
|
73
|
+
# Stable database-wide migration domain (ASCII KSADKERN). Independent Runtime
|
|
74
|
+
# processes must acquire it before any Kernel DDL.
|
|
75
|
+
_SCHEMA_MIGRATION_LOCK = 0x4B5341444B45524E
|
|
87
76
|
|
|
88
77
|
NONCE_RETENTION_SECONDS = 24 * 3600.0
|
|
89
78
|
|
|
@@ -92,6 +81,7 @@ ACTIVATION_FOR_SHARE_SQL = (
|
|
|
92
81
|
" bundle_digest, capability_digest, agent_instance_id, session_id"
|
|
93
82
|
" FROM kernel_activations"
|
|
94
83
|
" WHERE agent_instance_id = $1 AND session_id = $2"
|
|
84
|
+
" AND (session_namespace=$3 OR session_namespace IS NULL)"
|
|
95
85
|
" FOR SHARE"
|
|
96
86
|
)
|
|
97
87
|
|
|
@@ -100,13 +90,287 @@ def _now() -> datetime:
|
|
|
100
90
|
return datetime.now(timezone.utc)
|
|
101
91
|
|
|
102
92
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
class PostgresKernelEventLog:
|
|
96
|
+
"""把 ``SessionEventEnvelope`` 写进共享 session log(ksadk_events)。
|
|
97
|
+
|
|
98
|
+
``append_on(connection, ...)`` 允许调用方把 event insert 并入一个已经
|
|
99
|
+
打开的 kernel writer 事务;``append`` 则自开事务。
|
|
100
|
+
"""
|
|
101
|
+
|
|
102
|
+
def __init__(
|
|
103
|
+
self,
|
|
104
|
+
pool: Any,
|
|
105
|
+
*,
|
|
106
|
+
namespace: str = "default",
|
|
107
|
+
tenant_id: str = "default",
|
|
108
|
+
workspace_id: str = "default",
|
|
109
|
+
) -> None:
|
|
110
|
+
self._pool = pool
|
|
111
|
+
self._namespace = namespace.strip() or "default"
|
|
112
|
+
self._tenant_id = tenant_id.strip() or "default"
|
|
113
|
+
self._workspace_id = workspace_id.strip() or "default"
|
|
114
|
+
|
|
115
|
+
@asynccontextmanager
|
|
116
|
+
async def _connection(self, *, write: bool = False):
|
|
117
|
+
async with budgeted_pool_connection(
|
|
118
|
+
self._pool, session_db_budget(), write=write,
|
|
119
|
+
) as connection:
|
|
120
|
+
yield connection
|
|
121
|
+
|
|
122
|
+
async def append_on(
|
|
123
|
+
self,
|
|
124
|
+
connection: Any,
|
|
125
|
+
envelope: SessionEventEnvelope,
|
|
126
|
+
guard: Any | None = None,
|
|
127
|
+
) -> SessionEventEnvelope:
|
|
128
|
+
if guard is not None:
|
|
129
|
+
validate_write_guard(envelope, guard)
|
|
130
|
+
if not envelope.session_id.strip():
|
|
131
|
+
raise ValueError("session_id must be nonempty")
|
|
132
|
+
packed = envelope_to_session_event(envelope)
|
|
133
|
+
storage_id = session_event_storage_id(envelope.session_id, str(envelope.event_id))
|
|
134
|
+
# 锁 session 行串行化 seq 分配,与 PostgresSessionService.append_event 相同。
|
|
135
|
+
session_row = await connection.fetchrow(
|
|
136
|
+
f"SELECT id FROM {KSADK_PG_SESSIONS_TABLE} WHERE namespace=$1 AND id=$2 FOR UPDATE",
|
|
137
|
+
self._namespace,
|
|
138
|
+
envelope.session_id,
|
|
139
|
+
)
|
|
140
|
+
if session_row is None:
|
|
141
|
+
raise InvalidCommandError(
|
|
142
|
+
f"session {envelope.session_id!r} does not exist in the shared event log"
|
|
143
|
+
)
|
|
144
|
+
next_seq = await connection.fetchval(
|
|
145
|
+
f"SELECT COALESCE(MAX(seq_id), 0) + 1 FROM {KSADK_PG_EVENTS_TABLE}"
|
|
146
|
+
" WHERE namespace=$1 AND session_id=$2",
|
|
147
|
+
self._namespace,
|
|
148
|
+
envelope.session_id,
|
|
149
|
+
)
|
|
150
|
+
seq = int(next_seq or 1)
|
|
151
|
+
packed.bind_seq_id(seq) # 把物理 seq 绑定回 runtime/session envelope 内容
|
|
152
|
+
inserted = await connection.fetchrow(
|
|
153
|
+
f"""
|
|
154
|
+
INSERT INTO {KSADK_PG_EVENTS_TABLE} (
|
|
155
|
+
namespace, tenant_id, workspace_id, id, session_id, author,
|
|
156
|
+
event_type, content_json, timestamp, state_delta_json,
|
|
157
|
+
seq_id, invocation_id, metadata_json
|
|
158
|
+
) VALUES (
|
|
159
|
+
$1, $2, $3, $4, $5, $6, $7, $8::jsonb, $9,
|
|
160
|
+
'{{}}'::jsonb, $10, $11, $12::jsonb
|
|
161
|
+
)
|
|
162
|
+
ON CONFLICT (namespace, id) DO NOTHING
|
|
163
|
+
RETURNING seq_id, timestamp
|
|
164
|
+
""",
|
|
165
|
+
self._namespace,
|
|
166
|
+
self._tenant_id,
|
|
167
|
+
self._workspace_id,
|
|
168
|
+
storage_id,
|
|
169
|
+
envelope.session_id,
|
|
170
|
+
packed.author,
|
|
171
|
+
packed.event_type,
|
|
172
|
+
json.dumps(packed.content, ensure_ascii=False),
|
|
173
|
+
_timestamp_to_float(envelope.timestamp),
|
|
174
|
+
int(next_seq or 1),
|
|
175
|
+
packed.invocation_id,
|
|
176
|
+
json.dumps(packed.metadata, ensure_ascii=False),
|
|
177
|
+
)
|
|
178
|
+
if inserted is not None:
|
|
179
|
+
# The INSERT has the exact payload already. Returning its small
|
|
180
|
+
# receipt avoids downloading a full graph snapshot again while
|
|
181
|
+
# holding both the session row and activation fence locks.
|
|
182
|
+
packed.bind_seq_id(int(inserted["seq_id"]))
|
|
183
|
+
packed.timestamp = inserted["timestamp"]
|
|
184
|
+
return session_event_to_envelope(packed)
|
|
185
|
+
stored = await self._fetch_event(connection, envelope.session_id, storage_id)
|
|
186
|
+
if stored is not None:
|
|
187
|
+
return stored
|
|
188
|
+
raise RuntimeError("kernel event insert did not persist") # pragma: no cover
|
|
189
|
+
|
|
190
|
+
async def _fetch_event(
|
|
191
|
+
self, connection: Any, session_id: str, storage_id: str
|
|
192
|
+
) -> SessionEventEnvelope | None:
|
|
193
|
+
row = await connection.fetchrow(
|
|
194
|
+
f"SELECT content_json, metadata_json, seq_id, timestamp FROM {KSADK_PG_EVENTS_TABLE}"
|
|
195
|
+
" WHERE namespace=$1 AND session_id=$2 AND id=$3",
|
|
196
|
+
self._namespace,
|
|
197
|
+
session_id,
|
|
198
|
+
storage_id,
|
|
199
|
+
)
|
|
200
|
+
if row is None:
|
|
201
|
+
return None
|
|
202
|
+
from ksadk.sessions.base import SessionEvent
|
|
203
|
+
|
|
204
|
+
event = SessionEvent(
|
|
205
|
+
id=storage_id,
|
|
206
|
+
session_id=session_id,
|
|
207
|
+
author="",
|
|
208
|
+
event_type="",
|
|
209
|
+
content=json.loads(row["content_json"]),
|
|
210
|
+
timestamp=row["timestamp"],
|
|
211
|
+
seq_id=row["seq_id"],
|
|
212
|
+
metadata=json.loads(row["metadata_json"]),
|
|
213
|
+
)
|
|
214
|
+
return session_event_to_envelope(event)
|
|
215
|
+
|
|
216
|
+
async def append(
|
|
217
|
+
self, envelope: SessionEventEnvelope, *, guard: Any | None = None
|
|
218
|
+
) -> SessionEventEnvelope:
|
|
219
|
+
async with self._connection(write=True) as connection:
|
|
220
|
+
async with connection.transaction():
|
|
221
|
+
return await self.append_on(connection, envelope, guard)
|
|
222
|
+
|
|
223
|
+
async def get_by_id(self, session_id: str, event_id: Any) -> SessionEventEnvelope | None:
|
|
224
|
+
storage_id = session_event_storage_id(session_id, str(event_id))
|
|
225
|
+
async with self._connection() as connection:
|
|
226
|
+
return await self._fetch_event(connection, session_id, storage_id)
|
|
227
|
+
|
|
228
|
+
async def get_max_seq_id(self, session_id: str) -> int:
|
|
229
|
+
"""Indexed metadata read; never decode historical event bodies."""
|
|
230
|
+
async with self._connection() as connection:
|
|
231
|
+
return int(await connection.fetchval(
|
|
232
|
+
f"SELECT COALESCE(MAX(seq_id),0) FROM {KSADK_PG_EVENTS_TABLE} "
|
|
233
|
+
"WHERE namespace=$1 AND session_id=$2", self._namespace, session_id,
|
|
234
|
+
) or 0)
|
|
235
|
+
|
|
236
|
+
async def read(self, session_id: str, after_seq: int, limit: int) -> list[SessionEventEnvelope]:
|
|
237
|
+
if limit < 1:
|
|
238
|
+
raise ValueError("limit must be positive")
|
|
239
|
+
async with self._connection() as connection:
|
|
240
|
+
rows = await connection.fetch(
|
|
241
|
+
f"SELECT id, content_json, metadata_json, seq_id, timestamp, author,"
|
|
242
|
+
f" event_type, invocation_id FROM {KSADK_PG_EVENTS_TABLE}"
|
|
243
|
+
" WHERE namespace=$1 AND session_id=$2 AND seq_id > $3"
|
|
244
|
+
" ORDER BY seq_id LIMIT $4",
|
|
245
|
+
self._namespace,
|
|
246
|
+
session_id,
|
|
247
|
+
int(after_seq),
|
|
248
|
+
int(limit),
|
|
249
|
+
)
|
|
250
|
+
return self._decode_rows(session_id, rows)
|
|
251
|
+
|
|
252
|
+
async def read_runtime(
|
|
253
|
+
self, session_id: str, *, after_seq: int = 0, before_seq: int | None = None,
|
|
254
|
+
run_id: str | None = None, event_types: list[str] | None = None,
|
|
255
|
+
item_kinds: list[str] | None = None, scope_id: str | None = None,
|
|
256
|
+
limit: int = 256, newest_first: bool = False,
|
|
257
|
+
) -> list[SessionEventEnvelope]:
|
|
258
|
+
if limit < 1:
|
|
259
|
+
raise ValueError("limit must be positive")
|
|
260
|
+
args: list[Any] = [self._namespace, session_id, after_seq]
|
|
261
|
+
where = ["namespace=$1", "session_id=$2", "seq_id > $3",
|
|
262
|
+
"metadata_json->>'family' = 'runtime'"]
|
|
263
|
+
for clause, value in (("seq_id <", before_seq), ("invocation_id =", run_id),
|
|
264
|
+
("event_type = ANY", event_types),
|
|
265
|
+
("content_json->'runtime_event'->>'item_kind' = ANY", item_kinds),
|
|
266
|
+
("content_json->'runtime_event'->>'scope_id' =", scope_id)):
|
|
267
|
+
if value is not None:
|
|
268
|
+
args.append(value)
|
|
269
|
+
placeholder = f"${len(args)}"
|
|
270
|
+
where.append(f"{clause}({placeholder}::text[])" if clause.endswith("ANY")
|
|
271
|
+
else f"{clause} {placeholder}")
|
|
272
|
+
args.append(limit)
|
|
273
|
+
order = "DESC" if newest_first else "ASC"
|
|
274
|
+
async with self._connection() as connection:
|
|
275
|
+
query = (f"SELECT id, content_json, metadata_json, seq_id, timestamp, author,"
|
|
276
|
+
f" event_type, invocation_id FROM {KSADK_PG_EVENTS_TABLE} WHERE "
|
|
277
|
+
+ " AND ".join(where) + f" ORDER BY seq_id {order} LIMIT ${len(args)}")
|
|
278
|
+
if limit > 32 and event_types is None:
|
|
279
|
+
# Restoring a run still needs every fact. Stream its opaque
|
|
280
|
+
# state through the existing replay budget instead of one
|
|
281
|
+
# potentially multi-MiB ordinary read command.
|
|
282
|
+
from ksadk.sessions.postgres_service import _TimedConnection
|
|
283
|
+
|
|
284
|
+
budget = session_db_budget()
|
|
285
|
+
replay = _TimedConnection(
|
|
286
|
+
connection, budget.read_sql_seconds, budget.cleanup_seconds,
|
|
287
|
+
budget.replay_operation_seconds, budget.replay_sql_seconds,
|
|
288
|
+
)
|
|
289
|
+
rows = await replay.fetch_replay(query, *args, batch_size=1)
|
|
290
|
+
else:
|
|
291
|
+
rows = await connection.fetch(query, *args)
|
|
292
|
+
return self._decode_rows(session_id, rows)
|
|
293
|
+
|
|
294
|
+
async def has_run_transition(self, session_id, run_id, state):
|
|
295
|
+
async with self._connection() as connection:
|
|
296
|
+
return bool(await connection.fetchval(
|
|
297
|
+
f"SELECT EXISTS(SELECT 1 FROM {KSADK_PG_EVENTS_TABLE} "
|
|
298
|
+
"WHERE namespace=$1 AND session_id=$2 AND invocation_id=$3 "
|
|
299
|
+
"AND event_type='control.run_transition' AND metadata_json->>'family'='control' "
|
|
300
|
+
"AND content_json->'session_event'->'payload'->>'state'=$4)",
|
|
301
|
+
self._namespace, session_id, run_id, state))
|
|
302
|
+
|
|
303
|
+
async def find_interaction_resolution(self, record):
|
|
304
|
+
keys = ("interaction_id", "tenant_id", "agent_instance_id", "session_id", "run_id", "kind", "revision")
|
|
305
|
+
args = [self._namespace, record.session_id, record.run_id]
|
|
306
|
+
clauses = ["namespace=$1", "session_id=$2", "invocation_id=$3",
|
|
307
|
+
"event_type='interaction.resolved'", "metadata_json->>'family'='interaction'",
|
|
308
|
+
"metadata_json->>'family_version'='1'"]
|
|
309
|
+
for key in keys:
|
|
310
|
+
args.append(str(getattr(record, key)))
|
|
311
|
+
clauses.append(f"content_json->'session_event'->'payload'->>'{key}'=${len(args)}")
|
|
312
|
+
async with self._connection() as connection:
|
|
313
|
+
rows = await connection.fetch(
|
|
314
|
+
"SELECT id,content_json,metadata_json,seq_id,timestamp,author,event_type,invocation_id "
|
|
315
|
+
f"FROM {KSADK_PG_EVENTS_TABLE} WHERE " + " AND ".join(clauses)
|
|
316
|
+
+ " ORDER BY seq_id LIMIT 1", *args)
|
|
317
|
+
decoded = self._decode_rows(record.session_id, rows)
|
|
318
|
+
return decoded[0] if decoded else None
|
|
319
|
+
|
|
320
|
+
async def read_subscription_page(
|
|
321
|
+
self, session_id: str, after_seq: int, *, limit: int = 64,
|
|
322
|
+
byte_limit: int = 512 * 1024,
|
|
323
|
+
) -> list[SessionEventEnvelope]:
|
|
324
|
+
"""Drain every fact using small byte-bounded subscription batches.
|
|
325
|
+
|
|
326
|
+
Unlike `read`, this may return a short page with more facts remaining.
|
|
327
|
+
One indivisible oversized fact always advances the sequence cursor.
|
|
328
|
+
"""
|
|
329
|
+
if limit < 1 or byte_limit < 1:
|
|
330
|
+
raise ValueError("subscription limits must be positive")
|
|
331
|
+
async with self._connection() as connection:
|
|
332
|
+
rows = await connection.fetch(
|
|
333
|
+
f"""WITH candidates AS (
|
|
334
|
+
SELECT id,content_json,metadata_json,seq_id,timestamp,author,
|
|
335
|
+
event_type,invocation_id,
|
|
336
|
+
COALESCE(octet_length(content_json::text),0) +
|
|
337
|
+
COALESCE(octet_length(metadata_json::text),0) + 1024 AS bytes
|
|
338
|
+
FROM {KSADK_PG_EVENTS_TABLE}
|
|
339
|
+
WHERE namespace=$1 AND session_id=$2 AND seq_id>$3
|
|
340
|
+
ORDER BY seq_id LIMIT $4
|
|
341
|
+
), measured AS (
|
|
342
|
+
SELECT *,ROW_NUMBER() OVER (ORDER BY seq_id) AS position,
|
|
343
|
+
SUM(bytes) OVER (ORDER BY seq_id) AS cumulative_bytes
|
|
344
|
+
FROM candidates
|
|
345
|
+
)
|
|
346
|
+
SELECT id,content_json,metadata_json,seq_id,timestamp,author,
|
|
347
|
+
event_type,invocation_id FROM measured
|
|
348
|
+
WHERE cumulative_bytes <= $5 OR position=1 ORDER BY seq_id""",
|
|
349
|
+
self._namespace, session_id, int(after_seq), limit, byte_limit,
|
|
350
|
+
)
|
|
351
|
+
return self._decode_rows(session_id, rows)
|
|
352
|
+
|
|
353
|
+
@staticmethod
|
|
354
|
+
def _decode_rows(session_id, rows) -> list[SessionEventEnvelope]:
|
|
355
|
+
from ksadk.sessions.base import SessionEvent
|
|
356
|
+
|
|
357
|
+
envelopes: list[SessionEventEnvelope] = []
|
|
358
|
+
for row in rows:
|
|
359
|
+
event = SessionEvent(
|
|
360
|
+
id=row["id"],
|
|
361
|
+
session_id=session_id,
|
|
362
|
+
author=row["author"],
|
|
363
|
+
event_type=row["event_type"],
|
|
364
|
+
content=json.loads(row["content_json"]),
|
|
365
|
+
timestamp=row["timestamp"],
|
|
366
|
+
seq_id=row["seq_id"],
|
|
367
|
+
invocation_id=row["invocation_id"],
|
|
368
|
+
metadata=json.loads(row["metadata_json"]),
|
|
369
|
+
)
|
|
370
|
+
envelope = session_event_to_envelope(event)
|
|
371
|
+
if envelope is not None:
|
|
372
|
+
envelopes.append(envelope)
|
|
373
|
+
return envelopes
|
|
110
374
|
|
|
111
375
|
|
|
112
376
|
class PostgresNonceStore:
|
|
@@ -159,7 +423,10 @@ class PostgresNonceStore:
|
|
|
159
423
|
)
|
|
160
424
|
|
|
161
425
|
|
|
162
|
-
|
|
426
|
+
from ksadk.kernel.interactions_postgres import PostgresInteractionStoreMixin
|
|
427
|
+
|
|
428
|
+
|
|
429
|
+
class PostgresAgentKernelStore(PostgresInteractionStoreMixin, PostgresExecutionGrantMixin):
|
|
163
430
|
def __init__(
|
|
164
431
|
self,
|
|
165
432
|
pool: Any,
|
|
@@ -183,9 +450,43 @@ class PostgresAgentKernelStore(PostgresExecutionGrantMixin):
|
|
|
183
450
|
yield connection
|
|
184
451
|
|
|
185
452
|
async def ensure_schema(self) -> None:
|
|
186
|
-
|
|
453
|
+
from ksadk.kernel.legacy_postgres_repair import repair_legacy_sessions
|
|
454
|
+
from ksadk.sessions._postgres_schema import install_kernel_session_delete_trigger
|
|
455
|
+
|
|
187
456
|
async with self._connection(write=True) as connection:
|
|
188
|
-
|
|
457
|
+
async with connection.transaction():
|
|
458
|
+
await connection.execute(
|
|
459
|
+
"SELECT pg_advisory_xact_lock($1::bigint)", _SCHEMA_MIGRATION_LOCK
|
|
460
|
+
)
|
|
461
|
+
# The last function in 002 was committed atomically with both
|
|
462
|
+
# schemas, including in databases upgraded by the previous wheel.
|
|
463
|
+
state = await connection.fetchrow(f"""
|
|
464
|
+
SELECT to_regprocedure(format('%I.ksadk_after_kernel_session_delete()',
|
|
465
|
+
current_schema())) IS NOT NULL AS migrated,
|
|
466
|
+
to_regclass(format('%I.kernel_legacy_repair_progress',
|
|
467
|
+
current_schema())) IS NOT NULL AS repairs_installed,
|
|
468
|
+
to_regclass('{KSADK_PG_SESSIONS_TABLE}') IS NOT NULL AND NOT EXISTS (
|
|
469
|
+
SELECT FROM pg_trigger
|
|
470
|
+
WHERE tgrelid=to_regclass('{KSADK_PG_SESSIONS_TABLE}')
|
|
471
|
+
AND tgname='ksadk_retire_deleted_session'
|
|
472
|
+
) AS needs_trigger
|
|
473
|
+
""")
|
|
474
|
+
if not state["migrated"] or state["needs_trigger"]:
|
|
475
|
+
await connection.execute(
|
|
476
|
+
"SELECT pg_advisory_xact_lock($1::bigint)", _PG_SCHEMA_ADVISORY_LOCK_KEY
|
|
477
|
+
)
|
|
478
|
+
if not state["migrated"]:
|
|
479
|
+
await connection.execute(SCHEMA_PATH.read_text(encoding="utf-8"))
|
|
480
|
+
retirement = SCHEMA_PATH.with_name("002_session_retirement.sql")
|
|
481
|
+
await connection.execute(retirement.read_text(encoding="utf-8"))
|
|
482
|
+
await install_kernel_session_delete_trigger(connection)
|
|
483
|
+
|
|
484
|
+
if not state["repairs_installed"]:
|
|
485
|
+
for migration in ("003_legacy_repair_queue.sql", "backfill_session_namespaces.sql"):
|
|
486
|
+
await connection.execute(SCHEMA_PATH.with_name(migration).read_text(encoding="utf-8"))
|
|
487
|
+
|
|
488
|
+
# Data repair must never hold either database-wide DDL lock.
|
|
489
|
+
await repair_legacy_sessions(self._connection, self.tenant_id, self._events._namespace)
|
|
189
490
|
|
|
190
491
|
async def reset_for_tests(self) -> None:
|
|
191
492
|
async with self._connection(write=True) as connection:
|
|
@@ -193,6 +494,7 @@ class PostgresAgentKernelStore(PostgresExecutionGrantMixin):
|
|
|
193
494
|
"DELETE FROM kernel_inbox; DELETE FROM kernel_runs;"
|
|
194
495
|
" DELETE FROM kernel_activations; DELETE FROM kernel_accepted_seq;"
|
|
195
496
|
" DELETE FROM kernel_interactions; DELETE FROM kernel_interaction_submissions;"
|
|
497
|
+
" DELETE FROM kernel_legacy_session_repairs;"
|
|
196
498
|
" DELETE FROM kernel_execution_grant_operations;"
|
|
197
499
|
" DELETE FROM kernel_execution_grants;"
|
|
198
500
|
" DELETE FROM ksadk_events WHERE namespace = 'default';"
|
|
@@ -212,7 +514,7 @@ class PostgresAgentKernelStore(PostgresExecutionGrantMixin):
|
|
|
212
514
|
# Lease expiry is authored by PostgreSQL. Never compare it with a Pod's
|
|
213
515
|
# wall clock: skew can reject a live owner or authorize an expired one.
|
|
214
516
|
row = await connection.fetchrow(
|
|
215
|
-
ACTIVATION_FOR_SHARE_SQL, agent_instance_id, session_id
|
|
517
|
+
ACTIVATION_FOR_SHARE_SQL, agent_instance_id, session_id, self._events._namespace
|
|
216
518
|
)
|
|
217
519
|
if (
|
|
218
520
|
row is None
|
|
@@ -249,10 +551,10 @@ class PostgresAgentKernelStore(PostgresExecutionGrantMixin):
|
|
|
249
551
|
|
|
250
552
|
async def _append_admission(
|
|
251
553
|
self, connection: Any, command: AgentControlCommand, envelope: SessionEventEnvelope
|
|
252
|
-
) ->
|
|
554
|
+
) -> SessionEventEnvelope:
|
|
253
555
|
# accepted/rejected 事实的 write guard 绑定提交方的 permit 引用
|
|
254
556
|
# (server permit_id 或本地 authority),不落内核自造 ref。
|
|
255
|
-
await self._events.append_on(
|
|
557
|
+
return await self._events.append_on(
|
|
256
558
|
connection,
|
|
257
559
|
envelope,
|
|
258
560
|
AdmissionWriteGuard(
|
|
@@ -287,8 +589,24 @@ class PostgresAgentKernelStore(PostgresExecutionGrantMixin):
|
|
|
287
589
|
async with connection.transaction():
|
|
288
590
|
if execution_grant_id(command):
|
|
289
591
|
await self._postgres_lock_command_grant(connection, command)
|
|
592
|
+
# Serialize admission before reading idempotency/queue depth.
|
|
593
|
+
# Locking only during sequence allocation lets concurrent
|
|
594
|
+
# writers both observe a missing key or the same free slot.
|
|
595
|
+
# Keep the existing grant -> cursor -> event lock order.
|
|
596
|
+
await connection.execute(
|
|
597
|
+
"INSERT INTO kernel_accepted_seq (tenant_id, session_id, last_seq)"
|
|
598
|
+
" VALUES ($1, $2, 0) ON CONFLICT (tenant_id, session_id) DO NOTHING",
|
|
599
|
+
self.tenant_id,
|
|
600
|
+
command.session_id,
|
|
601
|
+
)
|
|
602
|
+
await connection.fetchval(
|
|
603
|
+
"SELECT last_seq FROM kernel_accepted_seq"
|
|
604
|
+
" WHERE tenant_id=$1 AND session_id=$2 FOR UPDATE",
|
|
605
|
+
self.tenant_id,
|
|
606
|
+
command.session_id,
|
|
607
|
+
)
|
|
290
608
|
existing = await connection.fetchrow(
|
|
291
|
-
"SELECT message_id, accepted_seq, request_digest FROM kernel_inbox"
|
|
609
|
+
"SELECT message_id, accepted_seq, request_digest, payload FROM kernel_inbox"
|
|
292
610
|
" WHERE tenant_id=$1 AND session_id=$2 AND idempotency_key=$3",
|
|
293
611
|
self.tenant_id,
|
|
294
612
|
command.session_id,
|
|
@@ -322,7 +640,7 @@ class PostgresAgentKernelStore(PostgresExecutionGrantMixin):
|
|
|
322
640
|
),
|
|
323
641
|
)
|
|
324
642
|
return self._receipt(
|
|
325
|
-
|
|
643
|
+
AgentControlCommand.model_validate_json(existing["payload"]),
|
|
326
644
|
"duplicate",
|
|
327
645
|
message_id=str(existing["message_id"]),
|
|
328
646
|
accepted_seq=int(existing["accepted_seq"]),
|
|
@@ -399,8 +717,8 @@ class PostgresAgentKernelStore(PostgresExecutionGrantMixin):
|
|
|
399
717
|
await connection.execute(
|
|
400
718
|
"INSERT INTO kernel_inbox (message_id, tenant_id, agent_instance_id,"
|
|
401
719
|
" session_id, idempotency_key, request_digest, accepted_seq, status,"
|
|
402
|
-
" claimed_fence, payload) VALUES ($1::uuid, $2, $3, $4, $5, $6, $7,"
|
|
403
|
-
" 'accepted', NULL, $8::jsonb)",
|
|
720
|
+
" claimed_fence, payload, session_namespace) VALUES ($1::uuid, $2, $3, $4, $5, $6, $7,"
|
|
721
|
+
" 'accepted', NULL, $8::jsonb, $9)",
|
|
404
722
|
message_id,
|
|
405
723
|
self.tenant_id,
|
|
406
724
|
command.agent_instance_id,
|
|
@@ -409,9 +727,10 @@ class PostgresAgentKernelStore(PostgresExecutionGrantMixin):
|
|
|
409
727
|
command_digest(command),
|
|
410
728
|
accepted_seq,
|
|
411
729
|
command.model_dump_json(),
|
|
730
|
+
self._events._namespace,
|
|
412
731
|
)
|
|
413
732
|
# ControlEvent 与 inbox insert 同一事务(SQLite 版在事务外,此处按计划收进)。
|
|
414
|
-
await self._append_admission(
|
|
733
|
+
admitted = await self._append_admission(
|
|
415
734
|
connection,
|
|
416
735
|
command,
|
|
417
736
|
control_event(
|
|
@@ -427,6 +746,12 @@ class PostgresAgentKernelStore(PostgresExecutionGrantMixin):
|
|
|
427
746
|
causation_id=str(command.command_id),
|
|
428
747
|
),
|
|
429
748
|
)
|
|
749
|
+
accepted_seq = admitted.seq
|
|
750
|
+
await connection.execute(
|
|
751
|
+
"UPDATE kernel_inbox SET accepted_seq=$1"
|
|
752
|
+
" WHERE tenant_id=$2 AND message_id=$3::uuid",
|
|
753
|
+
accepted_seq, self.tenant_id, message_id,
|
|
754
|
+
)
|
|
430
755
|
return self._receipt(
|
|
431
756
|
command, "accepted", message_id=message_id, accepted_seq=accepted_seq
|
|
432
757
|
)
|
|
@@ -549,6 +874,95 @@ class PostgresAgentKernelStore(PostgresExecutionGrantMixin):
|
|
|
549
874
|
)
|
|
550
875
|
return [m for m in (self._row_to_message(r) for r in rows) if m is not None]
|
|
551
876
|
|
|
877
|
+
async def pending_session_ids(self, agent_instance_id: str) -> set[str]:
|
|
878
|
+
"""Scheduler metadata only: no completed command payloads or N+1 reads."""
|
|
879
|
+
async with self._connection() as connection:
|
|
880
|
+
rows = await connection.fetch(
|
|
881
|
+
f"""
|
|
882
|
+
WITH candidates AS (
|
|
883
|
+
SELECT session_id, session_namespace, false AS needs_missing FROM kernel_inbox
|
|
884
|
+
WHERE agent_instance_id=$1 AND tenant_id=$2 AND status IN ('accepted','claimed')
|
|
885
|
+
UNION ALL
|
|
886
|
+
SELECT r.session_id, r.session_namespace, r.state='pending' OR NOT EXISTS (
|
|
887
|
+
SELECT FROM kernel_inbox i WHERE i.agent_instance_id=$1 AND i.tenant_id=$2
|
|
888
|
+
AND i.session_id=r.session_id AND (i.session_namespace=$3 OR i.session_namespace IS NULL)
|
|
889
|
+
) FROM kernel_runs r WHERE r.agent_instance_id=$1 AND r.tenant_id=$2
|
|
890
|
+
AND r.state IN ('pending','running','paused','waiting')
|
|
891
|
+
UNION ALL
|
|
892
|
+
SELECT session_id, session_namespace, true FROM kernel_interactions
|
|
893
|
+
WHERE agent_instance_id=$1 AND status IN ('pending','resolving')
|
|
894
|
+
AND (session_namespace=$3 OR (session_namespace IS NULL AND tenant_id=$2))
|
|
895
|
+
)
|
|
896
|
+
SELECT DISTINCT c.session_id FROM candidates c
|
|
897
|
+
LEFT JOIN {KSADK_PG_SESSIONS_TABLE} s ON s.namespace=$3 AND s.id=c.session_id
|
|
898
|
+
WHERE (NOT c.needs_missing OR s.id IS NULL)
|
|
899
|
+
AND (c.session_namespace=$3 OR (c.session_namespace IS NULL AND (
|
|
900
|
+
s.id IS NOT NULL OR NOT EXISTS (
|
|
901
|
+
SELECT FROM {KSADK_PG_SESSIONS_TABLE} other
|
|
902
|
+
WHERE other.id=c.session_id AND other.tenant_id=$2 AND other.namespace<>$3
|
|
903
|
+
)
|
|
904
|
+
)))
|
|
905
|
+
""",
|
|
906
|
+
agent_instance_id, self.tenant_id, self._events._namespace,
|
|
907
|
+
)
|
|
908
|
+
return {row["session_id"] for row in rows}
|
|
909
|
+
|
|
910
|
+
async def is_session_missing(self, session_id: str) -> bool:
|
|
911
|
+
async with self._connection() as connection:
|
|
912
|
+
return not await connection.fetchval(
|
|
913
|
+
f"SELECT 1 FROM {KSADK_PG_SESSIONS_TABLE} WHERE namespace=$1 AND id=$2",
|
|
914
|
+
self._events._namespace, session_id,
|
|
915
|
+
)
|
|
916
|
+
|
|
917
|
+
async def read_runtime_leases(
|
|
918
|
+
self, agent_instance_id: str, session_ids: list[str],
|
|
919
|
+
) -> dict[str, ActivationLease]:
|
|
920
|
+
"""One real DB round trip for reachability and every retained fence."""
|
|
921
|
+
async with self._connection() as connection:
|
|
922
|
+
rows = await connection.fetch(
|
|
923
|
+
"SELECT session_id,activation_id,fencing_token,lease_expires_at,"
|
|
924
|
+
"bundle_digest,runtime_type,capability_digest FROM kernel_activations "
|
|
925
|
+
"WHERE agent_instance_id=$1 AND session_id=ANY($2::text[]) "
|
|
926
|
+
"AND released=FALSE AND lease_expires_at>clock_timestamp()",
|
|
927
|
+
agent_instance_id, session_ids,
|
|
928
|
+
)
|
|
929
|
+
return {row["session_id"]: ActivationLease(
|
|
930
|
+
agent_instance_id=agent_instance_id, activation_id=row["activation_id"],
|
|
931
|
+
fencing_token=int(row["fencing_token"]),
|
|
932
|
+
lease_expires_at=row["lease_expires_at"].isoformat(),
|
|
933
|
+
bundle_digest=row["bundle_digest"], runtime_type=row["runtime_type"],
|
|
934
|
+
capability_digest=row["capability_digest"],
|
|
935
|
+
) for row in rows}
|
|
936
|
+
|
|
937
|
+
async def renew_owned_activations(
|
|
938
|
+
self, agent_instance_id: str, owned: dict[str, tuple[str, int]], *,
|
|
939
|
+
lease_ttl_seconds: float,
|
|
940
|
+
) -> set[str]:
|
|
941
|
+
"""Renew valid leases in one statement, retaining owner/fence checks.
|
|
942
|
+
|
|
943
|
+
Expired, released or foreign leases are never revived by this port;
|
|
944
|
+
they retain the ordinary acquire/takeover/recovery path.
|
|
945
|
+
"""
|
|
946
|
+
if not math.isfinite(lease_ttl_seconds) or lease_ttl_seconds <= 0:
|
|
947
|
+
raise ValueError("lease TTL must be positive finite seconds")
|
|
948
|
+
if not owned:
|
|
949
|
+
return set()
|
|
950
|
+
sessions = list(owned)
|
|
951
|
+
async with self._connection(write=True) as connection:
|
|
952
|
+
rows = await connection.fetch(
|
|
953
|
+
"WITH requested AS (SELECT * FROM UNNEST($2::text[],$3::text[],$4::bigint[]) "
|
|
954
|
+
"AS r(session_id,activation_id,fencing_token)) "
|
|
955
|
+
"UPDATE kernel_activations a SET lease_expires_at="
|
|
956
|
+
"clock_timestamp()+$5::double precision*interval '1 second' "
|
|
957
|
+
"FROM requested r WHERE a.agent_instance_id=$1 "
|
|
958
|
+
"AND a.session_id=r.session_id AND a.activation_id=r.activation_id "
|
|
959
|
+
"AND a.fencing_token=r.fencing_token AND a.released=FALSE "
|
|
960
|
+
"AND a.lease_expires_at>clock_timestamp() RETURNING a.session_id",
|
|
961
|
+
agent_instance_id, sessions, [owned[s][0] for s in sessions],
|
|
962
|
+
[owned[s][1] for s in sessions], lease_ttl_seconds,
|
|
963
|
+
)
|
|
964
|
+
return {row["session_id"] for row in rows}
|
|
965
|
+
|
|
552
966
|
async def list_pending(
|
|
553
967
|
self,
|
|
554
968
|
agent_instance_id: str,
|
|
@@ -563,8 +977,9 @@ class PostgresAgentKernelStore(PostgresExecutionGrantMixin):
|
|
|
563
977
|
恰好在 claim 后退出,会让 stale claimed 永久挡住 FIFO 头。
|
|
564
978
|
"""
|
|
565
979
|
sql = (
|
|
566
|
-
"SELECT * FROM kernel_inbox WHERE agent_instance_id=$1"
|
|
567
|
-
|
|
980
|
+
"SELECT * FROM kernel_inbox WHERE agent_instance_id=$1 AND tenant_id=$2"
|
|
981
|
+
" AND (session_namespace=$3 OR session_namespace IS NULL)"
|
|
982
|
+
+ (" AND session_id=$4" if session_id else "")
|
|
568
983
|
+ (
|
|
569
984
|
" AND status IN ('accepted','claimed')"
|
|
570
985
|
if fencing_token is not None
|
|
@@ -572,7 +987,7 @@ class PostgresAgentKernelStore(PostgresExecutionGrantMixin):
|
|
|
572
987
|
)
|
|
573
988
|
+ " ORDER BY accepted_seq"
|
|
574
989
|
)
|
|
575
|
-
args: list[Any] = [agent_instance_id]
|
|
990
|
+
args: list[Any] = [agent_instance_id, self.tenant_id, self._events._namespace]
|
|
576
991
|
if session_id:
|
|
577
992
|
args.append(session_id)
|
|
578
993
|
async with self._connection() as connection:
|
|
@@ -586,7 +1001,9 @@ class PostgresAgentKernelStore(PostgresExecutionGrantMixin):
|
|
|
586
1001
|
async with connection.transaction():
|
|
587
1002
|
# Lock grant before Inbox, matching the revocation lock order.
|
|
588
1003
|
candidate = await connection.fetchrow(
|
|
589
|
-
"SELECT payload FROM kernel_inbox WHERE message_id=$1::uuid"
|
|
1004
|
+
"SELECT payload FROM kernel_inbox WHERE message_id=$1::uuid AND tenant_id=$2"
|
|
1005
|
+
" AND (session_namespace=$3 OR session_namespace IS NULL)",
|
|
1006
|
+
message_id, self.tenant_id, self._events._namespace,
|
|
590
1007
|
)
|
|
591
1008
|
if candidate is None:
|
|
592
1009
|
raise InvalidCommandError(f"unknown message_id {message_id!r}")
|
|
@@ -628,12 +1045,14 @@ class PostgresAgentKernelStore(PostgresExecutionGrantMixin):
|
|
|
628
1045
|
"SELECT EXISTS (SELECT 1 FROM kernel_inbox"
|
|
629
1046
|
" WHERE tenant_id=$1 AND agent_instance_id=$2"
|
|
630
1047
|
" AND session_id=$3 AND accepted_seq < $4"
|
|
1048
|
+
" AND (session_namespace=$5 OR session_namespace IS NULL)"
|
|
631
1049
|
" AND status IN ('accepted','claimed')"
|
|
632
1050
|
" AND payload->>'command_type'='enqueue')",
|
|
633
1051
|
self.tenant_id,
|
|
634
1052
|
row["agent_instance_id"],
|
|
635
1053
|
row["session_id"],
|
|
636
1054
|
int(row["accepted_seq"]),
|
|
1055
|
+
self._events._namespace,
|
|
637
1056
|
)
|
|
638
1057
|
if earlier:
|
|
639
1058
|
raise InvalidCommandError(
|
|
@@ -726,16 +1145,16 @@ class PostgresAgentKernelStore(PostgresExecutionGrantMixin):
|
|
|
726
1145
|
self, agent_instance_id: str, session_id: str | None = None
|
|
727
1146
|
) -> RunRecord | None:
|
|
728
1147
|
async with self._connection() as connection:
|
|
729
|
-
|
|
730
|
-
"SELECT * FROM kernel_runs WHERE agent_instance_id=$1"
|
|
731
|
-
|
|
732
|
-
+ "
|
|
733
|
-
|
|
1148
|
+
row = await connection.fetchrow(
|
|
1149
|
+
"SELECT * FROM kernel_runs WHERE agent_instance_id=$1 AND tenant_id=$2"
|
|
1150
|
+
" AND (session_namespace=$3 OR session_namespace IS NULL)"
|
|
1151
|
+
+ (" AND session_id=$4" if session_id else "")
|
|
1152
|
+
+ " AND state IN ('running','paused','waiting') ORDER BY created_at LIMIT 1",
|
|
1153
|
+
agent_instance_id, self.tenant_id, self._events._namespace,
|
|
734
1154
|
*([session_id] if session_id else []),
|
|
735
1155
|
)
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
return RunRecord(
|
|
1156
|
+
if row is not None:
|
|
1157
|
+
return RunRecord(
|
|
739
1158
|
run_id=row["run_id"],
|
|
740
1159
|
agent_instance_id=row["agent_instance_id"],
|
|
741
1160
|
session_id=row["session_id"],
|
|
@@ -744,7 +1163,7 @@ class PostgresAgentKernelStore(PostgresExecutionGrantMixin):
|
|
|
744
1163
|
created_at=row["created_at"].isoformat(),
|
|
745
1164
|
updated_at=row["updated_at"].isoformat(),
|
|
746
1165
|
metadata=json.loads(row["metadata"]),
|
|
747
|
-
|
|
1166
|
+
)
|
|
748
1167
|
return None
|
|
749
1168
|
|
|
750
1169
|
async def current_lease(
|
|
@@ -782,6 +1201,7 @@ class PostgresAgentKernelStore(PostgresExecutionGrantMixin):
|
|
|
782
1201
|
row = await connection.fetchrow(
|
|
783
1202
|
"SELECT * FROM kernel_inbox"
|
|
784
1203
|
" WHERE agent_instance_id=$1 AND session_id=$2"
|
|
1204
|
+
" AND tenant_id=$4 AND (session_namespace=$5 OR session_namespace IS NULL)"
|
|
785
1205
|
" AND (status='accepted' OR (status='claimed' AND claimed_fence <> $3))"
|
|
786
1206
|
" ORDER BY accepted_seq"
|
|
787
1207
|
" FOR UPDATE SKIP LOCKED"
|
|
@@ -789,6 +1209,7 @@ class PostgresAgentKernelStore(PostgresExecutionGrantMixin):
|
|
|
789
1209
|
agent_instance_id,
|
|
790
1210
|
session_id,
|
|
791
1211
|
int(fencing_token),
|
|
1212
|
+
self.tenant_id, self._events._namespace,
|
|
792
1213
|
)
|
|
793
1214
|
if row is None:
|
|
794
1215
|
return None
|
|
@@ -855,465 +1276,25 @@ class PostgresAgentKernelStore(PostgresExecutionGrantMixin):
|
|
|
855
1276
|
expected_fence,
|
|
856
1277
|
)
|
|
857
1278
|
|
|
858
|
-
# -------------------------------------------------------------- interactions
|
|
859
|
-
|
|
860
|
-
async def _assert_interaction_guard(
|
|
861
|
-
self, connection: Any, agent_instance_id: str, session_id: str, guard: Any
|
|
862
|
-
) -> dict[str, Any]:
|
|
863
|
-
row = await connection.fetchrow(
|
|
864
|
-
"SELECT activation_id, agent_instance_id, session_id, fencing_token,"
|
|
865
|
-
" lease_expires_at, released FROM kernel_activations"
|
|
866
|
-
" WHERE activation_id = $1 AND agent_instance_id = $2"
|
|
867
|
-
" AND session_id = $3 FOR SHARE",
|
|
868
|
-
guard.activation_id,
|
|
869
|
-
agent_instance_id,
|
|
870
|
-
session_id,
|
|
871
|
-
)
|
|
872
|
-
if (
|
|
873
|
-
row is None
|
|
874
|
-
or row["released"]
|
|
875
|
-
or row["lease_expires_at"] <= await connection.fetchval("SELECT clock_timestamp()")
|
|
876
|
-
or int(row["fencing_token"]) != int(guard.fencing_token)
|
|
877
|
-
or row["agent_instance_id"] != agent_instance_id
|
|
878
|
-
or row["session_id"] != session_id
|
|
879
|
-
):
|
|
880
|
-
raise StaleFenceError(
|
|
881
|
-
"interaction write guard does not match the current lease",
|
|
882
|
-
details={
|
|
883
|
-
"activation_id": guard.activation_id,
|
|
884
|
-
"fencing_token": int(guard.fencing_token),
|
|
885
|
-
"session_id": session_id,
|
|
886
|
-
},
|
|
887
|
-
)
|
|
888
|
-
return dict(row)
|
|
889
|
-
|
|
890
|
-
async def _interaction_row_for_guard(
|
|
891
|
-
self, connection: Any, interaction_id: str, guard: Any
|
|
892
|
-
) -> Any | None:
|
|
893
|
-
"""Resolve a public interaction id within its fenced activation scope.
|
|
894
|
-
|
|
895
|
-
Interaction ids are opaque browser-visible handles, not tenant grants.
|
|
896
|
-
A Runtime mutation already has the Server-admitted activation guard, so
|
|
897
|
-
select the row by that trusted AgentInstance/session before taking the
|
|
898
|
-
row lock. This prevents a same-id record in another tenant from being
|
|
899
|
-
selected and then rejected only after information has been consulted.
|
|
900
|
-
"""
|
|
901
|
-
|
|
902
|
-
activation = await connection.fetchrow(
|
|
903
|
-
"SELECT activation_id, agent_instance_id, session_id, fencing_token,"
|
|
904
|
-
" lease_expires_at, released FROM kernel_activations"
|
|
905
|
-
" WHERE activation_id=$1 FOR SHARE",
|
|
906
|
-
guard.activation_id,
|
|
907
|
-
)
|
|
908
|
-
if (
|
|
909
|
-
activation is None
|
|
910
|
-
or activation["released"]
|
|
911
|
-
or activation["lease_expires_at"] <= await connection.fetchval(
|
|
912
|
-
"SELECT clock_timestamp()"
|
|
913
|
-
)
|
|
914
|
-
or int(activation["fencing_token"]) != int(guard.fencing_token)
|
|
915
|
-
):
|
|
916
|
-
raise StaleFenceError(
|
|
917
|
-
"interaction write guard does not match the current lease",
|
|
918
|
-
details={
|
|
919
|
-
"activation_id": guard.activation_id,
|
|
920
|
-
"fencing_token": int(guard.fencing_token),
|
|
921
|
-
},
|
|
922
|
-
)
|
|
923
|
-
return await connection.fetchrow(
|
|
924
|
-
"SELECT * FROM kernel_interactions WHERE interaction_id=$1"
|
|
925
|
-
" AND agent_instance_id=$2 AND session_id=$3 FOR UPDATE",
|
|
926
|
-
interaction_id,
|
|
927
|
-
activation["agent_instance_id"],
|
|
928
|
-
activation["session_id"],
|
|
929
|
-
)
|
|
930
|
-
|
|
931
|
-
@staticmethod
|
|
932
|
-
def _interaction_row_to_record(row: Any) -> InteractionRecord:
|
|
933
|
-
from ksadk.interaction.contracts import InteractionPresentation
|
|
934
|
-
|
|
935
|
-
presentation = None
|
|
936
|
-
if row["presentation"] is not None:
|
|
937
|
-
presentation = InteractionPresentation.model_validate(
|
|
938
|
-
json.loads(row["presentation"])
|
|
939
|
-
)
|
|
940
|
-
return InteractionRecord(
|
|
941
|
-
interaction_id=row["interaction_id"],
|
|
942
|
-
tenant_id=row["tenant_id"],
|
|
943
|
-
agent_instance_id=row["agent_instance_id"],
|
|
944
|
-
session_id=row["session_id"],
|
|
945
|
-
run_id=row["run_id"],
|
|
946
|
-
kind=row["kind"],
|
|
947
|
-
request_schema=json.loads(row["request_schema"]),
|
|
948
|
-
revision=int(row["revision"]),
|
|
949
|
-
status=row["status"],
|
|
950
|
-
created_at=row["created_at"].isoformat(),
|
|
951
|
-
expires_at=(
|
|
952
|
-
row["expires_at"].isoformat() if row["expires_at"] is not None else None
|
|
953
|
-
),
|
|
954
|
-
presentation=presentation,
|
|
955
|
-
provider_id=row["provider_id"] or "",
|
|
956
|
-
native_target=(
|
|
957
|
-
json.loads(row["native_target"])
|
|
958
|
-
if row["native_target"] is not None
|
|
959
|
-
else None
|
|
960
|
-
),
|
|
961
|
-
continuation_metadata=(
|
|
962
|
-
json.loads(row["continuation_metadata"])
|
|
963
|
-
if row["continuation_metadata"] is not None
|
|
964
|
-
else None
|
|
965
|
-
),
|
|
966
|
-
)
|
|
967
|
-
|
|
968
|
-
async def request(
|
|
969
|
-
self, record: InteractionRecord, *, guard: Any
|
|
970
|
-
) -> InteractionRecord:
|
|
971
|
-
digest = request_digest(record)
|
|
972
|
-
async with self._connection(write=True) as connection:
|
|
973
|
-
async with connection.transaction():
|
|
974
|
-
await self._assert_interaction_guard(
|
|
975
|
-
connection, record.agent_instance_id, record.session_id, guard
|
|
976
|
-
)
|
|
977
|
-
existing = await connection.fetchrow(
|
|
978
|
-
"SELECT * FROM kernel_interactions"
|
|
979
|
-
" WHERE tenant_id=$1 AND interaction_id=$2",
|
|
980
|
-
record.tenant_id,
|
|
981
|
-
record.interaction_id,
|
|
982
|
-
)
|
|
983
|
-
if existing is not None:
|
|
984
|
-
if existing["request_digest"] != digest:
|
|
985
|
-
raise InvalidCommandError(
|
|
986
|
-
"interaction_id reused with a different request digest",
|
|
987
|
-
details={
|
|
988
|
-
"reason": REQUEST_CONFLICT,
|
|
989
|
-
"interaction_id": record.interaction_id,
|
|
990
|
-
},
|
|
991
|
-
)
|
|
992
|
-
return self._interaction_row_to_record(existing)
|
|
993
|
-
await connection.execute(
|
|
994
|
-
"""
|
|
995
|
-
INSERT INTO kernel_interactions (
|
|
996
|
-
interaction_id, tenant_id, agent_instance_id, session_id,
|
|
997
|
-
run_id, kind, request_schema, presentation, revision, status,
|
|
998
|
-
created_at, expires_at, provider_id, native_target,
|
|
999
|
-
continuation_metadata, request_digest, updated_at
|
|
1000
|
-
) VALUES (
|
|
1001
|
-
$1, $2, $3, $4, $5, $6, $7::jsonb, $8::jsonb, $9, 'pending',
|
|
1002
|
-
$10::timestamptz, $11::timestamptz, $12, $13::jsonb,
|
|
1003
|
-
$14::jsonb, $15, now()
|
|
1004
|
-
)
|
|
1005
|
-
""",
|
|
1006
|
-
record.interaction_id,
|
|
1007
|
-
record.tenant_id,
|
|
1008
|
-
record.agent_instance_id,
|
|
1009
|
-
record.session_id,
|
|
1010
|
-
record.run_id,
|
|
1011
|
-
record.kind,
|
|
1012
|
-
json.dumps(record.request_schema, ensure_ascii=False),
|
|
1013
|
-
(
|
|
1014
|
-
record.presentation.model_dump_json()
|
|
1015
|
-
if record.presentation is not None
|
|
1016
|
-
else None
|
|
1017
|
-
),
|
|
1018
|
-
record.revision,
|
|
1019
|
-
_parse_ts(record.created_at),
|
|
1020
|
-
_parse_ts(record.expires_at),
|
|
1021
|
-
record.provider_id,
|
|
1022
|
-
(
|
|
1023
|
-
json.dumps(record.native_target, ensure_ascii=False)
|
|
1024
|
-
if record.native_target is not None
|
|
1025
|
-
else None
|
|
1026
|
-
),
|
|
1027
|
-
(
|
|
1028
|
-
json.dumps(record.continuation_metadata, ensure_ascii=False)
|
|
1029
|
-
if record.continuation_metadata is not None
|
|
1030
|
-
else None
|
|
1031
|
-
),
|
|
1032
|
-
digest,
|
|
1033
|
-
)
|
|
1034
|
-
# requested 事件与 pending 行同一事务:commit 前被 kill 无半状态。
|
|
1035
|
-
await self._events.append_on(
|
|
1036
|
-
connection, requested_event_payload(record, now_iso()), guard
|
|
1037
|
-
)
|
|
1038
|
-
return record
|
|
1039
|
-
|
|
1040
|
-
async def resolve(
|
|
1041
|
-
self, submission: InteractionSubmission, *, guard: Any
|
|
1042
|
-
) -> InteractionReceipt:
|
|
1043
|
-
sub_digest = submission_digest(submission)
|
|
1044
|
-
async with self._connection(write=True) as connection:
|
|
1045
|
-
async with connection.transaction():
|
|
1046
|
-
row = await self._interaction_row_for_guard(
|
|
1047
|
-
connection, submission.interaction_id, guard
|
|
1048
|
-
)
|
|
1049
|
-
if row is None:
|
|
1050
|
-
raise InvalidCommandError(
|
|
1051
|
-
f"unknown interaction_id {submission.interaction_id!r}"
|
|
1052
|
-
)
|
|
1053
|
-
await self._assert_interaction_guard(
|
|
1054
|
-
connection, row["agent_instance_id"], row["session_id"], guard
|
|
1055
|
-
)
|
|
1056
|
-
current = self._interaction_row_to_record(row)
|
|
1057
|
-
if is_terminal(current.status):
|
|
1058
|
-
existing_sub = await connection.fetchrow(
|
|
1059
|
-
"SELECT submission_digest, receipt FROM"
|
|
1060
|
-
" kernel_interaction_submissions WHERE tenant_id=$1"
|
|
1061
|
-
" AND interaction_id=$2 AND idempotency_key=$3",
|
|
1062
|
-
current.tenant_id,
|
|
1063
|
-
current.interaction_id,
|
|
1064
|
-
submission.idempotency_key,
|
|
1065
|
-
)
|
|
1066
|
-
if (
|
|
1067
|
-
existing_sub is not None
|
|
1068
|
-
and existing_sub["submission_digest"] == sub_digest
|
|
1069
|
-
):
|
|
1070
|
-
return InteractionReceipt.model_validate(
|
|
1071
|
-
json.loads(existing_sub["receipt"])
|
|
1072
|
-
)
|
|
1073
|
-
raise InvalidCommandError(
|
|
1074
|
-
f"interaction already reached terminal status"
|
|
1075
|
-
f" {current.status!r}",
|
|
1076
|
-
details={
|
|
1077
|
-
"reason": ALREADY_RESOLVED,
|
|
1078
|
-
"interaction_id": current.interaction_id,
|
|
1079
|
-
},
|
|
1080
|
-
)
|
|
1081
|
-
if current.revision != submission.expected_revision:
|
|
1082
|
-
raise InvalidCommandError(
|
|
1083
|
-
"interaction revision does not match expected_revision",
|
|
1084
|
-
details={
|
|
1085
|
-
"reason": REVISION_MISMATCH,
|
|
1086
|
-
"interaction_id": current.interaction_id,
|
|
1087
|
-
"expected_revision": submission.expected_revision,
|
|
1088
|
-
"current_revision": current.revision,
|
|
1089
|
-
},
|
|
1090
|
-
)
|
|
1091
|
-
outcome = resolve_outcome(submission.action)
|
|
1092
|
-
updated = current.model_copy(
|
|
1093
|
-
update={"status": "resolved", "revision": current.revision + 1}
|
|
1094
|
-
)
|
|
1095
|
-
stored = await self._events.append_on(
|
|
1096
|
-
connection,
|
|
1097
|
-
interaction_event(
|
|
1098
|
-
updated,
|
|
1099
|
-
event_type="interaction.resolved",
|
|
1100
|
-
timestamp=now_iso(),
|
|
1101
|
-
outcome=outcome,
|
|
1102
|
-
response=submission.response,
|
|
1103
|
-
actor_ref="user",
|
|
1104
|
-
),
|
|
1105
|
-
guard,
|
|
1106
|
-
)
|
|
1107
|
-
receipt = InteractionReceipt(
|
|
1108
|
-
interaction_id=updated.interaction_id,
|
|
1109
|
-
revision=updated.revision,
|
|
1110
|
-
status="resolved",
|
|
1111
|
-
outcome=outcome, # type: ignore[arg-type]
|
|
1112
|
-
event_id=str(stored.event_id),
|
|
1113
|
-
accepted_seq=stored.seq,
|
|
1114
|
-
)
|
|
1115
|
-
await connection.execute(
|
|
1116
|
-
"UPDATE kernel_interactions SET revision=$1, status='resolved',"
|
|
1117
|
-
" response=$2::jsonb, outcome=$3, actor=$4, event_id=$5::uuid,"
|
|
1118
|
-
" accepted_seq=$6, fencing_token=$7, updated_at=now()"
|
|
1119
|
-
" WHERE tenant_id=$8 AND interaction_id=$9",
|
|
1120
|
-
updated.revision,
|
|
1121
|
-
json.dumps(submission.response, ensure_ascii=False),
|
|
1122
|
-
outcome,
|
|
1123
|
-
"user",
|
|
1124
|
-
str(stored.event_id),
|
|
1125
|
-
stored.seq,
|
|
1126
|
-
int(guard.fencing_token),
|
|
1127
|
-
updated.tenant_id,
|
|
1128
|
-
updated.interaction_id,
|
|
1129
|
-
)
|
|
1130
|
-
await connection.execute(
|
|
1131
|
-
"INSERT INTO kernel_interaction_submissions (tenant_id,"
|
|
1132
|
-
" interaction_id, idempotency_key, submission_digest, receipt)"
|
|
1133
|
-
" VALUES ($1, $2, $3, $4, $5::jsonb) ON CONFLICT DO NOTHING",
|
|
1134
|
-
updated.tenant_id,
|
|
1135
|
-
updated.interaction_id,
|
|
1136
|
-
submission.idempotency_key,
|
|
1137
|
-
sub_digest,
|
|
1138
|
-
receipt.model_dump_json(),
|
|
1139
|
-
)
|
|
1140
|
-
return receipt
|
|
1141
|
-
|
|
1142
|
-
async def _terminal_command(
|
|
1143
|
-
self,
|
|
1144
|
-
interaction_id: str,
|
|
1145
|
-
expected_revision: int,
|
|
1146
|
-
*,
|
|
1147
|
-
guard: Any,
|
|
1148
|
-
status: str,
|
|
1149
|
-
reason: str,
|
|
1150
|
-
) -> InteractionReceipt:
|
|
1151
|
-
async with self._connection(write=True) as connection:
|
|
1152
|
-
async with connection.transaction():
|
|
1153
|
-
row = await self._interaction_row_for_guard(
|
|
1154
|
-
connection, interaction_id, guard
|
|
1155
|
-
)
|
|
1156
|
-
if row is None:
|
|
1157
|
-
raise InvalidCommandError(
|
|
1158
|
-
f"unknown interaction_id {interaction_id!r}"
|
|
1159
|
-
)
|
|
1160
|
-
await self._assert_interaction_guard(
|
|
1161
|
-
connection, row["agent_instance_id"], row["session_id"], guard
|
|
1162
|
-
)
|
|
1163
|
-
current = self._interaction_row_to_record(row)
|
|
1164
|
-
if is_terminal(current.status):
|
|
1165
|
-
raise InvalidCommandError(
|
|
1166
|
-
f"interaction already reached terminal status"
|
|
1167
|
-
f" {current.status!r}",
|
|
1168
|
-
details={
|
|
1169
|
-
"reason": ALREADY_RESOLVED,
|
|
1170
|
-
"interaction_id": current.interaction_id,
|
|
1171
|
-
},
|
|
1172
|
-
)
|
|
1173
|
-
if current.revision != expected_revision:
|
|
1174
|
-
raise InvalidCommandError(
|
|
1175
|
-
"interaction revision does not match expected_revision",
|
|
1176
|
-
details={
|
|
1177
|
-
"reason": REVISION_MISMATCH,
|
|
1178
|
-
"interaction_id": current.interaction_id,
|
|
1179
|
-
"expected_revision": expected_revision,
|
|
1180
|
-
"current_revision": current.revision,
|
|
1181
|
-
},
|
|
1182
|
-
)
|
|
1183
|
-
updated = current.model_copy(
|
|
1184
|
-
update={"status": status, "revision": current.revision + 1}
|
|
1185
|
-
)
|
|
1186
|
-
event_type = (
|
|
1187
|
-
"interaction.cancelled"
|
|
1188
|
-
if status == "cancelled"
|
|
1189
|
-
else "interaction.expired"
|
|
1190
|
-
)
|
|
1191
|
-
stored = await self._events.append_on(
|
|
1192
|
-
connection,
|
|
1193
|
-
interaction_event(
|
|
1194
|
-
updated,
|
|
1195
|
-
event_type=event_type,
|
|
1196
|
-
timestamp=now_iso(),
|
|
1197
|
-
reason=reason,
|
|
1198
|
-
),
|
|
1199
|
-
guard,
|
|
1200
|
-
)
|
|
1201
|
-
receipt = InteractionReceipt(
|
|
1202
|
-
interaction_id=updated.interaction_id,
|
|
1203
|
-
revision=updated.revision,
|
|
1204
|
-
status=updated.status, # type: ignore[arg-type]
|
|
1205
|
-
outcome=updated.status, # type: ignore[arg-type]
|
|
1206
|
-
event_id=str(stored.event_id),
|
|
1207
|
-
accepted_seq=stored.seq,
|
|
1208
|
-
)
|
|
1209
|
-
await connection.execute(
|
|
1210
|
-
"UPDATE kernel_interactions SET revision=$1, status=$2,"
|
|
1211
|
-
" outcome=$3, event_id=$4::uuid, accepted_seq=$5,"
|
|
1212
|
-
" fencing_token=$6, updated_at=now()"
|
|
1213
|
-
" WHERE tenant_id=$7 AND interaction_id=$8",
|
|
1214
|
-
updated.revision,
|
|
1215
|
-
status,
|
|
1216
|
-
status,
|
|
1217
|
-
str(stored.event_id),
|
|
1218
|
-
stored.seq,
|
|
1219
|
-
int(guard.fencing_token),
|
|
1220
|
-
updated.tenant_id,
|
|
1221
|
-
updated.interaction_id,
|
|
1222
|
-
)
|
|
1223
|
-
return receipt
|
|
1224
|
-
|
|
1225
|
-
async def cancel(
|
|
1226
|
-
self, interaction_id: str, expected_revision: int, *, guard: Any
|
|
1227
|
-
) -> InteractionReceipt:
|
|
1228
|
-
return await self._terminal_command(
|
|
1229
|
-
interaction_id,
|
|
1230
|
-
expected_revision,
|
|
1231
|
-
guard=guard,
|
|
1232
|
-
status="cancelled",
|
|
1233
|
-
reason="cancelled by owner",
|
|
1234
|
-
)
|
|
1235
|
-
|
|
1236
|
-
async def expire(
|
|
1237
|
-
self, interaction_id: str, expected_revision: int, *, guard: Any
|
|
1238
|
-
) -> InteractionReceipt:
|
|
1239
|
-
return await self._terminal_command(
|
|
1240
|
-
interaction_id,
|
|
1241
|
-
expected_revision,
|
|
1242
|
-
guard=guard,
|
|
1243
|
-
status="expired",
|
|
1244
|
-
reason="interaction expired",
|
|
1245
|
-
)
|
|
1246
|
-
|
|
1247
|
-
async def get(
|
|
1248
|
-
self,
|
|
1249
|
-
interaction_id: str,
|
|
1250
|
-
*,
|
|
1251
|
-
tenant_id: str | None = None,
|
|
1252
|
-
agent_instance_id: str | None = None,
|
|
1253
|
-
session_id: str | None = None,
|
|
1254
|
-
run_id: str | None = None,
|
|
1255
|
-
) -> InteractionRecord | None:
|
|
1256
|
-
"""Read public ids only through a complete trusted execution scope."""
|
|
1257
|
-
|
|
1258
|
-
scope = (tenant_id, agent_instance_id, session_id, run_id)
|
|
1259
|
-
async with self._connection() as connection:
|
|
1260
|
-
if any(value is not None for value in scope):
|
|
1261
|
-
if not all(value is not None for value in scope):
|
|
1262
|
-
raise InvalidCommandError(
|
|
1263
|
-
"interaction lookup requires a complete trusted scope",
|
|
1264
|
-
details={"interaction_id": interaction_id},
|
|
1265
|
-
)
|
|
1266
|
-
row = await connection.fetchrow(
|
|
1267
|
-
"SELECT * FROM kernel_interactions WHERE interaction_id=$1"
|
|
1268
|
-
" AND tenant_id=$2 AND agent_instance_id=$3 AND session_id=$4"
|
|
1269
|
-
" AND run_id=$5",
|
|
1270
|
-
interaction_id,
|
|
1271
|
-
tenant_id,
|
|
1272
|
-
agent_instance_id,
|
|
1273
|
-
session_id,
|
|
1274
|
-
run_id,
|
|
1275
|
-
)
|
|
1276
|
-
return self._interaction_row_to_record(row) if row is not None else None
|
|
1277
|
-
rows = await connection.fetch(
|
|
1278
|
-
"SELECT * FROM kernel_interactions WHERE interaction_id=$1 LIMIT 2",
|
|
1279
|
-
interaction_id,
|
|
1280
|
-
)
|
|
1281
|
-
if len(rows) > 1:
|
|
1282
|
-
raise InvalidCommandError(
|
|
1283
|
-
f"interaction_id {interaction_id!r} is ambiguous without trusted scope",
|
|
1284
|
-
details={"reason": REQUEST_CONFLICT, "interaction_id": interaction_id},
|
|
1285
|
-
)
|
|
1286
|
-
return self._interaction_row_to_record(rows[0]) if rows else None
|
|
1287
|
-
|
|
1288
|
-
async def list_pending_interactions(
|
|
1289
|
-
self, tenant_id: str, session_id: str
|
|
1290
|
-
) -> list[InteractionRecord]:
|
|
1291
|
-
async with self._connection() as connection:
|
|
1292
|
-
rows = await connection.fetch(
|
|
1293
|
-
"SELECT * FROM kernel_interactions WHERE tenant_id=$1 AND session_id=$2"
|
|
1294
|
-
" AND status='pending' ORDER BY created_at",
|
|
1295
|
-
tenant_id,
|
|
1296
|
-
session_id,
|
|
1297
|
-
)
|
|
1298
|
-
return [self._interaction_row_to_record(row) for row in rows]
|
|
1299
|
-
|
|
1300
1279
|
# ------------------------------------------------------------- activations
|
|
1301
1280
|
|
|
1302
1281
|
async def acquire_activation(self, request: ActivationLeaseRequest) -> ActivationLease:
|
|
1303
1282
|
async with self._connection(write=True) as connection:
|
|
1304
1283
|
async with connection.transaction():
|
|
1305
1284
|
row = await connection.fetchrow(
|
|
1306
|
-
"""
|
|
1285
|
+
f"""
|
|
1307
1286
|
INSERT INTO kernel_activations (
|
|
1308
1287
|
agent_instance_id, session_id, activation_id, fencing_token,
|
|
1309
|
-
lease_expires_at, runtime_type, bundle_digest, capability_digest
|
|
1288
|
+
lease_expires_at, runtime_type, bundle_digest, capability_digest, session_namespace
|
|
1310
1289
|
) VALUES (
|
|
1311
|
-
$1, $2, $3, 1, clock_timestamp() + make_interval(secs => $4), $5, $6, $7
|
|
1290
|
+
$1, $2, $3, 1, clock_timestamp() + make_interval(secs => $4), $5, $6, $7, $8
|
|
1312
1291
|
)
|
|
1313
1292
|
ON CONFLICT (agent_instance_id, session_id) DO UPDATE SET
|
|
1314
1293
|
activation_id = excluded.activation_id,
|
|
1315
1294
|
fencing_token = CASE
|
|
1316
1295
|
WHEN kernel_activations.activation_id = excluded.activation_id
|
|
1296
|
+
AND NOT kernel_activations.released
|
|
1297
|
+
AND kernel_activations.lease_expires_at > clock_timestamp()
|
|
1317
1298
|
THEN kernel_activations.fencing_token
|
|
1318
1299
|
ELSE kernel_activations.fencing_token + 1
|
|
1319
1300
|
END,
|
|
@@ -1321,11 +1302,20 @@ class PostgresAgentKernelStore(PostgresExecutionGrantMixin):
|
|
|
1321
1302
|
released = FALSE,
|
|
1322
1303
|
runtime_type = excluded.runtime_type,
|
|
1323
1304
|
bundle_digest = excluded.bundle_digest,
|
|
1324
|
-
capability_digest = excluded.capability_digest
|
|
1325
|
-
|
|
1305
|
+
capability_digest = excluded.capability_digest,
|
|
1306
|
+
session_namespace = excluded.session_namespace
|
|
1307
|
+
WHERE (kernel_activations.session_namespace IS NULL
|
|
1308
|
+
OR kernel_activations.session_namespace=excluded.session_namespace
|
|
1309
|
+
OR (kernel_activations.released AND NOT EXISTS (
|
|
1310
|
+
SELECT FROM {KSADK_PG_SESSIONS_TABLE} previous
|
|
1311
|
+
WHERE previous.namespace=kernel_activations.session_namespace AND previous.id=$2
|
|
1312
|
+
)))
|
|
1313
|
+
AND (kernel_activations.released
|
|
1326
1314
|
OR kernel_activations.lease_expires_at <= clock_timestamp()
|
|
1327
|
-
OR kernel_activations.activation_id = excluded.activation_id
|
|
1328
|
-
RETURNING fencing_token, lease_expires_at
|
|
1315
|
+
OR kernel_activations.activation_id = excluded.activation_id)
|
|
1316
|
+
RETURNING fencing_token, lease_expires_at, EXISTS (
|
|
1317
|
+
SELECT FROM {KSADK_PG_SESSIONS_TABLE} WHERE namespace=$8 AND id=$2 FOR KEY SHARE
|
|
1318
|
+
) AS session_present
|
|
1329
1319
|
""",
|
|
1330
1320
|
request.agent_instance_id,
|
|
1331
1321
|
request.session_id,
|
|
@@ -1334,6 +1324,7 @@ class PostgresAgentKernelStore(PostgresExecutionGrantMixin):
|
|
|
1334
1324
|
request.runtime_type,
|
|
1335
1325
|
request.bundle_digest,
|
|
1336
1326
|
request.capability_digest,
|
|
1327
|
+
self._events._namespace,
|
|
1337
1328
|
)
|
|
1338
1329
|
if row is None:
|
|
1339
1330
|
holder = await connection.fetchrow(
|
|
@@ -1351,10 +1342,20 @@ class PostgresAgentKernelStore(PostgresExecutionGrantMixin):
|
|
|
1351
1342
|
),
|
|
1352
1343
|
},
|
|
1353
1344
|
)
|
|
1345
|
+
token = row["fencing_token"]
|
|
1346
|
+
if not row["session_present"]:
|
|
1347
|
+
# Ownership and orphan retirement commit together. The function
|
|
1348
|
+
# rechecks the parent before touching any work.
|
|
1349
|
+
advanced = await connection.fetchval(
|
|
1350
|
+
"SELECT ksadk_retire_kernel_session($1,$2,$3,$4,'session_missing')",
|
|
1351
|
+
self._events._namespace, self.tenant_id, request.session_id, request.agent_instance_id,
|
|
1352
|
+
)
|
|
1353
|
+
if advanced is not None:
|
|
1354
|
+
token = advanced
|
|
1354
1355
|
return ActivationLease(
|
|
1355
1356
|
agent_instance_id=request.agent_instance_id,
|
|
1356
1357
|
activation_id=request.activation_id,
|
|
1357
|
-
fencing_token=int(
|
|
1358
|
+
fencing_token=int(token),
|
|
1358
1359
|
lease_expires_at=row["lease_expires_at"].isoformat(),
|
|
1359
1360
|
bundle_digest=request.bundle_digest,
|
|
1360
1361
|
runtime_type=request.runtime_type,
|
|
@@ -1594,9 +1595,12 @@ class PostgresAgentKernelStore(PostgresExecutionGrantMixin):
|
|
|
1594
1595
|
if is_active_run(run.state):
|
|
1595
1596
|
clash = await connection.fetchval(
|
|
1596
1597
|
"SELECT run_id FROM kernel_runs WHERE session_id=$1 AND run_id <> $2"
|
|
1598
|
+
" AND (session_namespace=$3 OR (session_namespace IS NULL AND tenant_id=$4))"
|
|
1597
1599
|
" AND state IN ('running','paused','waiting')",
|
|
1598
1600
|
run.session_id,
|
|
1599
1601
|
run.run_id,
|
|
1602
|
+
self._events._namespace,
|
|
1603
|
+
self.tenant_id,
|
|
1600
1604
|
)
|
|
1601
1605
|
if clash is not None:
|
|
1602
1606
|
raise InvalidCommandError(
|
|
@@ -1616,13 +1620,13 @@ class PostgresAgentKernelStore(PostgresExecutionGrantMixin):
|
|
|
1616
1620
|
await connection.execute(
|
|
1617
1621
|
"""
|
|
1618
1622
|
INSERT INTO kernel_runs (run_id, tenant_id, agent_instance_id, session_id,
|
|
1619
|
-
state, activation_fence, created_at, updated_at, metadata)
|
|
1620
|
-
VALUES ($1, $2, $3, $4, $5, $6, now(), now(), $7::jsonb)
|
|
1623
|
+
state, activation_fence, created_at, updated_at, metadata, session_namespace)
|
|
1624
|
+
VALUES ($1, $2, $3, $4, $5, $6, now(), now(), $7::jsonb, $8)
|
|
1621
1625
|
ON CONFLICT (run_id) DO UPDATE SET
|
|
1622
1626
|
state = excluded.state,
|
|
1623
1627
|
activation_fence = excluded.activation_fence,
|
|
1624
1628
|
updated_at = now(),
|
|
1625
|
-
metadata = excluded.metadata
|
|
1629
|
+
metadata = excluded.metadata, session_namespace=excluded.session_namespace
|
|
1626
1630
|
""",
|
|
1627
1631
|
stored.run_id,
|
|
1628
1632
|
self.tenant_id,
|
|
@@ -1631,6 +1635,7 @@ class PostgresAgentKernelStore(PostgresExecutionGrantMixin):
|
|
|
1631
1635
|
stored.state.value,
|
|
1632
1636
|
stored.activation_fence,
|
|
1633
1637
|
json.dumps(stored.metadata, ensure_ascii=False),
|
|
1638
|
+
self._events._namespace,
|
|
1634
1639
|
)
|
|
1635
1640
|
await self._append_activation_fact(
|
|
1636
1641
|
connection,
|
|
@@ -1682,12 +1687,13 @@ class PostgresFencedSessionEventStore:
|
|
|
1682
1687
|
|
|
1683
1688
|
validate_write_guard(envelope, guard)
|
|
1684
1689
|
if isinstance(guard, ActivationWriteGuard):
|
|
1685
|
-
async with
|
|
1686
|
-
async with
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1690
|
+
async with asyncio.timeout(session_db_budget().write_operation_seconds):
|
|
1691
|
+
async with self._connection() as connection:
|
|
1692
|
+
async with connection.transaction():
|
|
1693
|
+
await self._assert_activation_fence(
|
|
1694
|
+
connection, guard, envelope.session_id
|
|
1695
|
+
)
|
|
1696
|
+
return await self._log.append_on(connection, envelope, guard)
|
|
1691
1697
|
return await self._log.append(envelope, guard=guard)
|
|
1692
1698
|
|
|
1693
1699
|
async def _assert_activation_fence(
|
|
@@ -1696,9 +1702,10 @@ class PostgresFencedSessionEventStore:
|
|
|
1696
1702
|
row = await connection.fetchrow(
|
|
1697
1703
|
"SELECT activation_id, fencing_token, lease_expires_at, released"
|
|
1698
1704
|
" FROM kernel_activations WHERE activation_id = $1 AND session_id = $2"
|
|
1699
|
-
" FOR SHARE",
|
|
1705
|
+
" AND (session_namespace=$3 OR session_namespace IS NULL) FOR SHARE",
|
|
1700
1706
|
guard.activation_id,
|
|
1701
1707
|
session_id,
|
|
1708
|
+
self._log._namespace,
|
|
1702
1709
|
)
|
|
1703
1710
|
if (
|
|
1704
1711
|
row is None
|
|
@@ -1732,6 +1739,18 @@ class PostgresFencedSessionEventStore:
|
|
|
1732
1739
|
async def get_by_id(self, session_id: str, event_id: Any) -> SessionEventEnvelope | None:
|
|
1733
1740
|
return await self._log.get_by_id(session_id, event_id)
|
|
1734
1741
|
|
|
1742
|
+
async def get_max_seq_id(self, session_id: str) -> int:
|
|
1743
|
+
return await self._log.get_max_seq_id(session_id)
|
|
1744
|
+
|
|
1745
|
+
async def has_run_transition(self, session_id, run_id, state):
|
|
1746
|
+
return await self._log.has_run_transition(session_id, run_id, state)
|
|
1747
|
+
|
|
1748
|
+
async def find_interaction_resolution(self, record):
|
|
1749
|
+
return await self._log.find_interaction_resolution(record)
|
|
1750
|
+
|
|
1751
|
+
async def read_runtime(self, session_id: str, **query) -> list[SessionEventEnvelope]:
|
|
1752
|
+
return await self._log.read_runtime(session_id, **query)
|
|
1753
|
+
|
|
1735
1754
|
async def subscribe(
|
|
1736
1755
|
self, session_id: str, after_seq: int, *, poll_interval: float = 0.25
|
|
1737
1756
|
):
|
|
@@ -1739,11 +1758,54 @@ class PostgresFencedSessionEventStore:
|
|
|
1739
1758
|
|
|
1740
1759
|
cursor = int(after_seq or 0)
|
|
1741
1760
|
while True:
|
|
1742
|
-
envelopes = await self._log.
|
|
1761
|
+
envelopes = await self._log.read_subscription_page(session_id, cursor)
|
|
1743
1762
|
for envelope in envelopes:
|
|
1744
1763
|
cursor = max(cursor, int(envelope.seq))
|
|
1745
1764
|
yield envelope
|
|
1746
|
-
|
|
1765
|
+
if not envelopes:
|
|
1766
|
+
await asyncio.sleep(poll_interval)
|
|
1767
|
+
|
|
1768
|
+
async def subscribe_recovering(
|
|
1769
|
+
self, session_id: str, after_seq: int, *, poll_interval: float = 0.25,
|
|
1770
|
+
):
|
|
1771
|
+
"""Internal A2A observation: resume reads, never submit another command.
|
|
1772
|
+
|
|
1773
|
+
Public SSE keeps its existing transport recovery/permit boundary. This
|
|
1774
|
+
capability is for the direct, already-admitted A2A observer which has
|
|
1775
|
+
no HTTP reconnect layer. Each successful SQL page, including an empty
|
|
1776
|
+
page, establishes backend health before another outage budget starts.
|
|
1777
|
+
"""
|
|
1778
|
+
from ksadk.sessions.resilience import is_transient_session_backend_failure
|
|
1779
|
+
|
|
1780
|
+
cursor = int(after_seq or 0)
|
|
1781
|
+
loop = asyncio.get_running_loop()
|
|
1782
|
+
while True:
|
|
1783
|
+
deadline = loop.time() + session_db_budget().event_observe_recovery_seconds
|
|
1784
|
+
delay = 0.2
|
|
1785
|
+
while True:
|
|
1786
|
+
try:
|
|
1787
|
+
async with asyncio.timeout(max(0.001, deadline - loop.time())):
|
|
1788
|
+
envelopes = await self._log.read_subscription_page(session_id, cursor)
|
|
1789
|
+
break
|
|
1790
|
+
except Exception as exc:
|
|
1791
|
+
remaining = deadline - loop.time()
|
|
1792
|
+
if remaining <= 0 or not is_transient_session_backend_failure(exc):
|
|
1793
|
+
raise
|
|
1794
|
+
logging.getLogger(__name__).warning(
|
|
1795
|
+
"Retrying admitted A2A event read after %s at cursor=%d",
|
|
1796
|
+
type(exc).__name__, cursor,
|
|
1797
|
+
)
|
|
1798
|
+
await asyncio.sleep(min(delay, remaining))
|
|
1799
|
+
delay = min(5.0, delay * 2)
|
|
1800
|
+
for envelope in envelopes:
|
|
1801
|
+
if envelope.session_id != session_id:
|
|
1802
|
+
raise PermissionError("Kernel event store returned another session")
|
|
1803
|
+
if envelope.seq <= cursor:
|
|
1804
|
+
continue
|
|
1805
|
+
cursor = envelope.seq
|
|
1806
|
+
yield envelope
|
|
1807
|
+
if not envelopes:
|
|
1808
|
+
await asyncio.sleep(poll_interval)
|
|
1747
1809
|
|
|
1748
1810
|
|
|
1749
1811
|
__all__ = [
|