WeKnora/migrations/sqlite
lyingbug 383d26535a
feat(agent): persist human-in-the-loop prompts with a shared broker (#4250)
* feat(agent): persist human-in-the-loop prompts with a shared broker

Tool approvals and MCP OAuth prompts are now rows in agent_prompts,
awaited through hitl.Broker (lease, DB polling, Redis wake-up, per-kind
answer validation). Resolve is bound to session and kind. This is P1 of
the suspend/resume design; runs still block as before.

* feat(agent): suspend runs whose prompt outlives a short in-memory wait

Behind agent.prompt_suspend_enabled (off by default). A run raised from the
HTTP stream saves its state when a tool approval is raised; after the hot
wait the prompt moves to suspended and the assistant message is saved as
awaiting_input instead of blocking. A reaper takes over prompts whose
waiting replica stopped renewing its lease. Resume comes in a later change.

* feat(agent): resume suspended runs once their prompt is answered

The replica that records the answer resumes the run in process under the
prompt's lease. Superseded, expired and abandoned runs are closed with a
result for every tool call, and approved tools are never replayed.

* feat(agent): let users answer suspended tool approvals and follow the resumed run

* feat(agent): ask_user tool and generic prompt answer endpoint

- ask_user built-in tool: options, short forms or free text; validated
  answers, decline, suspend/resume like tool approval; non-interactive
  callers (IM, API keys) are told to ask in the reply instead
- POST /agent/prompts/{prompt_id} (and embed variant) answers ask_user
  and tool_approval prompts, returns resumed; SDK ResolveAgentPrompt
- agent_prompt_required/resolved events; AskUserCard sharing the
  countdown with ToolApprovalCard; answered questions rebuilt as cards
  from history
- awaiting-input messages keep their steps expanded so the pending card
  stays visible; prompt cards keyed by their own id
- i18n for all locales; design doc updated

* fix(agent): keep prompt answers that race a suspending or vanished owner

- Resolve suspends a pending prompt whose owner's lease lapsed, as the
  reaper would, so the answer resumes the run instead of waking nobody.
- Resuming waits for the suspending run to persist its message and clear
  its live-run marker; a marker left by a vanished owner is cleared.
- A resumed run that suspends again on a new prompt no longer has its
  message closed from the old state.
- tool_approval answers are decoded strictly and require "approved";
  fix the SDK doc that showed {"decision": "approve"}.
- API-key runs block instead of suspending, since they cannot answer.
- A run state that cannot be saved falls back to an in-memory wait, and
  NUL escapes are stripped from snapshots for jsonb.

* style(chat): align the ask_user card with the other interaction cards

Question and answer use the timeline's step text styles instead of
primary-colored and monospace text; options and form controls use the
compact step size, the number input spans the row, and the free-text
character counter is hidden.

* feat(chat): dock pending agent prompts above the composer

Tool approvals, ask_user questions and MCP OAuth prompts were answered
inline in the agent timeline, where a long answer or scrolling back
pushes them out of view. Open prompts of a streaming or suspended run
now gather in a dock above the composer (main chat and embed), one at a
time with a pager, lettered options and Enter to submit. The timeline
keeps a one-line record with a link back to the dock and the outcome
once answered. Views without a dock still answer inline.

* fix(agent): fence prompt ownership and preserve resumed turn context

* fix(agent): keep runs through consume errors and file prompts under the caller

Consume reported a store error as a lost claim, so an answer consumed
during a database hiccup detached its run: the message was never
persisted, the live-run marker stayed, and the reaper skipped the row
because the waiter had already dropped the snapshot. Consume now retries,
then decides from the row, and gives a run up only when the prompt is
known to have moved on.

Tool approvals and OAuth prompts of a shared agent were filed under the
agent's workspace, so the user's answer failed the tenant check and the
prompt timed out. Like ask_user, they now use the caller's workspace;
policy and token lookups stay in the agent's.

Enter on a picked option submits it instead of toggling it off, and
resume errors no longer report a nil cause.

* fix(agent): validate prompt choices and require durable approval claims

Reject malformed serialized option lists so the model can retry with valid arguments. Distinguish prompt consumption failures from lost ownership without authorizing side effects, and preserve native Enter selection for unselected choices.

* fix(agent): resolve prompt workflow lint errors
2026-10-14 20:37:28 +08:00
..
000000_init.down.sql Remove redundant Wiki operation log 2026-07-28 11:18:33 +08:00
000000_init.up.sql feat(sandbox) (#2301) 2026-08-10 21:28:20 +08:00
000001_remove_wiki_log.down.sql Remove redundant Wiki operation log 2026-07-28 11:18:33 +08:00
000001_remove_wiki_log.up.sql Remove redundant Wiki operation log 2026-07-28 11:18:33 +08:00
000002_knowledge_folder_path.down.sql feat(knowledge): store folder path for folder uploads and expose folder tree API 2026-08-04 20:45:29 +08:00
000002_knowledge_folder_path.up.sql feat(knowledge): store folder path for folder uploads and expose folder tree API 2026-08-04 20:45:29 +08:00
000003_knowledge_base_auto_tag_config.down.sql feat: 增加自动添加标签的功能 2026-08-07 15:01:01 +08:00
000003_knowledge_base_auto_tag_config.up.sql feat: 增加自动添加标签的功能 2026-08-07 15:01:01 +08:00
000004_memory.down.sql feat(memory): add cross-session long-term memory 2026-08-13 18:00:02 +08:00
000004_memory.up.sql feat(memory): add forced consolidation feature and related i18n updates 2026-08-13 18:00:02 +08:00
000005_messages_attachments_and_invitation_fields.down.sql fix(migrations): 补齐 SQLite 迁移与 versioned 的索引与数据迁移缺口 2026-08-20 14:35:49 +08:00
000005_messages_attachments_and_invitation_fields.up.sql fix(migrations): 补齐 SQLite 迁移与 versioned 的索引与数据迁移缺口 2026-08-20 14:35:49 +08:00
000006_task_queue_and_dead_letters.down.sql fix(migrations): 补齐 Lite 模式缺失的 SQLite 版本化迁移 2026-08-20 14:35:49 +08:00
000006_task_queue_and_dead_letters.up.sql fix(migrations): 补齐 Lite 模式缺失的 SQLite 版本化迁移 2026-08-20 14:35:49 +08:00
000007_system_admin_and_settings.down.sql fix(migrations): 补齐 Lite 模式缺失的 SQLite 版本化迁移 2026-08-20 14:35:49 +08:00
000007_system_admin_and_settings.up.sql fix(migrations): 补齐 Lite 模式缺失的 SQLite 版本化迁移 2026-08-20 14:35:49 +08:00
000008_processing_spans_and_pending_subtasks.down.sql fix(migrations): 补齐 Lite 模式缺失的 SQLite 版本化迁移 2026-08-20 14:35:49 +08:00
000008_processing_spans_and_pending_subtasks.up.sql fix(migrations): 补齐 SQLite 迁移与 versioned 的索引与数据迁移缺口 2026-08-20 14:35:49 +08:00
000009_embed_channel_memory_flag.down.sql fix(migrations): 补齐 Lite 模式缺失的 SQLite 版本化迁移 2026-08-20 14:35:49 +08:00
000009_embed_channel_memory_flag.up.sql fix(migrations): 补齐 Lite 模式缺失的 SQLite 版本化迁移 2026-08-20 14:35:49 +08:00
000010_knowledge_multi_tags.down.sql fix(migrations): 补齐 SQLite 迁移与 versioned 的索引与数据迁移缺口 2026-08-20 14:35:49 +08:00
000010_knowledge_multi_tags.up.sql fix(migrations): 补齐 SQLite 迁移与 versioned 的索引与数据迁移缺口 2026-08-20 14:35:49 +08:00
000011_principal_model.down.sql fix(migrations): 补齐 SQLite 迁移与 versioned 的索引与数据迁移缺口 2026-08-20 14:35:49 +08:00
000011_principal_model.up.sql fix(migrations): 补齐 SQLite 迁移与 versioned 的索引与数据迁移缺口 2026-08-20 14:35:49 +08:00
000012_message_usage.down.sql feat(agent): report and attribute per-turn LLM token usage 2026-08-24 10:36:19 +08:00
000012_message_usage.up.sql feat(agent): report and attribute per-turn LLM token usage 2026-08-24 10:36:19 +08:00
000013_mcp_tool_enabled.down.sql feat(mcp): add per-tool enable toggle (#2989) 2026-09-05 17:19:20 +08:00
000013_mcp_tool_enabled.up.sql feat(mcp): add per-tool enable toggle (#2989) 2026-09-05 17:19:20 +08:00
000014_browser_authorization.down.sql feat(browser): connect local Chrome with task controls and display modes (#3180) 2026-09-11 17:59:27 +08:00
000014_browser_authorization.up.sql feat(browser): connect local Chrome with task controls and display modes (#3180) 2026-09-11 17:59:27 +08:00
000015_memory_consistency.down.sql fix(memory): preserve extraction progress and atomic memory updates (#3224) 2026-09-13 00:04:16 +08:00
000015_memory_consistency.up.sql fix(memory): preserve extraction progress and atomic memory updates (#3224) 2026-09-13 00:04:16 +08:00
000016_memory_vector_search.down.sql fix(memory): rank memories by the query, not by importance 2026-09-13 11:43:17 +08:00
000016_memory_vector_search.up.sql fix(memory): rank memories by the query, not by importance 2026-09-13 11:43:17 +08:00
000017_dingtalk_stream_only.down.sql fix: align client sessions and integration request handling (#3305) 2026-09-16 16:20:57 +08:00
000017_dingtalk_stream_only.up.sql fix: align client sessions and integration request handling (#3305) 2026-09-16 16:20:57 +08:00
000018_session_fork.down.sql feat(session): fork conversations from a historical user message (#3304) 2026-09-17 14:20:18 +08:00
000018_session_fork.up.sql feat(session): fork conversations from a historical user message (#3304) 2026-09-17 14:20:18 +08:00
000019_fork_snapshot_lease.down.sql feat(session): fork conversations from a historical user message (#3304) 2026-09-17 14:20:18 +08:00
000019_fork_snapshot_lease.up.sql feat(session): fork conversations from a historical user message (#3304) 2026-09-17 14:20:18 +08:00
000020_chunks_index_diet.down.sql perf(chunk): speed up chunk ingestion and batch updates (#3369) 2026-09-17 21:38:15 +08:00
000020_chunks_index_diet.up.sql perf(chunk): speed up chunk ingestion and batch updates (#3369) 2026-09-17 21:38:15 +08:00
000021_knowledge_profiles.down.sql feat(knowledge): derive knowledge base descriptions from document profiles (#3370) 2026-09-17 22:21:55 +08:00
000021_knowledge_profiles.up.sql feat(knowledge): derive knowledge base descriptions from document profiles (#3370) 2026-09-17 22:21:55 +08:00
000022_mcp_endpoints.down.sql feat(mcp): add built-in MCP server with per-workspace endpoints (#3371) 2026-09-17 22:40:05 +08:00
000022_mcp_endpoints.up.sql feat(mcp): add built-in MCP server with per-workspace endpoints (#3371) 2026-09-17 22:40:05 +08:00
000023_message_artifacts_table.down.sql feat(artifacts): artifacts library page backed by a message_artifacts table (#3384) 2026-09-18 12:10:19 +08:00
000023_message_artifacts_table.up.sql feat(artifacts): artifacts library page backed by a message_artifacts table (#3384) 2026-09-18 12:10:19 +08:00
000024_message_context_checkpoint.down.sql feat(agent): persist compaction checkpoints across turns (#3407) 2026-09-18 20:38:56 +08:00
000024_message_context_checkpoint.up.sql fix(migrations): renumber the context checkpoint migration to 000105 2026-09-18 21:26:26 +08:00
000025_messages_session_created_index.down.sql feat(agent): size agent history by the window and calibrate token estimates (#3413) 2026-09-18 22:51:31 +08:00
000025_messages_session_created_index.up.sql feat(agent): size agent history by the window and calibrate token estimates (#3413) 2026-09-18 22:51:31 +08:00
000026_message_artifacts_deleted_at.down.sql feat(artifacts): let users delete generated files (#3447) 2026-09-20 13:01:46 +08:00
000026_message_artifacts_deleted_at.up.sql feat(artifacts): let users delete generated files (#3447) 2026-09-20 13:01:46 +08:00
000027_session_sandbox_config_tenant.down.sql fix(sandbox): resolve a session's pinned sandbox in the workspace that owns it (#3471) 2026-09-21 15:38:39 +08:00
000027_session_sandbox_config_tenant.up.sql fix(sandbox): resolve a session's pinned sandbox in the workspace that owns it (#3471) 2026-09-21 15:38:39 +08:00
000028_tenant_skills_and_env_vars.down.sql feat(sandbox): run unpinned Lite sessions on the host OS sandbox (#3549) 2026-09-22 19:35:03 +08:00
000028_tenant_skills_and_env_vars.up.sql feat(sandbox): run unpinned Lite sessions on the host OS sandbox (#3549) 2026-09-22 19:35:03 +08:00
000029_session_host_workspace_dir.down.sql feat(sandbox): run unpinned Lite sessions on the host OS sandbox (#3549) 2026-09-22 19:35:03 +08:00
000029_session_host_workspace_dir.up.sql feat(sandbox): run unpinned Lite sessions on the host OS sandbox (#3549) 2026-09-22 19:35:03 +08:00
000030_im_channel_locale.down.sql feat(im): add per-channel reply locale (#3455) 2026-09-23 12:01:01 +08:00
000030_im_channel_locale.up.sql feat(im): add per-channel reply locale (#3455) 2026-09-23 12:01:01 +08:00
000031_model_catalog_config.down.sql feat(models): add system admin model catalog console (#3662) 2026-09-24 16:31:45 +08:00
000031_model_catalog_config.up.sql feat(models): add system admin model catalog console (#3662) 2026-09-24 16:31:45 +08:00
000032_chunk_images.down.sql feat(gallery): add an image gallery tab with schema-driven filters (#3694) 2026-09-25 12:33:59 +08:00
000032_chunk_images.up.sql feat(gallery): add an image gallery tab with schema-driven filters (#3694) 2026-09-25 12:33:59 +08:00
000033_chunk_source_locators.down.sql feat(chat): open cited documents at the cited passage (#3700) 2026-09-25 13:26:16 +08:00
000033_chunk_source_locators.up.sql feat(chat): open cited documents at the cited passage (#3700) 2026-09-25 13:26:16 +08:00
000034_mcp_metadata.down.sql fix(sqlite): add MCP metadata migration 2026-10-10 20:47:20 +08:00
000034_mcp_metadata.up.sql fix(sqlite): add MCP metadata migration 2026-10-10 20:47:20 +08:00
000035_agent_allowed_tools_explicit_defaults.down.sql fix(agent): make agent tool selection match the tools the runtime registers (#4211) 2026-10-13 11:29:24 +08:00
000035_agent_allowed_tools_explicit_defaults.up.sql fix(agent): make agent tool selection match the tools the runtime registers (#4211) 2026-10-13 11:29:24 +08:00
000036_messages_attachment_lookup.down.sql feat(agent): read chat attachments on demand (#4203) 2026-10-13 14:37:17 +08:00
000036_messages_attachment_lookup.up.sql feat(agent): read chat attachments on demand (#4203) 2026-10-13 14:37:17 +08:00
000037_agent_prompts.down.sql feat(agent): persist human-in-the-loop prompts with a shared broker (#4250) 2026-10-14 20:37:28 +08:00
000037_agent_prompts.up.sql feat(agent): persist human-in-the-loop prompts with a shared broker (#4250) 2026-10-14 20:37:28 +08:00