WeKnora/internal/application/repository
nullptr-error 8dab7550f5
feat(sandbox): 双模式沙箱分配的基础(门控关闭,线上行为不变) (#4507)
* refactor(sandbox): move workspace layout and path rules into a leaf package

internal/sandbox/workspace owns the remote layout (root, input, output,
GitDir, skills root) and the lexical path rules. The sandbox root package
re-exports them through aliases, so callers keep their imports. No
behaviour change.

* feat(sandbox): add the allocation domain model

Pure types for placing a session: session/user mode, the user-mode
admission whitelist (web account or API external user only, with a fixed
fallback reason otherwise), the shared-machine identity and its digest,
the empty-retention bounds and the deployment gate.

* feat(sandbox): add machine and session admission leases

Registry of in-flight operations per shared machine and per session, with
Redis and in-memory implementations. Leases renew only while still live,
report loss at a local deadline measured from the request send time, and
Bind cancels a context when any held lease or barrier is lost. Holding or
renewing only ever extends the scope key's lifetime.

* feat(sandbox): add allocation_mode and empty retention to sandbox configs

Configs gain allocation_mode (session|user, default session) and
user_sandbox_empty_retention_days (0 = default 7, up to 90). Updates that
omit them keep the stored values. Switching a config to user requires the
deployment gate (WEKNORA_SANDBOX_USER_ALLOCATION plus Redis), exposed as
the settings.sandbox.user_allocation capability.

The gate stays closed in this build regardless of the env var: the session
manager does not place sessions by their assignment yet, so a user-mode
placement would be recorded for a session that still runs on its own
machine.

* feat(session): record the server-verified owner auth source

sessions.owner_auth_source records how user_id was authenticated when the
session was created or its owner first bound: web, API direct header or
signed token, API key, MCP endpoint, embed, IM, internal. The auth
middleware puts the source on the context, CreateSession stamps it and
ignores client input, owner binding (MCP ask, embed backfill) records the
entry's own source, and a fork inherits it. Rows from before the column
stay empty, which means unknown.

Per-user sandbox allocation reads it to tell a verified person from a
shared entry; the owner's kind follows from the source and user_id, so it
is not stored separately.

* feat(sandbox): persist session placements and shared-machine registry

session_sandbox_assignments records each session's placement once: its
config pair, the shared machine digest ('' for a machine of its own),
when it was released and when its directory cleanup is due. Mode and
layout follow from the digest. sandbox_user_machines holds the identity
behind each digest and the empty-retention clock.

ClaimPlacement writes the assignment and projects the session pin in one
transaction that locks the session row, then the machine row, before
inserting. RetireSessions releases assignments under the same locks and
writes a tombstone for a session that was never placed, so no placement
lands after a deletion began. The repository is also exercised on the
schema the shipped SQLite migrations create.

* feat(sandbox): place sessions through the allocation service

sandboxalloc decides a session's placement on first remote use and records
it with the pin: sessions that already used a per-session sandbox stay on
it, maintenance sessions are always dedicated, and only an eligible owner
on a user-mode config with the gate open shares a machine. A placed
session resolves straight from its assignment; a released one is refused.
Skill maintenance sessions record a maintenance placement and are removed
if that fails.

* fix(sandbox): retry placement when the sandbox config cannot be read

A failed config load was stored as session mode, so the session could never join a shared machine after the error cleared.

* fix(sandbox): satisfy golangci-lint on the allocation foundations

Wrap lines past 120 characters, comment exported names, and clear the two staticcheck findings so the pull request lint job can pass.

---------

Co-authored-by: hailongzhao <hailongzhao@tencent.com>
2026-10-20 12:28:30 +08:00
..
retriever feat(graph): add standalone JSON graph search API (#4395) 2026-10-17 23:00:55 +08:00
agent_grant_repository.go feat(agent): unified agent permission model with grants and run modes (#4490) 2026-10-19 20:52:15 +08:00
agent_grant_repository_test.go feat(agent): unified agent permission model with grants and run modes (#4490) 2026-10-19 20:52:15 +08:00
agent_prompt_repository.go feat(assistant): add durable multi-agent collaboration and live task views (#4438) 2026-10-19 12:14:15 +08:00
agent_prompt_repository_test.go feat(agent): persist human-in-the-loop prompts with a shared broker (#4250) 2026-10-14 20:37:28 +08:00
agent_share.go fix(security): close cross-workspace access paths in shared spaces (#3408) 2026-09-18 22:00:02 +08:00
agent_share_source_test.go fix(security): close cross-workspace access paths in shared spaces (#3408) 2026-09-18 22:00:02 +08:00
attachment_descriptions.go feat(agent): read chat attachments on demand (#4203) 2026-10-13 14:37:17 +08:00
attachment_descriptions_test.go feat(agent): read chat attachments on demand (#4203) 2026-10-13 14:37:17 +08:00
audit_log.go feat(knowledge): add scoped activity audit trail 2026-07-23 10:50:32 +08:00
audit_log_scope_test.go feat(knowledge): add scoped activity audit trail 2026-07-23 10:50:32 +08:00
chunk.go fix(repository): 关键词 LIKE/ILIKE 检索补显式 ESCAPE,修复 Lite 上静默漏结果 2026-09-29 01:31:37 +08:00
chunk_empty_image_migration_test.go fix: reject invalid image inputs before multimodal extraction (#4489) 2026-10-19 19:20:47 +08:00
chunk_faq_diff_test.go feat(knowledge): enhance FAQ export functionality 2026-07-23 10:50:32 +08:00
chunk_fields_test.go refactor(resource-access): unify scoped authorization and transfer recovery (#3097) 2026-09-08 15:36:33 +08:00
chunk_image_assets.go feat(gallery): filter images by source document (#4159) 2026-10-12 15:43:28 +08:00
chunk_image_assets_test.go feat(gallery): filter images by source document (#4159) 2026-10-12 15:43:28 +08:00
chunk_revision_test.go fix(citations): 修复原文定位、高亮范围与 DocReader 启动失败 (#3794) 2026-09-27 20:32:26 +08:00
chunk_sqlite_test.go perf(chunk): speed up chunk ingestion and batch updates (#3369) 2026-09-17 21:38:15 +08:00
custom_agent.go fix(models): show usage details when deletion is blocked (#2975) 2026-09-02 17:20:37 +08:00
datasource_repo.go feat(assistant): expand management operations and polish interaction UI (#4427) 2026-10-17 14:35:58 +08:00
datasource_repo_test.go fix(datasource): restore sync_deletions on the in-memory object after create 2026-08-21 16:37:05 +08:00
embed_channel.go feat(embed): add backend embed channels with auth and rate limiting (#1657) 2026-06-12 23:10:39 +08:00
graph_search.go feat(graph): add standalone JSON graph search API (#4395) 2026-10-17 23:00:55 +08:00
graph_search_test.go feat(graph): add standalone JSON graph search API (#4395) 2026-10-17 23:00:55 +08:00
kbshare.go fix(security): close cross-workspace access paths in shared spaces (#3408) 2026-09-18 22:00:02 +08:00
knowledge.go fix(repository): 关键词 LIKE/ILIKE 检索补显式 ESCAPE,修复 Lite 上静默漏结果 2026-09-29 01:31:37 +08:00
knowledge_create_test.go fix(knowledge): default custom metadata on create 2026-07-28 22:22:59 +08:00
knowledge_datasource_external_id_test.go fix(datasource): perform real sync deletions scoped per data source (#2690) 2026-08-13 19:52:44 +08:00
knowledge_duplicate_test.go fix(knowledge): recover stranded deleting rows and align the KB count (#3367) 2026-09-18 00:55:44 +08:00
knowledge_finalize_test.go fix(knowledge): stop parses from getting stuck in processing or finalizing (#3696) 2026-09-25 13:26:38 +08:00
knowledge_folder_move_test.go refactor(knowledge): improve folder path handling and add tests for underscore scenarios 2026-08-04 20:45:29 +08:00
knowledge_folder_test.go refactor(knowledge): improve folder path handling and add tests for underscore scenarios 2026-08-04 20:45:29 +08:00
knowledge_list_filter_test.go refactor(resource-access): unify scoped authorization and transfer recovery (#3097) 2026-09-08 15:36:33 +08:00
knowledge_list_sort_test.go feat: add configurable sorting to document and resource lists (#3318) 2026-09-23 12:00:21 +08:00
knowledge_metadata_prefix_test.go feat(memory): add cross-session long-term memory 2026-08-13 18:00:02 +08:00
knowledge_source_schema_test.go fix(schema): expand knowledge source length 2026-06-05 15:12:25 +08:00
knowledge_span_repo.go fix(knowledge): close spans left open on terminal rows and superseded attempts (#3855) 2026-10-08 01:25:38 +08:00
knowledge_span_repo_test.go feat(knowledge): flag documents that stop making progress (#3557) 2026-09-22 21:34:08 +08:00
knowledge_tag.go fix(knowledge): address auto-tag review findings 2026-08-07 15:01:01 +08:00
knowledge_tag_test.go feat(knowledge): derive knowledge base descriptions from document profiles (#3370) 2026-09-17 22:21:55 +08:00
knowledge_transfer.go refactor(resource-access): unify scoped authorization and transfer recovery (#3097) 2026-09-08 15:36:33 +08:00
knowledge_transfer_test.go refactor(resource-access): unify scoped authorization and transfer recovery (#3097) 2026-09-08 15:36:33 +08:00
knowledgebase.go feat(knowledge): derive knowledge base descriptions from document profiles (#3370) 2026-09-17 22:21:55 +08:00
knowledgebase_sqlite_test.go feat(knowledge): derive knowledge base descriptions from document profiles (#3370) 2026-09-17 22:21:55 +08:00
like_escape_sqlite_test.go fix(repository): 关键词 LIKE/ILIKE 检索补显式 ESCAPE,修复 Lite 上静默漏结果 2026-09-29 01:31:37 +08:00
mcp_endpoint.go feat(mcp): add built-in MCP server with per-workspace endpoints (#3371) 2026-09-17 22:40:05 +08:00
mcp_metadata.go feat(mcp)!: persist tool catalogs and add guided configuration (#3118) 2026-09-09 13:34:56 +08:00
mcp_metadata_test.go feat(mcp)!: persist tool catalogs and add guided configuration (#3118) 2026-09-09 13:34:56 +08:00
mcp_oauth.go fix(mcp): keep OAuth token expiry independent of the process time zone (#4207) 2026-10-13 16:56:51 +08:00
mcp_oauth_test.go fix(mcp): keep OAuth token expiry independent of the process time zone (#4207) 2026-10-13 16:56:51 +08:00
mcp_service.go feat(mcp)!: persist tool catalogs and add guided configuration (#3118) 2026-09-09 13:34:56 +08:00
mcp_service_create_test.go fix(mcp): preserve disabled state on service creation 2026-10-10 20:50:05 +08:00
mcp_tool_approval_repository.go feat(agent): unified agent permission model with grants and run modes (#4490) 2026-10-19 20:52:15 +08:00
mcp_tool_approval_repository_test.go feat(agent): unified agent permission model with grants and run modes (#4490) 2026-10-19 20:52:15 +08:00
memory.go fix(memory): rank memories by the query, not by importance 2026-09-13 11:43:17 +08:00
memory_extraction.go fix(memory): preserve extraction progress and atomic memory updates (#3224) 2026-09-13 00:04:16 +08:00
memory_lifecycle.go fix(memory): preserve extraction progress and atomic memory updates (#3224) 2026-09-13 00:04:16 +08:00
memory_vector.go fix(memory): rank memories by the query, not by importance 2026-09-13 11:43:17 +08:00
message.go feat(assistant): manage agents and skills, separate history, refresh pages (#4344) 2026-10-15 21:43:20 +08:00
message_artifact.go feat(assistant): manage agents and skills, separate history, refresh pages (#4344) 2026-10-15 21:43:20 +08:00
message_artifact_delete_test.go feat(artifacts): let users delete generated files (#3447) 2026-09-20 13:01:46 +08:00
message_artifact_test.go feat(artifacts): artifacts library page backed by a message_artifacts table (#3384) 2026-09-18 12:10:19 +08:00
message_context_checkpoint_test.go feat(agent): size agent history by the window and calibrate token estimates (#3413) 2026-09-18 22:51:31 +08:00
message_fork_boundary_test.go feat(artifacts): artifacts library page backed by a message_artifacts table (#3384) 2026-09-18 12:10:19 +08:00
message_owner_scope_test.go feat(artifacts): artifacts library page backed by a message_artifacts table (#3384) 2026-09-18 12:10:19 +08:00
message_request_id_test.go feat(session): fork conversations from a historical user message (#3304) 2026-09-17 14:20:18 +08:00
message_rewind_boundary_test.go feat(session): in-place rewind with workspace checkpoint reset (#3469) 2026-09-20 21:01:00 +08:00
message_search_test.go feat(artifacts): artifacts library page backed by a message_artifacts table (#3384) 2026-09-18 12:10:19 +08:00
message_suggestion.go feat(session): in-place rewind with workspace checkpoint reset (#3469) 2026-09-20 21:01:00 +08:00
model.go fix(repository): correct query syntax to get correctly built-in models 2026-05-21 16:11:22 +08:00
model_catalog_config.go feat(models): add system admin model catalog console (#3662) 2026-09-24 16:31:45 +08:00
model_usage.go fix(models): protect auto-tag model references 2026-09-14 19:29:19 +08:00
model_usage_test.go fix(models): protect auto-tag model references 2026-09-14 19:29:19 +08:00
organization.go fix(security): close the low-severity shared-space findings (#3416) 2026-09-18 22:58:46 +08:00
organization_member_limit_test.go fix(security): close the low-severity shared-space findings (#3416) 2026-09-18 22:58:46 +08:00
resource.go feat(resource): 相同图片字节复用一个 handle,不再重复写字节与重复注册 (#4419) 2026-10-17 23:16:40 +08:00
resource_content_hash_test.go feat(resource): 相同图片字节复用一个 handle,不再重复写字节与重复注册 (#4419) 2026-10-17 23:16:40 +08:00
resource_references.go refactor(resource-access): unify scoped authorization and transfer recovery (#3097) 2026-09-08 15:36:33 +08:00
sandbox_allocation.go feat(sandbox): 双模式沙箱分配的基础(门控关闭,线上行为不变) (#4507) 2026-10-20 12:28:30 +08:00
sandbox_allocation_test.go feat(sandbox): 双模式沙箱分配的基础(门控关闭,线上行为不变) (#4507) 2026-10-20 12:28:30 +08:00
session.go feat(sandbox): 双模式沙箱分配的基础(门控关闭,线上行为不变) (#4507) 2026-10-20 12:28:30 +08:00
session_fork_test.go feat(artifacts): artifacts library page backed by a message_artifacts table (#3384) 2026-09-18 12:10:19 +08:00
session_kind_test.go feat(assistant): manage agents and skills, separate history, refresh pages (#4344) 2026-10-15 21:43:20 +08:00
session_test.go feat(sandbox): expose tenant skill management over HTTP and in the console (#2789) 2026-08-25 11:28:12 +08:00
storagebackend.go feat(storage): add multi-instance storage backends per workspace 2026-07-15 14:54:39 +08:00
system_setting.go feat(system): consolidate system admin and settings into one Settings panel 2026-05-26 21:13:56 +08:00
tag.go fix(repository): 关键词 LIKE/ILIKE 检索补显式 ESCAPE,修复 Lite 上静默漏结果 2026-09-29 01:31:37 +08:00
task_queue.go fix(wiki): bound outstanding follow-up tasks 2026-09-28 22:02:07 +08:00
task_queue_test.go fix(wiki): bound outstanding follow-up tasks 2026-09-28 22:02:07 +08:00
temporary_document.go feat(agent): read chat attachments on demand (#4203) 2026-10-13 14:37:17 +08:00
temporary_document_test.go feat(agent): read chat attachments on demand (#4203) 2026-10-13 14:37:17 +08:00
tenant.go feat(assistant): expand management operations and polish interaction UI (#4427) 2026-10-17 14:35:58 +08:00
tenant_api_key.go feat: support updating API key configuration 2026-08-12 11:43:03 +08:00
tenant_api_key_test.go feat: support updating API key configuration 2026-08-12 11:43:03 +08:00
tenant_disabled_shared_agent.go feat(agent): enhance agent and skill management features 2026-02-09 11:40:25 +08:00
tenant_invitation.go feat(rbac): add multi-use share-link invitations for invite_only mode (#1504) 2026-05-27 19:42:01 +08:00
tenant_member.go fix(repository): 关键词 LIKE/ILIKE 检索补显式 ESCAPE,修复 Lite 上静默漏结果 2026-09-29 01:31:37 +08:00
tenant_sandbox_config.go feat(sandbox): expose tenant skill management over HTTP and in the console (#2789) 2026-08-25 11:28:12 +08:00
tenant_sandbox_config_test.go feat(sandbox) (#2301) 2026-08-10 21:28:20 +08:00
tenant_skill.go fix(skills): upgrade outdated sandbox skills without rolling back the catalog or taking them offline (#3406) 2026-09-18 20:27:43 +08:00
tenant_skill_test.go feat(skills): store skills in a tenant catalog and install per sandbox 2026-08-28 15:17:37 +08:00
tenant_test.go feat: add scoped tenant api keys 2026-07-07 12:00:13 +08:00
user.go feat(system): add platform user management and streamline settings (#4153) 2026-10-11 17:07:00 +08:00
user_resource_favorite.go feat(favorites): implement user favorites and recents functionality 2026-05-18 17:28:58 +08:00
user_status_test.go feat(system): add platform user management and streamline settings (#4153) 2026-10-11 17:07:00 +08:00
user_tenantless_test.go feat(auth): support tenantless provisioning and gated self-service workspace creation 2026-07-13 18:13:51 +08:00
vectorstore.go feat: add VectorStore service layer with types and connection testing 2026-04-13 22:57:17 +08:00
web_search_provider.go feat(assistant): expand management operations and polish interaction UI (#4427) 2026-10-17 14:35:58 +08:00
wiki_page.go fix(repository): 关键词 LIKE/ILIKE 检索补显式 ESCAPE,修复 Lite 上静默漏结果 2026-09-29 01:31:37 +08:00
wiki_page_test.go feat(wiki): 增加跨知识库 Wiki 搜索 POST /wiki-search (#3535) 2026-09-25 22:22:58 +08:00