WeKnora/internal/sandbox
nullptr-error d4b9fd0c72
feat(session): in-place rewind with workspace checkpoint reset (#3469)
* refactor(session): extract shared workspace git reset helper

Fork bootstrap and in-place rewind both need the same /workspace reset
script. Move it out of fork_bootstrapper so rewind can reuse it without
copying ExecShellCommand plumbing.

* feat(message): add DeleteMessagesFrom for rewind truncation

Rewind needs a composite created_at+id cursor so same-millisecond
messages after the fork point are not left behind. Delete inside a
transaction and return the rows so callers can log the count.

* feat(session): add in-place rewind service

Truncate the current session at a user or assistant message and git-reset
the live sandbox when a reachable checkpoint exists. Reset failure is
fail-closed so messages are never deleted ahead of the workspace.

* feat(session): expose POST /sessions/:id/rewind

Wire SessionRewindService through the session handler and container so
the client can rewind in place. Busy sources map to 409; git reset
failures stay 500.

* feat(chat): add rewind API client and i18n copy

Expose rewindSession with the same 180s timeout as fork, and add
chat.rewind strings in all five locales so the confirm dialog is not
hardcoded Chinese.

* feat(chat): add rewind button with confirm dialog

Offer in-place rewind next to fork on user and assistant messages.
Confirm before truncating the thread, then reset locally and prefill
the original question when the cut point is a user message.

* fix(chat): confirm rewind with a compact popover

Replace the full-page confirm dialog with a small popconfirm above the
rewind button, and shorten the swagger description to satisfy line length.

* fix(chat): skip markdown images with an empty destination

Empty ![]() was rendered as <img src="">, which shows as a broken image in the reply.

* fix(chat): clip sandbox panel slide-in and rename open tooltip

Keep the enter animation inside the viewport so it cannot flash a document
scrollbar and jump the page. Rename the header toggle from sandbox terminal
to expand sidebar.

* fix(session): 回滚时完成截断、互斥发送并重拉历史

客户端中断不再让 git reset 成功后留下未删的消息;reset/删消息前复查 busy,并锁住当前会话输入。成功后重拉历史,避免切会话预填串台和 steer 分段截错。

* fix(session): 工作区 git 外置,并让未开箱 fork 的回滚对齐 SHA

checkpoint、回滚和 fork 共用 --git-dir=/var/lib/weknora/workspace.git,避免 rm -rf /workspace 丢掉历史。
未开箱分叉会话回滚时改写或清除 ForkBootstrap,避免第一次开箱仍 reset 到旧切点。

* fix(session): 回滚加会话锁,并堵住发送中回滚与脏 SHA

同一会话并发回滚互斥(进程内 + Redis),冲突返回 409。发送/流式中禁用回滚按钮;历史重拉成功后再改界面。未开箱 fork 的 checkpoint SHA 必须是 40 位 hex。工作区 git 只认外置 GIT_DIR,不再 mv/rm 根上的 .git。

* fix(session): 未开箱 fork 回滚成功时不要提示没有沙箱

ForkBootstrap 已对齐切点后返回 workspace_reset,前端走「已回滚」;清掉引导时改报 NO_CHECKPOINT。纯聊天仍用 NO_SANDBOX。

* fix(chat): stub composerLocked in steer interaction tests

handleSteerMsg now bails when rewind locks the composer. The VM harness
did not provide that ref, so CI threw ReferenceError on every steer case.

* fix(session): allow git-layout mkdir in pinned checkpoint test

SkipWorkspacePrep still omits the input/output bootstrap exec. The
checkpoint script now mkdirs WORK_TREE and GIT_DIR, so the old
"command must not contain mkdir" assertion was stale.

* fix(session): block send while rewind holds the session lock

BeginTurn now fails if the rewind key is held, so AgentQA cannot start
during git reset. Knowledge-chat and executeQA check the same lock
before persisting messages. composerLocked is still page-local.

* fix(session): close send/rewind races and fail closed without a checkpoint

Hold the turn lease before persist so rewind cannot truncate an in-flight
send. TryLockRewind fails while a turn is live; emptying the conversation
resets the workspace through the same git path as a SHA rewind.

* fix(session): wrap rewind reset call to satisfy line length lint

* fix(session): fail closed on a replaced sandbox and close leftover rewind holes

Do not truncate history when the live workspace cannot follow the checkpoint, retry deletes after a successful git reset, and keep send and rewind exclusive even without a sandbox manager.

* fix(session): address rewind review findings

Correctness:

- Adopt a pre-move /workspace/.git into SessionGitDir on first use. Sandboxes
  provisioned before the git dir moved out of the work tree still hold their
  checkpoints there, so every SHA recorded on those turns stopped resolving:
  rewind 500'd instead of truncating and fork's rollback failed on a bad
  object. Adoption is guarded on the new dir being absent and on the work-tree
  repo carrying the checkpointer's committer identity, so an agent's own
  `git init` in /workspace is left alone.
- Only fail a send closed when BeginSessionTurn reports a rewind lock. Every
  other lease error degrades to running without a lease, as before rewind
  existed; a Redis blip on the lease script was rejecting the user's message.
- Release an abandoned fork snapshot after the truncate lands, not before.
  Clearing the bootstrap column is a DB write a retry can redo; deleting the
  snapshot is not, and a delete that exhausted its retries left the fork with
  no workspace to boot from under a full transcript.
- Re-acquire the rewind lock when a renew call errors, not just when it
  reports the lease lost. Sitting the tick out let a short Redis outage expire
  the 2m key mid-reset and hand the session to a second rewind.
- Keep the history cursor when a post-rewind reload fails. Clearing it sent
  the next scroll-up back to the newest page, which the kept prefix already
  holds, instead of to older messages.

Efficiency:

- Add ListAssistantCheckpointsUpTo and use it to answer "which checkpoint does
  kept history still reach". Rewind was reading every message body and artifact
  row in the session to find one SHA.
- Take the send-side turn lease once per request. The handler already holds it
  before persisting; QARequest.TurnLeaseHeld lets the QA services skip their
  own, so IM/MCP still take one and HTTP send stops doubling every rewind check
  and lease round trip.
- Batch the suggestion delete behind DeleteByMessageIDs instead of one query
  per deleted message while the rewind lock is held.
- Resolve the rewind affordance for the whole transcript in one pass rather
  than two list scans per rendered row on every streamed token.

Cleanup:

- Drop the SANDBOX_REPLACED skip reason, which the service never produces (it
  fail-closes with a 409), along with its copy in all five locales.
- Drop GetMessagesBySession from rewindMessageStore; rewind never calls it.
- Drop the unused chat.rewind.confirmTitle copy from all five locales.
- Restore the chatHeader.toggleSandboxPanel wording this branch had changed
  unrelated to rewind.

---------

Co-authored-by: hailongzhao <hailongzhao@tencent.com>
Co-authored-by: wizardchen <wizardchen@tencent.com>
2026-09-20 21:01:00 +08:00
..
desktopscripts feat(sandbox): add a graphical desktop to session sandboxes (#3245) 2026-09-14 20:37:37 +08:00
capabilities.go fix(sandbox): separate file access from artifact publishing (#3356) 2026-09-17 16:18:01 +08:00
check_client_guard_test.go feat(sandbox): 沙箱后端改为按空间配置,并补齐 E2B 模板与检测诊断 2026-08-11 15:42:02 +08:00
command_output.go feat(sandbox): stream live shell and install command output 2026-09-12 10:16:39 +08:00
config_identity.go feat(sandbox): Docker 后端支持会话级长驻容器与远程守护进程 2026-08-24 12:22:58 +08:00
config_identity_test.go feat(sandbox): remove the Local host-process backend 2026-08-26 17:48:21 +08:00
config_required.go feat(sandbox): remove the Local host-process backend 2026-08-26 17:48:21 +08:00
config_sandboxes.go feat(sandbox) (#2301) 2026-08-10 21:28:20 +08:00
config_sandboxes_test.go feat(sandbox) (#2301) 2026-08-10 21:28:20 +08:00
cube_dns.go feat(sandbox): pin Cube DNS on templates and freeze skill snapshot configs 2026-08-26 16:56:26 +08:00
cube_dns_test.go feat(sandbox): pin Cube DNS on templates and freeze skill snapshot configs 2026-08-26 16:56:26 +08:00
cube_egress_integration_test.go feat(sandbox): pin Cube DNS on templates and freeze skill snapshot configs 2026-08-26 16:56:26 +08:00
cube_integration_test.go feat(sandbox): add tenant-configurable network policy (#2995) 2026-09-03 10:49:46 +08:00
cube_mock_test.go perf(sandbox): reduce redundant remote calls 2026-09-17 17:47:24 +08:00
cube_remote_client.go perf(sandbox): reduce redundant remote calls 2026-09-17 17:47:24 +08:00
cube_remote_client_test.go feat(session): fork conversations from a historical user message (#3304) 2026-09-17 14:20:18 +08:00
cube_template_catalog_test.go feat(sandbox): add a graphical desktop to session sandboxes (#3245) 2026-09-14 20:37:37 +08:00
cube_terminal.go feat(sandbox): add an interactive terminal and files tab beside chat (#3110) 2026-09-08 17:43:15 +08:00
cube_terminal_test.go feat(sandbox): add a graphical desktop to session sandboxes (#3245) 2026-09-14 20:37:37 +08:00
desktop.go feat(sandbox): add a graphical desktop to session sandboxes (#3245) 2026-09-14 20:37:37 +08:00
desktop_scripts.go feat(sandbox): add a graphical desktop to session sandboxes (#3245) 2026-09-14 20:37:37 +08:00
desktop_test.go feat(sandbox): add a graphical desktop to session sandboxes (#3245) 2026-09-14 20:37:37 +08:00
docker_enabled.go feat: require opt-in for the Docker sandbox backend (#2936) 2026-09-01 15:42:28 +08:00
docker_enabled_test.go feat: require opt-in for the Docker sandbox backend (#2936) 2026-09-01 15:42:28 +08:00
docker_engine.go fix(sandbox): treat in-use snapshot deletes as retryable conflicts 2026-08-31 19:42:32 +08:00
docker_host.go feat(sandbox): Docker 后端支持会话级长驻容器与远程守护进程 2026-08-24 12:22:58 +08:00
docker_host_test.go feat(sandbox): Docker 后端支持会话级长驻容器与远程守护进程 2026-08-24 12:22:58 +08:00
docker_idle_sweeper.go feat(sandbox): run sandboxed execs as root by default (#3067) 2026-09-07 13:03:35 +08:00
docker_idle_sweeper_test.go feat(sandbox): run sandboxed execs as root by default (#3067) 2026-09-07 13:03:35 +08:00
docker_integration_test.go fix(sandbox): use E2B BuildID as template version 2026-09-12 10:31:14 +08:00
docker_remote_client.go perf(sandbox): reduce redundant remote calls 2026-09-17 17:47:24 +08:00
docker_remote_client_test.go feat(sandbox): stream live shell and install command output 2026-09-12 10:16:39 +08:00
docker_rpc_timeout.go fix(sandbox): rebuild templates without dropping the live ID 2026-08-26 16:56:26 +08:00
docker_snapshot.go feat(session): fork conversations from a historical user message (#3304) 2026-09-17 14:20:18 +08:00
docker_snapshot_test.go feat(session): fork conversations from a historical user message (#3304) 2026-09-17 14:20:18 +08:00
docker_template_catalog.go feat(session): fork conversations from a historical user message (#3304) 2026-09-17 14:20:18 +08:00
e2b_compatible_integration_test.go feat(sandbox): remove the Local host-process backend 2026-08-26 17:48:21 +08:00
e2b_exec_timeout_test.go feat(sandbox): add a graphical desktop to session sandboxes (#3245) 2026-09-14 20:37:37 +08:00
e2b_integration_test.go feat(session): fork conversations from a historical user message (#3304) 2026-09-17 14:20:18 +08:00
e2b_remote_client.go perf(sandbox): reduce redundant remote calls 2026-09-17 17:47:24 +08:00
e2b_remote_client_test.go feat(sandbox): add a graphical desktop to session sandboxes (#3245) 2026-09-14 20:37:37 +08:00
e2b_rpc_timeout.go feat(agent): unify sandbox tools and drop host preloaded skills (#3033) 2026-09-05 16:45:59 +08:00
e2b_terminal.go feat(sandbox): add an interactive terminal and files tab beside chat (#3110) 2026-09-08 17:43:15 +08:00
envd_compat_transport.go feat(agent): unify sandbox tools and drop host preloaded skills (#3033) 2026-09-05 16:45:59 +08:00
envd_compat_transport_test.go feat(sandbox): run sandboxed execs as root by default (#3067) 2026-09-07 13:03:35 +08:00
filesystem_identity.go feat(session): fork conversations from a historical user message (#3304) 2026-09-17 14:20:18 +08:00
filesystem_identity_test.go feat(session): fork conversations from a historical user message (#3304) 2026-09-17 14:20:18 +08:00
gateway_transport.go refactor: remove unused private Go helpers 2026-09-17 15:51:51 +08:00
gateway_transport_test.go feat(sandbox): add tenant-configurable network policy (#2995) 2026-09-03 10:49:46 +08:00
inbound_token_registry.go fix(sandbox): always require inbound credentials 2026-09-03 13:34:40 +08:00
inbound_token_registry_test.go feat(sandbox): add tenant-configurable network policy (#2995) 2026-09-03 10:49:46 +08:00
langfuse.go perf(sandbox): reduce redundant remote calls 2026-09-17 17:47:24 +08:00
langfuse_test.go feat(session): fork conversations from a historical user message (#3304) 2026-09-17 14:20:18 +08:00
manager.go feat(sandbox): remove the Local host-process backend 2026-08-26 17:48:21 +08:00
mkdir.go feat(agent): unify sandbox tools and drop host preloaded skills (#3033) 2026-09-05 16:45:59 +08:00
mkdir_test.go feat(agent): unify sandbox tools and drop host preloaded skills (#3033) 2026-09-05 16:45:59 +08:00
orphan_reaper.go feat(sandbox) (#2301) 2026-08-10 21:28:20 +08:00
orphan_reaper_test.go feat(sandbox) (#2301) 2026-08-10 21:28:20 +08:00
pty_input_coalesce.go feat(sandbox): add an interactive terminal and files tab beside chat (#3110) 2026-09-08 17:43:15 +08:00
pty_input_coalesce_test.go feat(sandbox): add an interactive terminal and files tab beside chat (#3110) 2026-09-08 17:43:15 +08:00
remote_client.go perf(sandbox): reduce redundant remote calls 2026-09-17 17:47:24 +08:00
remote_client_test.go feat(sandbox): add tenant-configurable network policy (#2995) 2026-09-03 10:49:46 +08:00
remote_errors.go feat(session): fork conversations from a historical user message (#3304) 2026-09-17 14:20:18 +08:00
remote_errors_test.go feat(session): fork conversations from a historical user message (#3304) 2026-09-17 14:20:18 +08:00
remote_fake_test.go feat(session): fork conversations from a historical user message (#3304) 2026-09-17 14:20:18 +08:00
remote_sandbox.go feat(agent): write workspace scripts and run them with installed skills 2026-08-29 22:45:18 +08:00
remote_sandbox_test.go feat(agent): write workspace scripts and run them with installed skills 2026-08-29 22:45:18 +08:00
remote_snapshot_test.go fix(sandbox): keep skill image pointer out of sandbox config PUT 2026-08-24 16:00:23 +08:00
runtime_defaults.go feat(sandbox): Docker 后端支持会话级长驻容器与远程守护进程 2026-08-24 12:22:58 +08:00
sandbox.go feat(session): in-place rewind with workspace checkpoint reset (#3469) 2026-09-20 21:01:00 +08:00
sandbox_test.go feat(sandbox): remove the Local host-process backend 2026-08-26 17:48:21 +08:00
session_binding.go feat(session): in-place rewind with workspace checkpoint reset (#3469) 2026-09-20 21:01:00 +08:00
session_binding_redis.go feat(session): in-place rewind with workspace checkpoint reset (#3469) 2026-09-20 21:01:00 +08:00
session_binding_redis_test.go feat(session): in-place rewind with workspace checkpoint reset (#3469) 2026-09-20 21:01:00 +08:00
session_binding_tenant_test.go feat(sandbox) (#2301) 2026-08-10 21:28:20 +08:00
session_binding_test.go feat(session): in-place rewind with workspace checkpoint reset (#3469) 2026-09-20 21:01:00 +08:00
session_bootstrapper.go feat(session): fork conversations from a historical user message (#3304) 2026-09-17 14:20:18 +08:00
session_bootstrapper_test.go feat(session): fork conversations from a historical user message (#3304) 2026-09-17 14:20:18 +08:00
session_connect.go perf(sandbox): reduce redundant remote calls 2026-09-17 17:47:24 +08:00
session_connect_test.go perf(sandbox): reduce redundant remote calls 2026-09-17 17:47:24 +08:00
session_file_operation.go perf(sandbox): reduce redundant remote calls 2026-09-17 17:47:24 +08:00
session_file_operation_test.go perf(sandbox): reduce redundant remote calls 2026-09-17 17:47:24 +08:00
session_lifecycle.go perf(sandbox): reduce redundant remote calls 2026-09-17 17:47:24 +08:00
session_lifecycle_test.go feat(session): fork conversations from a historical user message (#3304) 2026-09-17 14:20:18 +08:00
session_manager.go feat(session): in-place rewind with workspace checkpoint reset (#3469) 2026-09-20 21:01:00 +08:00
session_manager_desktop_test.go feat(sandbox): add a graphical desktop to session sandboxes (#3245) 2026-09-14 20:37:37 +08:00
session_manager_terminal_test.go feat(sandbox): unify the interactive PTY prompt and reconnect running sandboxes (#3128) 2026-09-09 18:17:10 +08:00
session_manager_test.go feat(session): in-place rewind with workspace checkpoint reset (#3469) 2026-09-20 21:01:00 +08:00
session_shell_snapshot_test.go perf(sandbox): reduce redundant remote calls 2026-09-17 17:47:24 +08:00
shell_quote.go feat(sandbox): add tenant skill install and remove service layer 2026-08-24 17:51:13 +08:00
shell_quote_test.go feat(sandbox): add tenant skill install and remove service layer 2026-08-24 17:51:13 +08:00
skill_image.go feat(sandbox): remove the Local host-process backend 2026-08-26 17:48:21 +08:00
skill_paths.go fix(sandbox): separate file access from artifact publishing (#3356) 2026-09-17 16:18:01 +08:00
skill_paths_test.go feat(sandbox): run sandboxed execs as root by default (#3067) 2026-09-07 13:03:35 +08:00
template_catalog.go feat(sandbox): add a graphical desktop to session sandboxes (#3245) 2026-09-14 20:37:37 +08:00
template_catalog_test.go feat(sandbox): add a graphical desktop to session sandboxes (#3245) 2026-09-14 20:37:37 +08:00
tenant_config.go feat(sandbox): add a graphical desktop to session sandboxes (#3245) 2026-09-14 20:37:37 +08:00
tenant_config_test.go feat(sandbox): add a graphical desktop to session sandboxes (#3245) 2026-09-14 20:37:37 +08:00
tenant_resolver.go feat(session): fork conversations from a historical user message (#3304) 2026-09-17 14:20:18 +08:00
tenant_resolver_test.go feat: require opt-in for the Docker sandbox backend (#2936) 2026-09-01 15:42:28 +08:00
terminal.go feat(sandbox): unify the interactive PTY prompt and reconnect running sandboxes (#3128) 2026-09-09 18:17:10 +08:00
terminal_test.go feat(sandbox): add an interactive terminal and files tab beside chat (#3110) 2026-09-08 17:43:15 +08:00
terminal_ttl_test.go feat(sandbox): add an interactive terminal and files tab beside chat (#3110) 2026-09-08 17:43:15 +08:00
url_guard.go fix: share IP classification between SSRF and sandbox URL guards 2026-09-01 15:35:14 +08:00
url_guard_test.go fix: share IP classification between SSRF and sandbox URL guards 2026-09-01 15:35:14 +08:00
validator.go perf(sandbox): compile command-substitution regexps once 2026-06-16 19:51:32 +08:00
validator_test.go feat(sandbox) (#2301) 2026-08-10 21:28:20 +08:00
websocket_dialer.go feat(sandbox): add a graphical desktop to session sandboxes (#3245) 2026-09-14 20:37:37 +08:00
websocket_dialer_test.go feat(sandbox): add a graphical desktop to session sandboxes (#3245) 2026-09-14 20:37:37 +08:00
workspace_failure_test.go feat(agent): unify sandbox tools and drop host preloaded skills (#3033) 2026-09-05 16:45:59 +08:00
workspace_path.go feat(agent): unify sandbox tools and drop host preloaded skills (#3033) 2026-09-05 16:45:59 +08:00