Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Bilingual-pair consistency record (docs/i18n/README.md): the git blob hash of each
# side as of the last confirmed-consistent state. Both languages carry equal authority;
# after editing either side, bring the other along and re-record with:
# pnpm run verify-translation-pairing --write .agents/notes/implemented/bug-fix/2026-11-24-hand-edited-session-logs-and-protected-host-stores.md
2026-11-24-hand-edited-session-logs-and-protected-host-stores.md: 5e3e8dcfe83ea6882244bd2390cfcdb37ebd945a
2026-11-24-hand-edited-session-logs-and-protected-host-stores.zh.md: 84564f89764df7c7afa06f8188cd77885099bfa6
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Agent Note: Hand-edited session logs no longer replay their prompts, and the Host's stores are protected

Status: implemented

English | [中文](2026-11-24-hand-edited-session-logs-and-protected-host-stores.zh.md)

## Problem

An agent on a new desktop account wrote 22 session logs straight into `~/.aeven/sessions` and rewrote them about ten times to fix titles and validation errors. Four product defects turned that into runaway turns, a Host that would not start, and a stop button that did nothing.

- **Sync re-asked every prompt of a rewritten log.** A log the agent rewrote no longer matched the history this device had published. When another device renamed the session, the fold rewrote the local log and, because the rewrite started after this device's claim base, enqueued every user message in the dropped tail as a new prompt. The prompts carried fresh request ids, so the answered check missed them, and 372 turns ran across 17 sessions before they were stopped.
- **One corrupt log stopped the Host.** `readArtifactHeader` threw on a log whose first Zstandard frame held more than the header line, and the listing rejected as a whole, so the workspace plugin failed to load.
- **Stop could not reach a turn on another device.** `cancel` and queue edits forward only when `runnerOf` finds a live runner entry. The device running the replayed turns published none, so stop fell through to the local path and failed with `session/not-found`.
- **Nothing stopped an agent from writing the Host's stores.** An approved escalation to `danger-full-access` runs bash unconfined, and the file tools return the target unfenced in that mode.

## Decision

- `session-sync` `rewrite()` asks dropped prompts again only when the accepted events belong to another device's claim. A divergence under this device's own claim means the stored log was changed on disk after publication; the log is put back to the accepted history and no prompt is re-sent.
- `session-persistence-jsonl` classifies header failures as `CorruptSessionHeaderError`; listings skip such a log with a warning, and loading it by id still fails with the cause.
- `SessionHandoff.turnElsewhere` falls back to the index entry's `running` mark and `writer` device; `session-controller` routes `cancel` and `updateQueue` through it when no agent is attached here. A stale mark costs one forwarded input that expires unapplied.
- `sandbox-policy` gains `protectedRoots`, set in the base bundle to the Host's stores under `$AVN_HOME` (`sessions`, `storages`, `accounts`, `session-query`, `identity`, `keys`). The file tools refuse writes under them in every mode, Seatbelt profiles end with a denial for them, bwrap mounts them read-only, and `SandboxProvider.protect` wraps `danger-full-access` bash on macOS in an allow-default profile carrying only those denials.

## Alternatives considered

- **Match request ids more loosely when re-asking prompts.** Rejected because a rewritten log carries new ids for old prompts; only the claim tells a lost race from an edited file.
- **Make `runnerOf` itself trust the index `running` mark.** Rejected because renames and moves also consult it, and a mark left by a crashed device would block them indefinitely; stop and queue edits tolerate a stale mark because their forwarded input expires.
- **Refuse escalation requests that mention `~/.aeven`.** Rejected because an agent wrote its edits through a script file whose command text never named the path.

## Consequences

- Landlock cannot carve a protected root out of a writable root, and full-access bash on Linux and Windows still runs unconfined.
- An agent can still stop its own Host with `pkill`; a guard needs its own package.
- Conversations cannot be deleted across devices, and there is no supported conversation import, so an agent asked to import chats still has no product path.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Agent Note:手动编辑的会话日志不再重放其提示,Host 的存储受到保护

Status: implemented

[English](2026-11-24-hand-edited-session-logs-and-protected-host-stores.md) | 中文

## 问题

一个新桌面账户上的 agent 直接向 `~/.aeven/sessions` 写入了 22 个会话日志,并为修正标题和校验错误把它们重写了约十次。四个产品缺陷把这件事变成了失控的轮次、无法启动的 Host,以及不起作用的停止按钮。

- **同步重新提出被重写日志中的每个提示。** 被 agent 重写的日志不再与本设备已发布的历史一致。另一台设备重命名该会话时,折叠会重写本地日志;由于重写起点在本设备的认领基点之后,被丢弃尾部中的每条用户消息都作为新提示入队。这些提示带有新的请求 id,已回答检查无法识别它们,在被停止之前,17 个会话中共运行了 372 个轮次。
- **一个损坏的日志让 Host 停止。** 当日志的第一个 Zstandard 帧包含的内容多于头部行时,`readArtifactHeader` 抛出异常,整个列表请求被拒绝,导致 workspace 插件加载失败。
- **停止操作无法到达另一台设备上的轮次。** `cancel` 和队列编辑只有在 `runnerOf` 找到存活的运行者条目时才转发。运行被重放轮次的设备没有发布任何条目,于是停止落到本地路径,并以 `session/not-found` 失败。
- **没有任何机制阻止 agent 写入 Host 的存储。** 经批准升级到 `danger-full-access` 后,bash 不受限制地运行,文件工具在该模式下返回的目标也没有围栏。

## 决策

- `session-sync` 的 `rewrite()` 只在被接受的事件属于另一台设备的认领时才重新提出被丢弃的提示。在本设备自己的认领下出现分歧,说明存储的日志在发布后被磁盘上的修改改变;日志会恢复为被接受的历史,且不会重新发送任何提示。
- `session-persistence-jsonl` 将头部失败归类为 `CorruptSessionHeaderError`;列表会跳过此类日志并记录警告,按 id 加载它时仍会带着原因失败。
- `SessionHandoff.turnElsewhere` 回退到索引条目的 `running` 标记和 `writer` 设备;当本机没有附加的 agent 时,`session-controller` 通过它路由 `cancel` 和 `updateQueue`。过期的标记只会让一条转发输入在未应用的情况下过期。
- `sandbox-policy` 新增 `protectedRoots`,基础 bundle 将其设置为 `$AVN_HOME` 下 Host 的存储(`sessions`、`storages`、`accounts`、`session-query`、`identity`、`keys`)。文件工具在所有模式下拒绝写入这些目录,Seatbelt 配置以针对它们的拒绝规则结尾,bwrap 以只读方式挂载它们,`SandboxProvider.protect` 在 macOS 上把 `danger-full-access` 的 bash 包装进一个只含这些拒绝规则的默认允许配置。

## 考虑过的替代方案

- **重新提出提示时更宽松地匹配请求 id。** 未采用,因为被重写的日志为旧提示带来新的 id;只有认领能区分输掉的竞争与被编辑的文件。
- **让 `runnerOf` 本身信任索引的 `running` 标记。** 未采用,因为重命名和移动也会查询它,崩溃设备留下的标记会无限期阻塞这些操作;停止和队列编辑能容忍过期标记,因为它们转发的输入会过期。
- **拒绝提及 `~/.aeven` 的升级请求。** 未采用,因为 agent 曾通过脚本文件写入修改,而命令文本从未出现该路径。

## 后果

- Landlock 无法从可写根目录中划出受保护的根目录,Linux 和 Windows 上的完全访问 bash 仍不受限制地运行。
- agent 仍可以用 `pkill` 停止自己的 Host;防护需要单独的包。
- 会话无法跨设备删除,也没有受支持的会话导入,因此被要求导入聊天的 agent 仍没有产品路径。
4 changes: 2 additions & 2 deletions docs/config-catalog.i18n.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
# side as of the last confirmed-consistent state. Both languages carry equal authority;
# after editing either side, bring the other along and re-record with:
# pnpm run verify-translation-pairing --write docs/config-catalog.md
config-catalog.md: ef71e5388bdf372005652aea94b660dff2005be0
config-catalog.zh.md: 5ff9dde3a1109ae09415bd1e566026d643527b48
config-catalog.md: 0eaa8da35d283994998c7ca641955c8aea2e7bf8
config-catalog.zh.md: 01af4f85d6890f20677a8f44e4a6c98a4d0156de
5 changes: 5 additions & 0 deletions docs/config-catalog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4165,6 +4165,11 @@ export interface Config {
* where the desktop keeps the files it makes for the user.
*/
writableRoots?: string[]
/**
* Absolute directories no call may modify in any mode (default none): the Host's own data stores, such as session
* logs and account and workspace records, which only the Host writes.
*/
protectedRoots?: string[]
}
```

Expand Down
5 changes: 5 additions & 0 deletions docs/config-catalog.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -4167,6 +4167,11 @@ export interface Config {
* where the desktop keeps the files it makes for the user.
*/
writableRoots?: string[]
/**
* Absolute directories no call may modify in any mode (default none): the Host's own data stores, such as session
* logs and account and workspace records, which only the Host writes.
*/
protectedRoots?: string[]
}
```

Expand Down
4 changes: 2 additions & 2 deletions docs/subsystems/sandbox.i18n.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
# side as of the last confirmed-consistent state. Both languages carry equal authority;
# after editing either side, bring the other along and re-record with:
# pnpm run verify-translation-pairing --write docs/subsystems/sandbox.md
sandbox.md: 9d34b4b5d748f0c0d3ba52b90c39eab3c391279f
sandbox.zh.md: e19a1da69761b691b92d248a1af227366ab30450
sandbox.md: ef362e30d7b195cea2dd4b1fa11bb6ce3255bc61
sandbox.zh.md: 1f500e98b49f10afd0ceebe5e10bcb6547348c0a
15 changes: 15 additions & 0 deletions docs/subsystems/sandbox.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ interface SandboxExecutionPolicy {
* which lives outside the checkout. Ignored under `read-only`.
*/
additionalWritableRoots?: readonly string[]
/**
* Absolute directories no mode may modify, not even `danger-full-access`: the Host's own data stores (session logs,
* account and workspace records), which only the Host writes. Backends that express denials add them to every
* profile; {@link SandboxProvider.protect} carries them to unconfined executions.
*/
protectedRoots?: readonly string[]
/**
* Opaque identity of the calling session (the branded `avn-session`
* SessionId). Backends key per-session state off it (e.g. windows-acl gives
Expand Down Expand Up @@ -190,6 +196,15 @@ Abstract process-sandbox service. confine must return enforcing argv or fail clo
* the selected backend achieves for it.
*/
abstract confine(argv: readonly string[], policy: SandboxPolicy): ConfinedArgv

/**
* Wrap an unconfined (`danger-full-access`) argv so it may write anywhere except the policy's protected roots.
* @param argv - the exact argv the caller is about to spawn.
* @param policy - the per-call policy; only its protected roots matter here.
* @returns the argv to spawn instead, or undefined when the policy protects nothing or this host's backend cannot
* express an allow-all profile with denials, in which case the caller runs the argv unchanged.
*/
protect(argv: readonly string[], policy: SandboxExecutionPolicy): ConfinedArgv | undefined
```

Source: [`packages/sandbox/sandbox/src/index.ts`](../../packages/sandbox/sandbox/src/index.ts)
Expand Down
15 changes: 15 additions & 0 deletions docs/subsystems/sandbox.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ interface SandboxExecutionPolicy {
* which lives outside the checkout. Ignored under `read-only`.
*/
additionalWritableRoots?: readonly string[]
/**
* Absolute directories no mode may modify, not even `danger-full-access`: the Host's own data stores (session logs,
* account and workspace records), which only the Host writes. Backends that express denials add them to every
* profile; {@link SandboxProvider.protect} carries them to unconfined executions.
*/
protectedRoots?: readonly string[]
/**
* Opaque identity of the calling session (the branded `avn-session`
* SessionId). Backends key per-session state off it (e.g. windows-acl gives
Expand Down Expand Up @@ -190,6 +196,15 @@ Abstract process-sandbox service. confine must return enforcing argv or fail clo
* the selected backend achieves for it.
*/
abstract confine(argv: readonly string[], policy: SandboxPolicy): ConfinedArgv

/**
* Wrap an unconfined (`danger-full-access`) argv so it may write anywhere except the policy's protected roots.
* @param argv - the exact argv the caller is about to spawn.
* @param policy - the per-call policy; only its protected roots matter here.
* @returns the argv to spawn instead, or undefined when the policy protects nothing or this host's backend cannot
* express an allow-all profile with denials, in which case the caller runs the argv unchanged.
*/
protect(argv: readonly string[], policy: SandboxExecutionPolicy): ConfinedArgv | undefined
```

Source: [`packages/sandbox/sandbox/src/index.ts`](../../packages/sandbox/sandbox/src/index.ts)
Expand Down
4 changes: 2 additions & 2 deletions docs/subsystems/session.i18n.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
# side as of the last confirmed-consistent state. Both languages carry equal authority;
# after editing either side, bring the other along and re-record with:
# pnpm run verify-translation-pairing --write docs/subsystems/session.md
session.md: 6d0b771ea061634e7408c45932ed75bf50f376f0
session.zh.md: 34abb0492fe6afb3d43efc7c526ea151b0f78c9a
session.md: 24b08c8a6b47e8bdd54c44ffb252d5f49740e287
session.zh.md: c1a336fcb71f4be25d97e16351b3ad428f58761e
11 changes: 11 additions & 0 deletions docs/subsystems/session.md
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,17 @@ abstract shared(owner: string, sessionId: SessionId): boolean
*/
abstract runnerOf(owner: string, sessionId: SessionId): SessionRunner | undefined

/**
* The device running a turn of a session when it is another device, for inputs that only a running turn can apply
* (stop, queue edits). Besides {@link runnerOf}'s live runner it counts a session the shared index marks as running
* on another writing device, because a device whose build publishes no live runner still runs turns. A stale mark
* costs one forwarded input that expires unapplied.
* @param owner - the account.
* @param sessionId - the session.
* @returns the running device, or undefined when no other device is known to run a turn of it.
*/
turnElsewhere(owner: string, sessionId: SessionId): SessionRunner | undefined

/**
* The always-on device, such as Aeven Cloud, that ran a session's latest turn, when it is another device.
* A session stays on that device, where its files and background jobs live: this device forwards a turn-starting
Expand Down
11 changes: 11 additions & 0 deletions docs/subsystems/session.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,17 @@ abstract shared(owner: string, sessionId: SessionId): boolean
*/
abstract runnerOf(owner: string, sessionId: SessionId): SessionRunner | undefined

/**
* The device running a turn of a session when it is another device, for inputs that only a running turn can apply
* (stop, queue edits). Besides {@link runnerOf}'s live runner it counts a session the shared index marks as running
* on another writing device, because a device whose build publishes no live runner still runs turns. A stale mark
* costs one forwarded input that expires unapplied.
* @param owner - the account.
* @param sessionId - the session.
* @returns the running device, or undefined when no other device is known to run a turn of it.
*/
turnElsewhere(owner: string, sessionId: SessionId): SessionRunner | undefined

/**
* The always-on device, such as Aeven Cloud, that ran a session's latest turn, when it is another device.
* A session stays on that device, where its files and background jobs live: this device forwards a turn-starting
Expand Down
16 changes: 14 additions & 2 deletions packages/api/session-controller/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@ export class SessionCommandController {
)
}
}
const owner = this.runnerAccount(request.sessionId)
const owner = this.turnAccount(request.sessionId)
if (owner !== undefined) return this.forward(owner, request.sessionId, 'queue', request)
const agent = this.ctx.agents.get(request.sessionId)
if (agent !== undefined && hasApiSessionSubagentOwner(this.ctx, agent.session, agent)) {
Expand Down Expand Up @@ -859,7 +859,7 @@ export class SessionCommandController {
* @returns acknowledgement that cancellation was requested.
*/
cancel(request: SessionCancelRequest): SessionCancelValue | Promise<SessionCancelValue> {
const owner = this.runnerAccount(request.sessionId)
const owner = this.turnAccount(request.sessionId)
if (owner !== undefined) return this.forward(owner, request.sessionId, 'cancel', request)
const agent = this.ctx.agents.get(request.sessionId)
if (agent === undefined || !this.agents.callerMayAccess(agent.session.header)) {
Expand Down Expand Up @@ -896,6 +896,18 @@ export class SessionCommandController {
return this.ctx.get('sessionHandoff')?.runnerOf(owner, sessionId) === undefined ? undefined : owner
}

/**
* The account whose other device runs a turn of a session that is not attached here, for inputs only a running
* turn applies (stop, queue edits): such a turn may be known only from the shared index's running mark.
*/
private turnAccount(sessionId: SessionId): string | undefined {
const owner = this.runnerAccount(sessionId)
if (owner !== undefined || this.ctx.agents.get(sessionId) !== undefined) return owner
const acting = this.ctx.get('identityUsers')?.actingUser()?.id
if (acting === undefined) return undefined
return this.ctx.get('sessionHandoff')?.turnElsewhere(acting, sessionId) === undefined ? undefined : acting
}

/**
* Route one browser message to a continuable subagent as a prompt to its parent would be routed: forwarded to the
* account's device that runs the parent, or, when this device runs it, delivered here after this device claims the
Expand Down
2 changes: 2 additions & 0 deletions packages/bundle/base/cordis.patch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,8 @@
config:
mode: !!js process.env.AVN_PERMISSION_MODE ?? 'workspace-write'
workspaceRoot: !!js process.cwd()
# The Host's own stores: no command or file tool may change them, at any access mode.
protectedRoots: !!js "['sessions', 'storages', 'accounts', 'session-query', 'identity', 'keys'].map(dir => avnHomePath(dir))"

- id: bash-sandbox
name: '@aeven/bash-sandbox'
Expand Down
Loading
Loading