WeKnora/internal/im
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
..
dingtalk fix(im): cap IM callback bodies before any adapter reads them (#4369) 2026-10-16 17:16:15 +08:00
feishu fix(im): cap IM callback bodies before any adapter reads them (#4369) 2026-10-16 17:16:15 +08:00
mattermost fix(im): cap IM callback bodies before any adapter reads them (#4369) 2026-10-16 17:16:15 +08:00
qqbot fix(im): cap IM callback bodies before any adapter reads them (#4369) 2026-10-16 17:16:15 +08:00
slack fix(im): cap IM callback bodies before any adapter reads them (#4369) 2026-10-16 17:16:15 +08:00
telegram fix(im): cap IM callback bodies before any adapter reads them (#4369) 2026-10-16 17:16:15 +08:00
wechat refactor: remove unused private Go helpers 2026-09-17 15:51:51 +08:00
wecom fix(im): cap IM callback bodies before any adapter reads them (#4369) 2026-10-16 17:16:15 +08:00
yunzhijia fix(im): cap IM callback bodies before any adapter reads them (#4369) 2026-10-16 17:16:15 +08:00
adapter.go fix(im/feishu): show progress card in full output mode (#2909) 2026-09-01 13:09:11 +08:00
callback_validation_test.go fix: align client sessions and integration request handling (#3305) 2026-09-16 16:20:57 +08:00
channel_agent_name_test.go fix(i18n): 修复内置智能体名称与描述不随界面语言切换的问题 (#2828) 2026-08-27 11:53:45 +08:00
channel_kb_scope_test.go fix(security): close the low-severity shared-space findings (#3416) 2026-09-18 22:58:46 +08:00
channel_mapping_test.go feat(im,datasource): support Lark, Feishu's international edition 2026-07-17 11:05:54 +08:00
channel_security.go fix: align client sessions and integration request handling (#3305) 2026-09-16 16:20:57 +08:00
channel_security_test.go fix: align client sessions and integration request handling (#3305) 2026-09-16 16:20:57 +08:00
cmd_clear.go feat(im): add slash-command system with /help, /info, /search, /stop, /clear 2026-03-20 15:49:59 +08:00
cmd_help.go feat(im): add slash-command system with /help, /info, /search, /stop, /clear 2026-03-20 15:49:59 +08:00
cmd_info.go feat(im): add slash-command system with /help, /info, /search, /stop, /clear 2026-03-20 15:49:59 +08:00
cmd_search.go feat(retrieval): unify rerank across search APIs and expose diagnostics (#3675) 2026-09-24 20:41:49 +08:00
cmd_stop.go feat(im): add slash-command system with /help, /info, /search, /stop, /clear 2026-03-20 15:49:59 +08:00
command.go feat(im): add slash-command system with /help, /info, /search, /stop, /clear 2026-03-20 15:49:59 +08:00
command_registry.go feat(im): add slash-command system with /help, /info, /search, /stop, /clear 2026-03-20 15:49:59 +08:00
content_rewrite_test.go fix: align client sessions and integration request handling (#3305) 2026-09-16 16:20:57 +08:00
credentials.go revert: take the plugin system back out of main 2026-09-26 14:58:18 +08:00
file_message_test.go fix(im): tighten DingTalk rich-text follow-up handling 2026-08-24 14:51:04 +08:00
full_output_test.go fix(feishu): preserve active streams during long-running QA 2026-09-14 22:19:53 +08:00
identity_test.go feat(im): add per-channel reply locale (#3455) 2026-09-23 12:01:01 +08:00
im_config_warning_test.go fix(im): render resource:// images in IM channels (nginx /r/ + config guards) 2026-07-28 21:25:12 +08:00
im_file_service_test.go refactor(storage): extract storage reference URL rewriting into internal/storageurl 2026-08-05 14:42:51 +08:00
mode.go refactor(im): move adapter factories into per-platform subpackages 2026-04-29 20:08:22 +08:00
oauth_notice_test.go feat(im): include per-service MCP OAuth URLs in IM auth notices 2026-07-01 17:53:54 +08:00
qa_exit_test.go fix(im): finalize replies after agent QA returns (#3261) 2026-09-15 17:37:40 +08:00
qaqueue.go feat: add unit tests for COS object name parsing and enhance error handling 2026-05-29 13:47:32 +08:00
service.go feat(sandbox): 双模式沙箱分配的基础(门控关闭,线上行为不变) (#4507) 2026-10-20 12:28:30 +08:00
service_agent_test.go fix(integrations): polish agent filter UX and embed session rebind 2026-06-24 20:09:19 +08:00
service_lifecycle_test.go feat(im): add per-channel reply locale (#3455) 2026-09-23 12:01:01 +08:00
service_quote_test.go fix(im): anti-hallucination for non-text quotes and unprocessable media messages 2026-04-03 11:34:22 +08:00
session_not_found_test.go fix(im): recover from deleted session when GetSession returns app sentinel (#1499) 2026-05-27 11:51:11 +08:00
session_test.go fix(im): tighten DingTalk rich-text follow-up handling 2026-08-24 14:51:04 +08:00
session_title_test.go feat(im): IM session improvements — titles, in-flight recovery, classification 2026-06-12 17:01:28 +08:00
stream_delivery_test.go fix(feishu): preserve active streams during long-running QA 2026-09-14 22:19:53 +08:00
stream_display_test.go feat(memory): add cross-session long-term memory 2026-08-13 18:00:02 +08:00
stream_exit_test.go fix(im): preserve errors emitted after agent completion 2026-09-15 17:56:54 +08:00
stream_lifecycle_test.go fix(im): address stream display review feedback 2026-06-24 10:33:55 +08:00
stream_section.go fix(im): address stream display review feedback 2026-06-24 10:33:55 +08:00
stream_test.go feat(memory): add cross-session long-term memory 2026-08-13 18:00:02 +08:00
supervisor.go fix(im): prevent DingTalk stream connection from going stale 2026-06-22 15:04:23 +08:00
think.go feat(im,datasource): support Lark, Feishu's international edition 2026-07-17 11:05:54 +08:00
think_test.go feat(memory): add cross-session long-term memory 2026-08-13 18:00:02 +08:00
tool_display.go feat(agent): persist human-in-the-loop prompts with a shared broker (#4250) 2026-10-14 20:37:28 +08:00
tool_display_test.go feat(agent): stream live +/- progress for sandbox write and edit 2026-09-02 23:36:58 +08:00
types.go feat(im): add per-channel reply locale (#3455) 2026-09-23 12:01:01 +08:00
types_summary_test.go feat(im): add per-channel reply locale (#3455) 2026-09-23 12:01:01 +08:00
types_test.go feat(im): add per-channel reply locale (#3455) 2026-09-23 12:01:01 +08:00
webhook_body.go fix(im): cap IM callback bodies before any adapter reads them (#4369) 2026-10-16 17:16:15 +08:00
webhook_body_test.go fix(im): cap IM callback bodies before any adapter reads them (#4369) 2026-10-16 17:16:15 +08:00