2026-08-19 10:54:55 +00:00
|
|
|
package database
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"database/sql"
|
feat(session): fork conversations from a historical user message (#3304)
* feat(session): add fork schema and history queries
为会话分叉增加数据模型与迁移,并提供截至分叉点的消息查询以及会话内的 request_id 配对。
* feat(sandbox): add git, fork snapshots, and bootstrap hook
沙箱镜像安装 git,Docker 快照使用独立的 fork 命名空间,并在首次创建会话沙箱时接入可选 bootstrap。
* feat(session): checkpoint workspace at the end of each turn
每轮结束后对沙箱 /workspace 打 git checkpoint,并避免 fork 后因 mtime 刷新重复挂上产物、以及附件仍绑在父会话而无法还原。
* feat(session): fork conversations and reap orphan snapshots
支持从历史 user 消息分叉会话、首次打开时从快照 bootstrap,并在失败或删除未打开的分叉时回收孤儿快照。
* feat(chat): add session fork entry, prefill, and badges
在用户消息上提供分叉入口,进入新会话时预填原问题,并展示降级提示与来源角标。
* style: add missing newline so session_fork_delete_test.go is gofmt-clean
* fix(session): prune later git history when rolling a fork workspace back
reset --hard 只还原工作区,分叉点之后的 commit 仍可被 checkout。校验 SHA 后丢掉其他 ref 并 gc,避免错误基线。
* style(session): clear golangci-lint findings on the session-fork diff
Pre-push lints the whole PR against main; wrap long lines, check c.Error,
and fix gofumpt/revive/staticcheck so the merge can be pushed.
* fix(chat): show the fork button on hover without shifting the thread
Overlay the action so revealing it no longer expands the user bubble and janks the messages below.
* fix(chat): drop the fork landing banners
Keep the original question prefilled; do not explain sandbox snapshot vs checkpoint on the new thread.
* fix(agent): dedupe artifacts by content hash, not size
Same-path same-size rewrites were skipped as restores. Keep path+mtime as the cheap skip, hash bytes when mtime moves, and stamp the restored mtime onto this session only.
* feat(session): allow forking from an assistant answer
User forks still copy history before the question and prefill it. Assistant forks copy through that reply and reuse its checkpoint, with a degrade tooltip when none exists.
* fix(session): resolve parent attachments from a forked chat
Fork copies attachment IDs onto the new messages but leaves temporary_documents on the parent. Preview and Get now look up those IDs on the fork's copied history instead of a scoped miss.
* fix(agent): rewrite sandbox refs after a content-hash skip
Fork restores change mtime on unchanged files, so Collect returns empty
and named citations were left as sandbox: paths. Resolve those names
against session artifacts, notify only real uploads, and stamp restored
mtime only on the matching content hash.
* fix(session): drop a dead fork snapshot and retry checkpoint rewrite
Create from a missing template now abandons bootstrap so the next
Resolve uses a normal sandbox. A failed checkpoint rewrite no longer
marks the bootstrap consumed, which previously made nested forks
SANDBOX_REPLACED.
* fix(session): load forked parent attachments into the prompt
ResolveForPrompt used session-scoped lookup, so copied parent attachment
IDs passed Get but never reached the model. Use the same resolveInSession
path as preview.
* fix(chat): keep the user-message fork button visible
The control was hover-only, which hid it on touch. Always show it, and
drop the unused degrade tooltip.
---------
Co-authored-by: hailongzhao <hailongzhao@tencent.com>
Co-authored-by: wizardchen <wizardchen@tencent.com>
2026-09-17 06:20:18 +00:00
|
|
|
"fmt"
|
2026-08-19 10:54:55 +00:00
|
|
|
"os"
|
|
|
|
|
"path/filepath"
|
feat(session): fork conversations from a historical user message (#3304)
* feat(session): add fork schema and history queries
为会话分叉增加数据模型与迁移,并提供截至分叉点的消息查询以及会话内的 request_id 配对。
* feat(sandbox): add git, fork snapshots, and bootstrap hook
沙箱镜像安装 git,Docker 快照使用独立的 fork 命名空间,并在首次创建会话沙箱时接入可选 bootstrap。
* feat(session): checkpoint workspace at the end of each turn
每轮结束后对沙箱 /workspace 打 git checkpoint,并避免 fork 后因 mtime 刷新重复挂上产物、以及附件仍绑在父会话而无法还原。
* feat(session): fork conversations and reap orphan snapshots
支持从历史 user 消息分叉会话、首次打开时从快照 bootstrap,并在失败或删除未打开的分叉时回收孤儿快照。
* feat(chat): add session fork entry, prefill, and badges
在用户消息上提供分叉入口,进入新会话时预填原问题,并展示降级提示与来源角标。
* style: add missing newline so session_fork_delete_test.go is gofmt-clean
* fix(session): prune later git history when rolling a fork workspace back
reset --hard 只还原工作区,分叉点之后的 commit 仍可被 checkout。校验 SHA 后丢掉其他 ref 并 gc,避免错误基线。
* style(session): clear golangci-lint findings on the session-fork diff
Pre-push lints the whole PR against main; wrap long lines, check c.Error,
and fix gofumpt/revive/staticcheck so the merge can be pushed.
* fix(chat): show the fork button on hover without shifting the thread
Overlay the action so revealing it no longer expands the user bubble and janks the messages below.
* fix(chat): drop the fork landing banners
Keep the original question prefilled; do not explain sandbox snapshot vs checkpoint on the new thread.
* fix(agent): dedupe artifacts by content hash, not size
Same-path same-size rewrites were skipped as restores. Keep path+mtime as the cheap skip, hash bytes when mtime moves, and stamp the restored mtime onto this session only.
* feat(session): allow forking from an assistant answer
User forks still copy history before the question and prefill it. Assistant forks copy through that reply and reuse its checkpoint, with a degrade tooltip when none exists.
* fix(session): resolve parent attachments from a forked chat
Fork copies attachment IDs onto the new messages but leaves temporary_documents on the parent. Preview and Get now look up those IDs on the fork's copied history instead of a scoped miss.
* fix(agent): rewrite sandbox refs after a content-hash skip
Fork restores change mtime on unchanged files, so Collect returns empty
and named citations were left as sandbox: paths. Resolve those names
against session artifacts, notify only real uploads, and stamp restored
mtime only on the matching content hash.
* fix(session): drop a dead fork snapshot and retry checkpoint rewrite
Create from a missing template now abandons bootstrap so the next
Resolve uses a normal sandbox. A failed checkpoint rewrite no longer
marks the bootstrap consumed, which previously made nested forks
SANDBOX_REPLACED.
* fix(session): load forked parent attachments into the prompt
ResolveForPrompt used session-scoped lookup, so copied parent attachment
IDs passed Get but never reached the model. Use the same resolveInSession
path as preview.
* fix(chat): keep the user-message fork button visible
The control was hover-only, which hid it on touch. Always show it, and
drop the unused degrade tooltip.
---------
Co-authored-by: hailongzhao <hailongzhao@tencent.com>
Co-authored-by: wizardchen <wizardchen@tencent.com>
2026-09-17 06:20:18 +00:00
|
|
|
"strings"
|
2026-08-19 10:54:55 +00:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// versionedSQLiteTables is the set of tables that SQLite migrations must
|
|
|
|
|
// create to stay in sync with the versioned (PostgreSQL) migrations:
|
|
|
|
|
// 000041 task queue, 000053 system settings, 000055 processing spans,
|
2026-09-11 09:59:27 +00:00
|
|
|
// 000063 knowledge multi-tags, 000093 browser authorization.
|
2026-08-19 10:54:55 +00:00
|
|
|
var versionedSQLiteTables = []string{
|
2026-09-12 16:04:16 +00:00
|
|
|
"memory_extraction_sessions",
|
2026-08-19 10:54:55 +00:00
|
|
|
"task_pending_ops",
|
|
|
|
|
"task_dead_letters",
|
|
|
|
|
"system_settings",
|
|
|
|
|
"knowledge_processing_spans",
|
|
|
|
|
"knowledge_tag_relations",
|
2026-09-11 09:59:27 +00:00
|
|
|
"browser_devices",
|
|
|
|
|
"browser_pairings",
|
|
|
|
|
"browser_task_interruptions",
|
feat(session): fork conversations from a historical user message (#3304)
* feat(session): add fork schema and history queries
为会话分叉增加数据模型与迁移,并提供截至分叉点的消息查询以及会话内的 request_id 配对。
* feat(sandbox): add git, fork snapshots, and bootstrap hook
沙箱镜像安装 git,Docker 快照使用独立的 fork 命名空间,并在首次创建会话沙箱时接入可选 bootstrap。
* feat(session): checkpoint workspace at the end of each turn
每轮结束后对沙箱 /workspace 打 git checkpoint,并避免 fork 后因 mtime 刷新重复挂上产物、以及附件仍绑在父会话而无法还原。
* feat(session): fork conversations and reap orphan snapshots
支持从历史 user 消息分叉会话、首次打开时从快照 bootstrap,并在失败或删除未打开的分叉时回收孤儿快照。
* feat(chat): add session fork entry, prefill, and badges
在用户消息上提供分叉入口,进入新会话时预填原问题,并展示降级提示与来源角标。
* style: add missing newline so session_fork_delete_test.go is gofmt-clean
* fix(session): prune later git history when rolling a fork workspace back
reset --hard 只还原工作区,分叉点之后的 commit 仍可被 checkout。校验 SHA 后丢掉其他 ref 并 gc,避免错误基线。
* style(session): clear golangci-lint findings on the session-fork diff
Pre-push lints the whole PR against main; wrap long lines, check c.Error,
and fix gofumpt/revive/staticcheck so the merge can be pushed.
* fix(chat): show the fork button on hover without shifting the thread
Overlay the action so revealing it no longer expands the user bubble and janks the messages below.
* fix(chat): drop the fork landing banners
Keep the original question prefilled; do not explain sandbox snapshot vs checkpoint on the new thread.
* fix(agent): dedupe artifacts by content hash, not size
Same-path same-size rewrites were skipped as restores. Keep path+mtime as the cheap skip, hash bytes when mtime moves, and stamp the restored mtime onto this session only.
* feat(session): allow forking from an assistant answer
User forks still copy history before the question and prefill it. Assistant forks copy through that reply and reuse its checkpoint, with a degrade tooltip when none exists.
* fix(session): resolve parent attachments from a forked chat
Fork copies attachment IDs onto the new messages but leaves temporary_documents on the parent. Preview and Get now look up those IDs on the fork's copied history instead of a scoped miss.
* fix(agent): rewrite sandbox refs after a content-hash skip
Fork restores change mtime on unchanged files, so Collect returns empty
and named citations were left as sandbox: paths. Resolve those names
against session artifacts, notify only real uploads, and stamp restored
mtime only on the matching content hash.
* fix(session): drop a dead fork snapshot and retry checkpoint rewrite
Create from a missing template now abandons bootstrap so the next
Resolve uses a normal sandbox. A failed checkpoint rewrite no longer
marks the bootstrap consumed, which previously made nested forks
SANDBOX_REPLACED.
* fix(session): load forked parent attachments into the prompt
ResolveForPrompt used session-scoped lookup, so copied parent attachment
IDs passed Get but never reached the model. Use the same resolveInSession
path as preview.
* fix(chat): keep the user-message fork button visible
The control was hover-only, which hid it on touch. Always show it, and
drop the unused degrade tooltip.
---------
Co-authored-by: hailongzhao <hailongzhao@tencent.com>
Co-authored-by: wizardchen <wizardchen@tencent.com>
2026-09-17 06:20:18 +00:00
|
|
|
"fork_snapshot_leases",
|
2026-08-19 10:54:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// versionedSQLiteColumns maps each existing table to the columns that the
|
|
|
|
|
// versioned migrations add and the SQLite baseline was missing.
|
|
|
|
|
var versionedSQLiteColumns = map[string][]string{
|
feat(session): fork conversations from a historical user message (#3304)
* feat(session): add fork schema and history queries
为会话分叉增加数据模型与迁移,并提供截至分叉点的消息查询以及会话内的 request_id 配对。
* feat(sandbox): add git, fork snapshots, and bootstrap hook
沙箱镜像安装 git,Docker 快照使用独立的 fork 命名空间,并在首次创建会话沙箱时接入可选 bootstrap。
* feat(session): checkpoint workspace at the end of each turn
每轮结束后对沙箱 /workspace 打 git checkpoint,并避免 fork 后因 mtime 刷新重复挂上产物、以及附件仍绑在父会话而无法还原。
* feat(session): fork conversations and reap orphan snapshots
支持从历史 user 消息分叉会话、首次打开时从快照 bootstrap,并在失败或删除未打开的分叉时回收孤儿快照。
* feat(chat): add session fork entry, prefill, and badges
在用户消息上提供分叉入口,进入新会话时预填原问题,并展示降级提示与来源角标。
* style: add missing newline so session_fork_delete_test.go is gofmt-clean
* fix(session): prune later git history when rolling a fork workspace back
reset --hard 只还原工作区,分叉点之后的 commit 仍可被 checkout。校验 SHA 后丢掉其他 ref 并 gc,避免错误基线。
* style(session): clear golangci-lint findings on the session-fork diff
Pre-push lints the whole PR against main; wrap long lines, check c.Error,
and fix gofumpt/revive/staticcheck so the merge can be pushed.
* fix(chat): show the fork button on hover without shifting the thread
Overlay the action so revealing it no longer expands the user bubble and janks the messages below.
* fix(chat): drop the fork landing banners
Keep the original question prefilled; do not explain sandbox snapshot vs checkpoint on the new thread.
* fix(agent): dedupe artifacts by content hash, not size
Same-path same-size rewrites were skipped as restores. Keep path+mtime as the cheap skip, hash bytes when mtime moves, and stamp the restored mtime onto this session only.
* feat(session): allow forking from an assistant answer
User forks still copy history before the question and prefill it. Assistant forks copy through that reply and reuse its checkpoint, with a degrade tooltip when none exists.
* fix(session): resolve parent attachments from a forked chat
Fork copies attachment IDs onto the new messages but leaves temporary_documents on the parent. Preview and Get now look up those IDs on the fork's copied history instead of a scoped miss.
* fix(agent): rewrite sandbox refs after a content-hash skip
Fork restores change mtime on unchanged files, so Collect returns empty
and named citations were left as sandbox: paths. Resolve those names
against session artifacts, notify only real uploads, and stamp restored
mtime only on the matching content hash.
* fix(session): drop a dead fork snapshot and retry checkpoint rewrite
Create from a missing template now abandons bootstrap so the next
Resolve uses a normal sandbox. A failed checkpoint rewrite no longer
marks the bootstrap consumed, which previously made nested forks
SANDBOX_REPLACED.
* fix(session): load forked parent attachments into the prompt
ResolveForPrompt used session-scoped lookup, so copied parent attachment
IDs passed Get but never reached the model. Use the same resolveInSession
path as preview.
* fix(chat): keep the user-message fork button visible
The control was hover-only, which hid it on touch. Always show it, and
drop the unused degrade tooltip.
---------
Co-authored-by: hailongzhao <hailongzhao@tencent.com>
Co-authored-by: wizardchen <wizardchen@tencent.com>
2026-09-17 06:20:18 +00:00
|
|
|
"memory_subjects": {"extraction_state"}, // 000094
|
|
|
|
|
"memory_items": {"replaces_id"}, // 000094
|
|
|
|
|
"tenants": {"api_principal_config"}, // 000064
|
|
|
|
|
"users": {"is_system_admin"}, // 000053
|
feat(knowledge): derive knowledge base descriptions from document profiles (#3370)
* feat(knowledge): derive knowledge base descriptions from document profiles
Knowledge bases only had a hand-written description, which most users
leave empty, so agents bound to several knowledge bases had nothing to
route on and searched all of them. This adds a generated description
that is derived from per-document data instead of maintained by a model.
Document profile: the summary call now returns JSON with a 2-3 sentence
summary plus a gist, 3-5 topic keywords, a document type and one
typical question (knowledges.profile). Input is capped at 8k chars and
output at 1024 tokens; plain-text replies from custom templates still
work and simply carry no profile. The summary chunk embeds the gist and
short summary.
Knowledge base aggregate: a database-only fold over those rows (counts
per file type, tag, normalized topic and doc type; stratified samples of
titles and questions; a hash of the inputs). Deleting, moving or
re-parsing a document changes nothing but the rows, so the next rebuild
is exact without any model judgement.
Description text: one small model call over the aggregate yields a
gist, merged topics and typical questions (knowledge_bases.
generated_profile). The call is skipped when the aggregate hash is
unchanged; failures keep the previous text and record the error; an
empty knowledge base clears it. The manual description is never
touched, and the agent runtime context renders both so the model can
pass knowledge_base_ids instead of fanning out.
Refreshes are requested from summary task exit, post-process completion,
deletion, cross-KB moves and enabling the option, debounced per
knowledge base in 30 s windows via kb:profile on the summary queue.
POST /knowledge-bases/:id/profile/generate regenerates synchronously.
profile_config (enabled, model_id, custom_instructions) opts a document
knowledge base in; the settings dialog shows the generated card with
regenerate and adopt-as-description actions in five locales. Search
results now log hits per chunk type so the value of indexing summary
chunks can be measured.
Migrations 000101 (PostgreSQL) and 000021 (SQLite) add the columns; the
SQLite schema test expects the new version and columns.
* fix(knowledge): keep generated descriptions out of duplicates and refresh clones
DuplicateKnowledgeBase copies the source row through JSON, which carried
generated_profile onto a knowledge base that has no documents yet, so
an empty duplicate advertised the source's topics. The duplicate now
starts without a generated description and keeps profile_config so it
derives its own once documents arrive.
CopyKnowledgeBase builds the target field by field and skipped
profile_config, and the clone task never asked for a description after
copying the documents, so a clone stayed undescribed until its next
upload. The target now carries a copy of profile_config and both clone
paths request a refresh on completion.
* fix(knowledge): refresh the loaded clone target and carry document profiles
ProcessKBClone requested the description refresh with the reservation
stub it builds before CopyKnowledgeBase runs. For the main create path
that stub has neither a type nor profile_config, so the refresh helper
rejected it and nothing was enqueued. The refresh now uses the loaded
target returned by CopyKnowledgeBase.
cloneKnowledge copied the summary text but not the structured profile,
so even a scheduled refresh would have aggregated titles without topics
until every clone was re-summarized. Cloned documents now carry an
independent copy of the profile.
2026-09-17 14:21:55 +00:00
|
|
|
"knowledges": {"pending_subtasks_count", "profile"}, // 000056, 000101
|
|
|
|
|
"knowledge_bases": {"profile_config", "generated_profile"}, // 000101
|
feat(session): fork conversations from a historical user message (#3304)
* feat(session): add fork schema and history queries
为会话分叉增加数据模型与迁移,并提供截至分叉点的消息查询以及会话内的 request_id 配对。
* feat(sandbox): add git, fork snapshots, and bootstrap hook
沙箱镜像安装 git,Docker 快照使用独立的 fork 命名空间,并在首次创建会话沙箱时接入可选 bootstrap。
* feat(session): checkpoint workspace at the end of each turn
每轮结束后对沙箱 /workspace 打 git checkpoint,并避免 fork 后因 mtime 刷新重复挂上产物、以及附件仍绑在父会话而无法还原。
* feat(session): fork conversations and reap orphan snapshots
支持从历史 user 消息分叉会话、首次打开时从快照 bootstrap,并在失败或删除未打开的分叉时回收孤儿快照。
* feat(chat): add session fork entry, prefill, and badges
在用户消息上提供分叉入口,进入新会话时预填原问题,并展示降级提示与来源角标。
* style: add missing newline so session_fork_delete_test.go is gofmt-clean
* fix(session): prune later git history when rolling a fork workspace back
reset --hard 只还原工作区,分叉点之后的 commit 仍可被 checkout。校验 SHA 后丢掉其他 ref 并 gc,避免错误基线。
* style(session): clear golangci-lint findings on the session-fork diff
Pre-push lints the whole PR against main; wrap long lines, check c.Error,
and fix gofumpt/revive/staticcheck so the merge can be pushed.
* fix(chat): show the fork button on hover without shifting the thread
Overlay the action so revealing it no longer expands the user bubble and janks the messages below.
* fix(chat): drop the fork landing banners
Keep the original question prefilled; do not explain sandbox snapshot vs checkpoint on the new thread.
* fix(agent): dedupe artifacts by content hash, not size
Same-path same-size rewrites were skipped as restores. Keep path+mtime as the cheap skip, hash bytes when mtime moves, and stamp the restored mtime onto this session only.
* feat(session): allow forking from an assistant answer
User forks still copy history before the question and prefill it. Assistant forks copy through that reply and reuse its checkpoint, with a degrade tooltip when none exists.
* fix(session): resolve parent attachments from a forked chat
Fork copies attachment IDs onto the new messages but leaves temporary_documents on the parent. Preview and Get now look up those IDs on the fork's copied history instead of a scoped miss.
* fix(agent): rewrite sandbox refs after a content-hash skip
Fork restores change mtime on unchanged files, so Collect returns empty
and named citations were left as sandbox: paths. Resolve those names
against session artifacts, notify only real uploads, and stamp restored
mtime only on the matching content hash.
* fix(session): drop a dead fork snapshot and retry checkpoint rewrite
Create from a missing template now abandons bootstrap so the next
Resolve uses a normal sandbox. A failed checkpoint rewrite no longer
marks the bootstrap consumed, which previously made nested forks
SANDBOX_REPLACED.
* fix(session): load forked parent attachments into the prompt
ResolveForPrompt used session-scoped lookup, so copied parent attachment
IDs passed Get but never reached the model. Use the same resolveInSession
path as preview.
* fix(chat): keep the user-message fork button visible
The control was hover-only, which hid it on touch. Always show it, and
drop the unused degrade tooltip.
---------
Co-authored-by: hailongzhao <hailongzhao@tencent.com>
Co-authored-by: wizardchen <wizardchen@tencent.com>
2026-09-17 06:20:18 +00:00
|
|
|
"messages": {"attachments", "usage", "sandbox_checkpoint"}, // 000034, 000085, 000097
|
|
|
|
|
"sessions": {"parent_session_id", "forked_from_message_id", "fork_bootstrap"}, // 000097
|
|
|
|
|
"tenant_invitations": {"token", "accepted_count"}, // 000054
|
|
|
|
|
"embed_channels": {"allow_memory"}, // 000060
|
|
|
|
|
"mcp_oauth_tokens": {"principal_type", "principal_id"}, // 000064
|
|
|
|
|
"mcp_tool_approvals": {"enabled"}, // 000091
|
2026-08-19 10:54:55 +00:00
|
|
|
}
|
|
|
|
|
|
feat(knowledge): derive knowledge base descriptions from document profiles (#3370)
* feat(knowledge): derive knowledge base descriptions from document profiles
Knowledge bases only had a hand-written description, which most users
leave empty, so agents bound to several knowledge bases had nothing to
route on and searched all of them. This adds a generated description
that is derived from per-document data instead of maintained by a model.
Document profile: the summary call now returns JSON with a 2-3 sentence
summary plus a gist, 3-5 topic keywords, a document type and one
typical question (knowledges.profile). Input is capped at 8k chars and
output at 1024 tokens; plain-text replies from custom templates still
work and simply carry no profile. The summary chunk embeds the gist and
short summary.
Knowledge base aggregate: a database-only fold over those rows (counts
per file type, tag, normalized topic and doc type; stratified samples of
titles and questions; a hash of the inputs). Deleting, moving or
re-parsing a document changes nothing but the rows, so the next rebuild
is exact without any model judgement.
Description text: one small model call over the aggregate yields a
gist, merged topics and typical questions (knowledge_bases.
generated_profile). The call is skipped when the aggregate hash is
unchanged; failures keep the previous text and record the error; an
empty knowledge base clears it. The manual description is never
touched, and the agent runtime context renders both so the model can
pass knowledge_base_ids instead of fanning out.
Refreshes are requested from summary task exit, post-process completion,
deletion, cross-KB moves and enabling the option, debounced per
knowledge base in 30 s windows via kb:profile on the summary queue.
POST /knowledge-bases/:id/profile/generate regenerates synchronously.
profile_config (enabled, model_id, custom_instructions) opts a document
knowledge base in; the settings dialog shows the generated card with
regenerate and adopt-as-description actions in five locales. Search
results now log hits per chunk type so the value of indexing summary
chunks can be measured.
Migrations 000101 (PostgreSQL) and 000021 (SQLite) add the columns; the
SQLite schema test expects the new version and columns.
* fix(knowledge): keep generated descriptions out of duplicates and refresh clones
DuplicateKnowledgeBase copies the source row through JSON, which carried
generated_profile onto a knowledge base that has no documents yet, so
an empty duplicate advertised the source's topics. The duplicate now
starts without a generated description and keeps profile_config so it
derives its own once documents arrive.
CopyKnowledgeBase builds the target field by field and skipped
profile_config, and the clone task never asked for a description after
copying the documents, so a clone stayed undescribed until its next
upload. The target now carries a copy of profile_config and both clone
paths request a refresh on completion.
* fix(knowledge): refresh the loaded clone target and carry document profiles
ProcessKBClone requested the description refresh with the reservation
stub it builds before CopyKnowledgeBase runs. For the main create path
that stub has neither a type nor profile_config, so the refresh helper
rejected it and nothing was enqueued. The refresh now uses the loaded
target returned by CopyKnowledgeBase.
cloneKnowledge copied the summary text but not the structured profile,
so even a scheduled refresh would have aggregated titles without topics
until every clone was re-summarized. Cloned documents now carry an
independent copy of the profile.
2026-09-17 14:21:55 +00:00
|
|
|
const expectedSQLiteMigrationVersion = 21
|
2026-08-19 10:54:55 +00:00
|
|
|
|
|
|
|
|
func TestSQLiteMigrationsCreateVersionedSchema(t *testing.T) {
|
|
|
|
|
repoRoot := sqliteRepoRoot(t)
|
|
|
|
|
chdirAndRestore(t, repoRoot)
|
|
|
|
|
|
|
|
|
|
dbPath := filepath.Join(t.TempDir(), "fresh.db")
|
|
|
|
|
require.NoError(t, RunMigrationsWithOptions("sqlite3://unused", MigrationOptions{SQLiteDBPath: dbPath}))
|
|
|
|
|
|
|
|
|
|
db := openSQLiteDB(t, dbPath)
|
|
|
|
|
version, dirty := sqliteMigrationState(t, db)
|
|
|
|
|
require.Equal(t, expectedSQLiteMigrationVersion, version)
|
|
|
|
|
require.False(t, dirty)
|
|
|
|
|
|
|
|
|
|
for _, table := range versionedSQLiteTables {
|
|
|
|
|
require.Truef(t, sqliteTableExists(t, db, table), "SQLite migrations must create table %s", table)
|
|
|
|
|
}
|
|
|
|
|
for table, columns := range versionedSQLiteColumns {
|
|
|
|
|
for _, column := range columns {
|
|
|
|
|
require.Truef(
|
|
|
|
|
t,
|
|
|
|
|
sqliteColumnExists(t, db, table, column),
|
|
|
|
|
"SQLite migrations must add column %s.%s",
|
|
|
|
|
table,
|
|
|
|
|
column,
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-08-20 03:46:38 +00:00
|
|
|
|
|
|
|
|
assertSQLiteShareLinkInvitationsWork(t, db)
|
|
|
|
|
assertSQLiteMCPOAuthPrincipalUpsertWorks(t, db)
|
|
|
|
|
require.False(t, sqliteColumnExists(t, db, "knowledges", "tag_id"),
|
|
|
|
|
"SQLite migrations must drop legacy knowledges.tag_id after multi-tag migration")
|
2026-08-19 10:54:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestSQLiteMigrationsUpgradeV4PreservesData(t *testing.T) {
|
|
|
|
|
repoRoot := sqliteRepoRoot(t)
|
|
|
|
|
|
|
|
|
|
// Build a legacy v4 migration root (000000_init .. 000004_memory) so we
|
|
|
|
|
// can prove the new migrations upgrade an existing Lite database without
|
|
|
|
|
// replaying the baseline.
|
|
|
|
|
legacyRoot := copySQLiteMigrationsV4(t, repoRoot)
|
|
|
|
|
chdirAndRestore(t, legacyRoot)
|
|
|
|
|
|
|
|
|
|
dbPath := filepath.Join(t.TempDir(), "upgrade.db")
|
|
|
|
|
require.NoError(t, RunMigrationsWithOptions("sqlite3://unused", MigrationOptions{SQLiteDBPath: dbPath}))
|
|
|
|
|
|
|
|
|
|
db := openSQLiteDB(t, dbPath)
|
|
|
|
|
versionBefore, dirtyBefore := sqliteMigrationState(t, db)
|
|
|
|
|
require.Equal(t, 4, versionBefore)
|
|
|
|
|
require.False(t, dirtyBefore)
|
|
|
|
|
_, err := db.Exec("INSERT INTO tenants (name, business) VALUES (?, ?)", "upgrade-sentinel", "migration-test")
|
|
|
|
|
require.NoError(t, err)
|
2026-08-20 03:46:38 +00:00
|
|
|
_, err = db.Exec(
|
|
|
|
|
"INSERT INTO knowledges (id, tenant_id, knowledge_base_id, type, title, source, tag_id) "+
|
|
|
|
|
"VALUES (?, 1, ?, 'document', 'tagged-doc', 'manual', ?)",
|
|
|
|
|
"legacy-knowledge-1", "legacy-kb-1", "legacy-tag-1",
|
|
|
|
|
)
|
|
|
|
|
require.NoError(t, err)
|
2026-08-19 10:54:55 +00:00
|
|
|
|
|
|
|
|
// Run the full migration set from the repo root.
|
|
|
|
|
chdirAndRestore(t, repoRoot)
|
|
|
|
|
require.NoError(t, RunMigrationsWithOptions("sqlite3://unused", MigrationOptions{SQLiteDBPath: dbPath}))
|
|
|
|
|
|
|
|
|
|
db = openSQLiteDB(t, dbPath)
|
|
|
|
|
versionAfter, dirtyAfter := sqliteMigrationState(t, db)
|
|
|
|
|
require.Equal(t, expectedSQLiteMigrationVersion, versionAfter)
|
|
|
|
|
require.False(t, dirtyAfter)
|
|
|
|
|
|
|
|
|
|
for _, table := range versionedSQLiteTables {
|
|
|
|
|
require.Truef(t, sqliteTableExists(t, db, table), "upgraded SQLite DB must have table %s", table)
|
|
|
|
|
}
|
|
|
|
|
for table, columns := range versionedSQLiteColumns {
|
|
|
|
|
for _, column := range columns {
|
|
|
|
|
require.Truef(
|
|
|
|
|
t,
|
|
|
|
|
sqliteColumnExists(t, db, table, column),
|
|
|
|
|
"upgraded SQLite DB must have column %s.%s",
|
|
|
|
|
table,
|
|
|
|
|
column,
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var sentinelName string
|
|
|
|
|
require.NoError(t, db.QueryRow("SELECT name FROM tenants WHERE business = ?", "migration-test").Scan(&sentinelName))
|
|
|
|
|
require.Equal(t, "upgrade-sentinel", sentinelName)
|
2026-08-20 03:46:38 +00:00
|
|
|
|
|
|
|
|
var relationCount int
|
|
|
|
|
require.NoError(t, db.QueryRow(
|
|
|
|
|
"SELECT COUNT(*) FROM knowledge_tag_relations WHERE knowledge_id = ? AND tag_id = ?",
|
|
|
|
|
"legacy-knowledge-1", "legacy-tag-1",
|
|
|
|
|
).Scan(&relationCount))
|
|
|
|
|
require.Equal(t, 1, relationCount)
|
|
|
|
|
require.False(t, sqliteColumnExists(t, db, "knowledges", "tag_id"))
|
2026-08-19 10:54:55 +00:00
|
|
|
}
|
|
|
|
|
|
feat(session): fork conversations from a historical user message (#3304)
* feat(session): add fork schema and history queries
为会话分叉增加数据模型与迁移,并提供截至分叉点的消息查询以及会话内的 request_id 配对。
* feat(sandbox): add git, fork snapshots, and bootstrap hook
沙箱镜像安装 git,Docker 快照使用独立的 fork 命名空间,并在首次创建会话沙箱时接入可选 bootstrap。
* feat(session): checkpoint workspace at the end of each turn
每轮结束后对沙箱 /workspace 打 git checkpoint,并避免 fork 后因 mtime 刷新重复挂上产物、以及附件仍绑在父会话而无法还原。
* feat(session): fork conversations and reap orphan snapshots
支持从历史 user 消息分叉会话、首次打开时从快照 bootstrap,并在失败或删除未打开的分叉时回收孤儿快照。
* feat(chat): add session fork entry, prefill, and badges
在用户消息上提供分叉入口,进入新会话时预填原问题,并展示降级提示与来源角标。
* style: add missing newline so session_fork_delete_test.go is gofmt-clean
* fix(session): prune later git history when rolling a fork workspace back
reset --hard 只还原工作区,分叉点之后的 commit 仍可被 checkout。校验 SHA 后丢掉其他 ref 并 gc,避免错误基线。
* style(session): clear golangci-lint findings on the session-fork diff
Pre-push lints the whole PR against main; wrap long lines, check c.Error,
and fix gofumpt/revive/staticcheck so the merge can be pushed.
* fix(chat): show the fork button on hover without shifting the thread
Overlay the action so revealing it no longer expands the user bubble and janks the messages below.
* fix(chat): drop the fork landing banners
Keep the original question prefilled; do not explain sandbox snapshot vs checkpoint on the new thread.
* fix(agent): dedupe artifacts by content hash, not size
Same-path same-size rewrites were skipped as restores. Keep path+mtime as the cheap skip, hash bytes when mtime moves, and stamp the restored mtime onto this session only.
* feat(session): allow forking from an assistant answer
User forks still copy history before the question and prefill it. Assistant forks copy through that reply and reuse its checkpoint, with a degrade tooltip when none exists.
* fix(session): resolve parent attachments from a forked chat
Fork copies attachment IDs onto the new messages but leaves temporary_documents on the parent. Preview and Get now look up those IDs on the fork's copied history instead of a scoped miss.
* fix(agent): rewrite sandbox refs after a content-hash skip
Fork restores change mtime on unchanged files, so Collect returns empty
and named citations were left as sandbox: paths. Resolve those names
against session artifacts, notify only real uploads, and stamp restored
mtime only on the matching content hash.
* fix(session): drop a dead fork snapshot and retry checkpoint rewrite
Create from a missing template now abandons bootstrap so the next
Resolve uses a normal sandbox. A failed checkpoint rewrite no longer
marks the bootstrap consumed, which previously made nested forks
SANDBOX_REPLACED.
* fix(session): load forked parent attachments into the prompt
ResolveForPrompt used session-scoped lookup, so copied parent attachment
IDs passed Get but never reached the model. Use the same resolveInSession
path as preview.
* fix(chat): keep the user-message fork button visible
The control was hover-only, which hid it on touch. Always show it, and
drop the unused degrade tooltip.
---------
Co-authored-by: hailongzhao <hailongzhao@tencent.com>
Co-authored-by: wizardchen <wizardchen@tencent.com>
2026-09-17 06:20:18 +00:00
|
|
|
func TestSQLiteMigrationsUpgradeV16AddsSessionForkColumns(t *testing.T) {
|
|
|
|
|
repoRoot := sqliteRepoRoot(t)
|
|
|
|
|
|
|
|
|
|
legacyRoot := copySQLiteMigrationsThrough(t, repoRoot, 16)
|
|
|
|
|
chdirAndRestore(t, legacyRoot)
|
|
|
|
|
|
|
|
|
|
dbPath := filepath.Join(t.TempDir(), "upgrade-v16.db")
|
|
|
|
|
require.NoError(t, RunMigrationsWithOptions("sqlite3://unused", MigrationOptions{SQLiteDBPath: dbPath}))
|
|
|
|
|
|
|
|
|
|
db := openSQLiteDB(t, dbPath)
|
|
|
|
|
versionBefore, dirtyBefore := sqliteMigrationState(t, db)
|
|
|
|
|
require.Equal(t, 16, versionBefore)
|
|
|
|
|
require.False(t, dirtyBefore)
|
|
|
|
|
require.False(t, sqliteColumnExists(t, db, "sessions", "parent_session_id"))
|
|
|
|
|
require.False(t, sqliteColumnExists(t, db, "sessions", "forked_from_message_id"))
|
|
|
|
|
require.False(t, sqliteColumnExists(t, db, "sessions", "fork_bootstrap"))
|
|
|
|
|
require.False(t, sqliteColumnExists(t, db, "messages", "sandbox_checkpoint"))
|
|
|
|
|
|
|
|
|
|
chdirAndRestore(t, repoRoot)
|
|
|
|
|
require.NoError(t, RunMigrationsWithOptions("sqlite3://unused", MigrationOptions{SQLiteDBPath: dbPath}))
|
|
|
|
|
|
|
|
|
|
db = openSQLiteDB(t, dbPath)
|
|
|
|
|
versionAfter, dirtyAfter := sqliteMigrationState(t, db)
|
|
|
|
|
require.Equal(t, expectedSQLiteMigrationVersion, versionAfter)
|
|
|
|
|
require.False(t, dirtyAfter)
|
|
|
|
|
for _, column := range versionedSQLiteColumns["sessions"] {
|
|
|
|
|
require.Truef(
|
|
|
|
|
t,
|
|
|
|
|
sqliteColumnExists(t, db, "sessions", column),
|
|
|
|
|
"upgraded SQLite DB must have column sessions.%s",
|
|
|
|
|
column,
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
require.True(t, sqliteColumnExists(t, db, "messages", "sandbox_checkpoint"))
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-19 10:54:55 +00:00
|
|
|
func sqliteRepoRoot(t *testing.T) string {
|
|
|
|
|
t.Helper()
|
|
|
|
|
repoRoot, err := filepath.Abs(filepath.Join("..", ".."))
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
return repoRoot
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func chdirAndRestore(t *testing.T, dir string) {
|
|
|
|
|
t.Helper()
|
|
|
|
|
previousDir, err := os.Getwd()
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
require.NoError(t, os.Chdir(dir))
|
|
|
|
|
t.Cleanup(func() { _ = os.Chdir(previousDir) })
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func openSQLiteDB(t *testing.T, dbPath string) *sql.DB {
|
|
|
|
|
t.Helper()
|
|
|
|
|
db, err := sql.Open("sqlite3", dbPath)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
t.Cleanup(func() { _ = db.Close() })
|
|
|
|
|
return db
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func sqliteMigrationState(t *testing.T, db *sql.DB) (version int, dirty bool) {
|
|
|
|
|
t.Helper()
|
|
|
|
|
require.NoError(t, db.QueryRow("SELECT version, dirty FROM schema_migrations").Scan(&version, &dirty))
|
|
|
|
|
return version, dirty
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func sqliteTableExists(t *testing.T, db *sql.DB, table string) bool {
|
|
|
|
|
t.Helper()
|
|
|
|
|
var n int
|
|
|
|
|
require.NoError(t, db.QueryRow(
|
|
|
|
|
"SELECT COUNT(*) FROM sqlite_master WHERE type = 'table' AND name = ?",
|
|
|
|
|
table,
|
|
|
|
|
).Scan(&n))
|
|
|
|
|
return n == 1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func sqliteColumnExists(t *testing.T, db *sql.DB, table, column string) bool {
|
|
|
|
|
t.Helper()
|
|
|
|
|
var n int
|
|
|
|
|
require.NoError(t, db.QueryRow(
|
|
|
|
|
"SELECT COUNT(*) FROM pragma_table_info(?) WHERE name = ?",
|
|
|
|
|
table,
|
|
|
|
|
column,
|
|
|
|
|
).Scan(&n))
|
|
|
|
|
return n == 1
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-20 03:46:38 +00:00
|
|
|
func assertSQLiteShareLinkInvitationsWork(t *testing.T, db *sql.DB) {
|
|
|
|
|
t.Helper()
|
|
|
|
|
_, err := db.Exec("INSERT INTO tenants (name, business) VALUES (?, ?)", "share-link-tenant", "share-link-test")
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
|
|
expiresAt := "2099-01-01 00:00:00"
|
|
|
|
|
shareLinkInsert := "INSERT INTO tenant_invitations " +
|
|
|
|
|
"(tenant_id, invitee_user_id, token, role, status, expires_at) " +
|
|
|
|
|
"VALUES (1, '', ?, 'member', 'pending', ?)"
|
|
|
|
|
_, err = db.Exec(shareLinkInsert, "token-a", expiresAt)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
_, err = db.Exec(shareLinkInsert, "token-b", expiresAt)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
|
|
var count int
|
|
|
|
|
require.NoError(t, db.QueryRow(
|
|
|
|
|
"SELECT COUNT(*) FROM tenant_invitations WHERE tenant_id = 1 AND invitee_user_id = '' AND status = 'pending'",
|
|
|
|
|
).Scan(&count))
|
|
|
|
|
require.Equal(t, 2, count)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func assertSQLiteMCPOAuthPrincipalUpsertWorks(t *testing.T, db *sql.DB) {
|
|
|
|
|
t.Helper()
|
|
|
|
|
_, err := db.Exec(
|
|
|
|
|
"INSERT INTO mcp_services (id, tenant_id, name, transport_type) VALUES (?, 1, 'svc', 'http')",
|
|
|
|
|
"svc-migration-1",
|
|
|
|
|
)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
|
|
tokenInsertPrefix := "INSERT INTO mcp_oauth_tokens " +
|
|
|
|
|
"(id, tenant_id, user_id, service_id, principal_type, principal_id, access_token) "
|
|
|
|
|
_, err = db.Exec(
|
|
|
|
|
tokenInsertPrefix +
|
|
|
|
|
"VALUES ('tok-1', 1, 'u1', 'svc-migration-1', 'web_user', 'u1', 'token-1')",
|
|
|
|
|
)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
|
|
_, err = db.Exec(
|
|
|
|
|
tokenInsertPrefix +
|
|
|
|
|
"VALUES ('tok-2', 1, 'u1', 'svc-migration-1', 'web_user', 'u1', 'token-2') " +
|
|
|
|
|
"ON CONFLICT(tenant_id, principal_type, principal_id, service_id) " +
|
|
|
|
|
"DO UPDATE SET access_token = excluded.access_token",
|
|
|
|
|
)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
|
|
var accessToken string
|
|
|
|
|
require.NoError(t, db.QueryRow(
|
|
|
|
|
"SELECT access_token FROM mcp_oauth_tokens "+
|
|
|
|
|
"WHERE tenant_id = 1 AND principal_type = 'web_user' "+
|
|
|
|
|
"AND principal_id = 'u1' AND service_id = 'svc-migration-1'",
|
|
|
|
|
).Scan(&accessToken))
|
|
|
|
|
require.Equal(t, "token-2", accessToken)
|
|
|
|
|
|
|
|
|
|
var rowCount int
|
|
|
|
|
require.NoError(t, db.QueryRow(
|
|
|
|
|
"SELECT COUNT(*) FROM mcp_oauth_tokens WHERE tenant_id = 1 AND service_id = 'svc-migration-1'",
|
|
|
|
|
).Scan(&rowCount))
|
|
|
|
|
require.Equal(t, 1, rowCount)
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-19 10:54:55 +00:00
|
|
|
func copySQLiteMigrationsV4(t *testing.T, repoRoot string) string {
|
feat(session): fork conversations from a historical user message (#3304)
* feat(session): add fork schema and history queries
为会话分叉增加数据模型与迁移,并提供截至分叉点的消息查询以及会话内的 request_id 配对。
* feat(sandbox): add git, fork snapshots, and bootstrap hook
沙箱镜像安装 git,Docker 快照使用独立的 fork 命名空间,并在首次创建会话沙箱时接入可选 bootstrap。
* feat(session): checkpoint workspace at the end of each turn
每轮结束后对沙箱 /workspace 打 git checkpoint,并避免 fork 后因 mtime 刷新重复挂上产物、以及附件仍绑在父会话而无法还原。
* feat(session): fork conversations and reap orphan snapshots
支持从历史 user 消息分叉会话、首次打开时从快照 bootstrap,并在失败或删除未打开的分叉时回收孤儿快照。
* feat(chat): add session fork entry, prefill, and badges
在用户消息上提供分叉入口,进入新会话时预填原问题,并展示降级提示与来源角标。
* style: add missing newline so session_fork_delete_test.go is gofmt-clean
* fix(session): prune later git history when rolling a fork workspace back
reset --hard 只还原工作区,分叉点之后的 commit 仍可被 checkout。校验 SHA 后丢掉其他 ref 并 gc,避免错误基线。
* style(session): clear golangci-lint findings on the session-fork diff
Pre-push lints the whole PR against main; wrap long lines, check c.Error,
and fix gofumpt/revive/staticcheck so the merge can be pushed.
* fix(chat): show the fork button on hover without shifting the thread
Overlay the action so revealing it no longer expands the user bubble and janks the messages below.
* fix(chat): drop the fork landing banners
Keep the original question prefilled; do not explain sandbox snapshot vs checkpoint on the new thread.
* fix(agent): dedupe artifacts by content hash, not size
Same-path same-size rewrites were skipped as restores. Keep path+mtime as the cheap skip, hash bytes when mtime moves, and stamp the restored mtime onto this session only.
* feat(session): allow forking from an assistant answer
User forks still copy history before the question and prefill it. Assistant forks copy through that reply and reuse its checkpoint, with a degrade tooltip when none exists.
* fix(session): resolve parent attachments from a forked chat
Fork copies attachment IDs onto the new messages but leaves temporary_documents on the parent. Preview and Get now look up those IDs on the fork's copied history instead of a scoped miss.
* fix(agent): rewrite sandbox refs after a content-hash skip
Fork restores change mtime on unchanged files, so Collect returns empty
and named citations were left as sandbox: paths. Resolve those names
against session artifacts, notify only real uploads, and stamp restored
mtime only on the matching content hash.
* fix(session): drop a dead fork snapshot and retry checkpoint rewrite
Create from a missing template now abandons bootstrap so the next
Resolve uses a normal sandbox. A failed checkpoint rewrite no longer
marks the bootstrap consumed, which previously made nested forks
SANDBOX_REPLACED.
* fix(session): load forked parent attachments into the prompt
ResolveForPrompt used session-scoped lookup, so copied parent attachment
IDs passed Get but never reached the model. Use the same resolveInSession
path as preview.
* fix(chat): keep the user-message fork button visible
The control was hover-only, which hid it on touch. Always show it, and
drop the unused degrade tooltip.
---------
Co-authored-by: hailongzhao <hailongzhao@tencent.com>
Co-authored-by: wizardchen <wizardchen@tencent.com>
2026-09-17 06:20:18 +00:00
|
|
|
t.Helper()
|
|
|
|
|
return copySQLiteMigrationsThrough(t, repoRoot, 4)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func copySQLiteMigrationsThrough(t *testing.T, repoRoot string, maxVersion int) string {
|
2026-08-19 10:54:55 +00:00
|
|
|
t.Helper()
|
|
|
|
|
dest := t.TempDir()
|
|
|
|
|
srcDir := filepath.Join(repoRoot, "migrations", "sqlite")
|
|
|
|
|
destDir := filepath.Join(dest, "migrations", "sqlite")
|
|
|
|
|
require.NoError(t, os.MkdirAll(destDir, 0o755))
|
|
|
|
|
|
feat(session): fork conversations from a historical user message (#3304)
* feat(session): add fork schema and history queries
为会话分叉增加数据模型与迁移,并提供截至分叉点的消息查询以及会话内的 request_id 配对。
* feat(sandbox): add git, fork snapshots, and bootstrap hook
沙箱镜像安装 git,Docker 快照使用独立的 fork 命名空间,并在首次创建会话沙箱时接入可选 bootstrap。
* feat(session): checkpoint workspace at the end of each turn
每轮结束后对沙箱 /workspace 打 git checkpoint,并避免 fork 后因 mtime 刷新重复挂上产物、以及附件仍绑在父会话而无法还原。
* feat(session): fork conversations and reap orphan snapshots
支持从历史 user 消息分叉会话、首次打开时从快照 bootstrap,并在失败或删除未打开的分叉时回收孤儿快照。
* feat(chat): add session fork entry, prefill, and badges
在用户消息上提供分叉入口,进入新会话时预填原问题,并展示降级提示与来源角标。
* style: add missing newline so session_fork_delete_test.go is gofmt-clean
* fix(session): prune later git history when rolling a fork workspace back
reset --hard 只还原工作区,分叉点之后的 commit 仍可被 checkout。校验 SHA 后丢掉其他 ref 并 gc,避免错误基线。
* style(session): clear golangci-lint findings on the session-fork diff
Pre-push lints the whole PR against main; wrap long lines, check c.Error,
and fix gofumpt/revive/staticcheck so the merge can be pushed.
* fix(chat): show the fork button on hover without shifting the thread
Overlay the action so revealing it no longer expands the user bubble and janks the messages below.
* fix(chat): drop the fork landing banners
Keep the original question prefilled; do not explain sandbox snapshot vs checkpoint on the new thread.
* fix(agent): dedupe artifacts by content hash, not size
Same-path same-size rewrites were skipped as restores. Keep path+mtime as the cheap skip, hash bytes when mtime moves, and stamp the restored mtime onto this session only.
* feat(session): allow forking from an assistant answer
User forks still copy history before the question and prefill it. Assistant forks copy through that reply and reuse its checkpoint, with a degrade tooltip when none exists.
* fix(session): resolve parent attachments from a forked chat
Fork copies attachment IDs onto the new messages but leaves temporary_documents on the parent. Preview and Get now look up those IDs on the fork's copied history instead of a scoped miss.
* fix(agent): rewrite sandbox refs after a content-hash skip
Fork restores change mtime on unchanged files, so Collect returns empty
and named citations were left as sandbox: paths. Resolve those names
against session artifacts, notify only real uploads, and stamp restored
mtime only on the matching content hash.
* fix(session): drop a dead fork snapshot and retry checkpoint rewrite
Create from a missing template now abandons bootstrap so the next
Resolve uses a normal sandbox. A failed checkpoint rewrite no longer
marks the bootstrap consumed, which previously made nested forks
SANDBOX_REPLACED.
* fix(session): load forked parent attachments into the prompt
ResolveForPrompt used session-scoped lookup, so copied parent attachment
IDs passed Get but never reached the model. Use the same resolveInSession
path as preview.
* fix(chat): keep the user-message fork button visible
The control was hover-only, which hid it on touch. Always show it, and
drop the unused degrade tooltip.
---------
Co-authored-by: hailongzhao <hailongzhao@tencent.com>
Co-authored-by: wizardchen <wizardchen@tencent.com>
2026-09-17 06:20:18 +00:00
|
|
|
entries, err := os.ReadDir(srcDir)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
copied := 0
|
|
|
|
|
for _, entry := range entries {
|
|
|
|
|
name := entry.Name()
|
|
|
|
|
if entry.IsDir() || !strings.HasSuffix(name, ".up.sql") {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
var version int
|
|
|
|
|
_, scanErr := fmt.Sscanf(name, "%d_", &version)
|
|
|
|
|
require.NoError(t, scanErr, "sqlite migration filename %s", name)
|
|
|
|
|
if version > maxVersion {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
data, readErr := os.ReadFile(filepath.Join(srcDir, name))
|
|
|
|
|
require.NoError(t, readErr)
|
2026-08-19 10:54:55 +00:00
|
|
|
require.NoError(t, os.WriteFile(filepath.Join(destDir, name), data, 0o600))
|
feat(session): fork conversations from a historical user message (#3304)
* feat(session): add fork schema and history queries
为会话分叉增加数据模型与迁移,并提供截至分叉点的消息查询以及会话内的 request_id 配对。
* feat(sandbox): add git, fork snapshots, and bootstrap hook
沙箱镜像安装 git,Docker 快照使用独立的 fork 命名空间,并在首次创建会话沙箱时接入可选 bootstrap。
* feat(session): checkpoint workspace at the end of each turn
每轮结束后对沙箱 /workspace 打 git checkpoint,并避免 fork 后因 mtime 刷新重复挂上产物、以及附件仍绑在父会话而无法还原。
* feat(session): fork conversations and reap orphan snapshots
支持从历史 user 消息分叉会话、首次打开时从快照 bootstrap,并在失败或删除未打开的分叉时回收孤儿快照。
* feat(chat): add session fork entry, prefill, and badges
在用户消息上提供分叉入口,进入新会话时预填原问题,并展示降级提示与来源角标。
* style: add missing newline so session_fork_delete_test.go is gofmt-clean
* fix(session): prune later git history when rolling a fork workspace back
reset --hard 只还原工作区,分叉点之后的 commit 仍可被 checkout。校验 SHA 后丢掉其他 ref 并 gc,避免错误基线。
* style(session): clear golangci-lint findings on the session-fork diff
Pre-push lints the whole PR against main; wrap long lines, check c.Error,
and fix gofumpt/revive/staticcheck so the merge can be pushed.
* fix(chat): show the fork button on hover without shifting the thread
Overlay the action so revealing it no longer expands the user bubble and janks the messages below.
* fix(chat): drop the fork landing banners
Keep the original question prefilled; do not explain sandbox snapshot vs checkpoint on the new thread.
* fix(agent): dedupe artifacts by content hash, not size
Same-path same-size rewrites were skipped as restores. Keep path+mtime as the cheap skip, hash bytes when mtime moves, and stamp the restored mtime onto this session only.
* feat(session): allow forking from an assistant answer
User forks still copy history before the question and prefill it. Assistant forks copy through that reply and reuse its checkpoint, with a degrade tooltip when none exists.
* fix(session): resolve parent attachments from a forked chat
Fork copies attachment IDs onto the new messages but leaves temporary_documents on the parent. Preview and Get now look up those IDs on the fork's copied history instead of a scoped miss.
* fix(agent): rewrite sandbox refs after a content-hash skip
Fork restores change mtime on unchanged files, so Collect returns empty
and named citations were left as sandbox: paths. Resolve those names
against session artifacts, notify only real uploads, and stamp restored
mtime only on the matching content hash.
* fix(session): drop a dead fork snapshot and retry checkpoint rewrite
Create from a missing template now abandons bootstrap so the next
Resolve uses a normal sandbox. A failed checkpoint rewrite no longer
marks the bootstrap consumed, which previously made nested forks
SANDBOX_REPLACED.
* fix(session): load forked parent attachments into the prompt
ResolveForPrompt used session-scoped lookup, so copied parent attachment
IDs passed Get but never reached the model. Use the same resolveInSession
path as preview.
* fix(chat): keep the user-message fork button visible
The control was hover-only, which hid it on touch. Always show it, and
drop the unused degrade tooltip.
---------
Co-authored-by: hailongzhao <hailongzhao@tencent.com>
Co-authored-by: wizardchen <wizardchen@tencent.com>
2026-09-17 06:20:18 +00:00
|
|
|
copied++
|
2026-08-19 10:54:55 +00:00
|
|
|
}
|
feat(session): fork conversations from a historical user message (#3304)
* feat(session): add fork schema and history queries
为会话分叉增加数据模型与迁移,并提供截至分叉点的消息查询以及会话内的 request_id 配对。
* feat(sandbox): add git, fork snapshots, and bootstrap hook
沙箱镜像安装 git,Docker 快照使用独立的 fork 命名空间,并在首次创建会话沙箱时接入可选 bootstrap。
* feat(session): checkpoint workspace at the end of each turn
每轮结束后对沙箱 /workspace 打 git checkpoint,并避免 fork 后因 mtime 刷新重复挂上产物、以及附件仍绑在父会话而无法还原。
* feat(session): fork conversations and reap orphan snapshots
支持从历史 user 消息分叉会话、首次打开时从快照 bootstrap,并在失败或删除未打开的分叉时回收孤儿快照。
* feat(chat): add session fork entry, prefill, and badges
在用户消息上提供分叉入口,进入新会话时预填原问题,并展示降级提示与来源角标。
* style: add missing newline so session_fork_delete_test.go is gofmt-clean
* fix(session): prune later git history when rolling a fork workspace back
reset --hard 只还原工作区,分叉点之后的 commit 仍可被 checkout。校验 SHA 后丢掉其他 ref 并 gc,避免错误基线。
* style(session): clear golangci-lint findings on the session-fork diff
Pre-push lints the whole PR against main; wrap long lines, check c.Error,
and fix gofumpt/revive/staticcheck so the merge can be pushed.
* fix(chat): show the fork button on hover without shifting the thread
Overlay the action so revealing it no longer expands the user bubble and janks the messages below.
* fix(chat): drop the fork landing banners
Keep the original question prefilled; do not explain sandbox snapshot vs checkpoint on the new thread.
* fix(agent): dedupe artifacts by content hash, not size
Same-path same-size rewrites were skipped as restores. Keep path+mtime as the cheap skip, hash bytes when mtime moves, and stamp the restored mtime onto this session only.
* feat(session): allow forking from an assistant answer
User forks still copy history before the question and prefill it. Assistant forks copy through that reply and reuse its checkpoint, with a degrade tooltip when none exists.
* fix(session): resolve parent attachments from a forked chat
Fork copies attachment IDs onto the new messages but leaves temporary_documents on the parent. Preview and Get now look up those IDs on the fork's copied history instead of a scoped miss.
* fix(agent): rewrite sandbox refs after a content-hash skip
Fork restores change mtime on unchanged files, so Collect returns empty
and named citations were left as sandbox: paths. Resolve those names
against session artifacts, notify only real uploads, and stamp restored
mtime only on the matching content hash.
* fix(session): drop a dead fork snapshot and retry checkpoint rewrite
Create from a missing template now abandons bootstrap so the next
Resolve uses a normal sandbox. A failed checkpoint rewrite no longer
marks the bootstrap consumed, which previously made nested forks
SANDBOX_REPLACED.
* fix(session): load forked parent attachments into the prompt
ResolveForPrompt used session-scoped lookup, so copied parent attachment
IDs passed Get but never reached the model. Use the same resolveInSession
path as preview.
* fix(chat): keep the user-message fork button visible
The control was hover-only, which hid it on touch. Always show it, and
drop the unused degrade tooltip.
---------
Co-authored-by: hailongzhao <hailongzhao@tencent.com>
Co-authored-by: wizardchen <wizardchen@tencent.com>
2026-09-17 06:20:18 +00:00
|
|
|
require.Greater(t, copied, 0)
|
2026-08-19 10:54:55 +00:00
|
|
|
return dest
|
|
|
|
|
}
|