Repository navigation
Conversation
|
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
commit: |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 06dc55dea6
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| await this.sessionSpace.delete( | ||
| this.sessionSpace.keyFor(sessionScopeOf(this.handlerScope, sessionId)), | ||
| ); |
There was a problem hiding this comment.
Keep deletion idempotent for indexed sessions
When a session remains in the index but its directory is already absent—for example after manual cleanup or an interrupted recovery—the new SessionSpace.delete() throws not-found, so execution never reaches index.remove() and TUI, SDK, KAP, and ACP clients cannot remove the stale session. The previous HostFileSystem.remove() used forceful recursive removal and still completed the index cleanup; treat an absent directory as already deleted at this lifecycle boundary.
AGENTS.md reference: AGENTS.md:L207-L209
Useful? React with 👍 / 👎.
| this.data = { ...this.data, ...patch, updatedAt }; | ||
| await this.store.set(this.scope, META_KEY, encodeSessionMeta(this.data)); | ||
| const next: SessionMeta = { ...this.data, ...patch, updatedAt }; | ||
| this.data = await this.sessionSpace.update(this.key, next, { touchUpdatedAt: false }); |
There was a problem hiding this comment.
Preserve normalized fields when updating legacy metadata
For an old metadata record whose id or timestamps need normalization but which already has agents, custom, and consistent title fields, load() normalizes only the in-memory value and does not rewrite it. This call then rereads the raw record through SessionSpace.update(), which preserves the raw immutable id and createdAt over the normalized next value; an untitled legacy record with ISO timestamps and no id, for example, becomes a version-2 record with a missing id and string createdAt after its first prompt, breaking live KAP/SDK summaries and index mirroring. Persist the normalized record before using the generic update path.
AGENTS.md reference: AGENTS.md:L191-L193
Useful? React with 👍 / 👎.
| if (isEnoent(error)) return false; | ||
| throw error; | ||
| } | ||
| await rm(dir, { recursive: true, force: true }); |
There was a problem hiding this comment.
Verify a record exists before deleting its directory
If a/b is a valid stored session but no record exists at a, delete('a') sees the ancestor directory, recursively removes it, and reports success, silently deleting a/b instead of returning not-found. The host adapter has the same directory-only existence check. Check for a canonical or legacy state.json belonging to the requested key before removing the container.
Useful? React with 👍 / 👎.
| } | ||
| if (key !== '' && entries.some((entry) => entry.isFile() && entry.name === 'state.json')) { | ||
| keys.push(key); | ||
| return; |
There was a problem hiding this comment.
Continue traversal below parent records
Hierarchical keys permit both a and a/b, but after both are successfully created this early return stops traversal at a/state.json, so the filesystem backend's list() omits a/b while the memory backend returns both. The host adapter repeats the same early return. Record the parent key without terminating traversal so all valid descendant keys remain discoverable.
Useful? React with 👍 / 👎.
| if ((await backend.read(key)) !== undefined) { | ||
| throw new SessionSpaceError('already-exists', `session '${key}' already exists`); |
There was a problem hiding this comment.
Make duplicate creation atomic
When two callers concurrently run create() for the same key, both can await backend.read() before either write occurs, observe that the key is absent, and then both resolve successfully while the later write overwrites the first. This violates the advertised already-exists behavior and is reproducible with the asynchronous memory backend as well as possible across node-backed processes; use an exclusive backend create operation or per-key serialization so exactly one caller succeeds.
Useful? React with 👍 / 👎.
| key.length === 0 || | ||
| key.startsWith('/') || | ||
| key.endsWith('/') || | ||
| key.includes('\\') || |
There was a problem hiding this comment.
Preserve accepted custom session IDs
Lifecycle operations now derive storage keys from externally supplied session IDs and reject backslashes here, even though the Klient lifecycle contract still accepts any string and the previous document-store path accepted a backslash as a literal filename character on Linux. A caller with an existing ID such as release\candidate can therefore no longer create, resume, or delete that session after upgrading. Encode IDs when forming keys or narrow the external contract with explicit compatibility handling.
AGENTS.md reference: AGENTS.md:L191-L193
Useful? React with 👍 / 👎.
| { | ||
| seeds: [ | ||
| ...sessionContextSeed(ctx), | ||
| [ISessionSpace, this.sessionSpace], |
There was a problem hiding this comment.
Provide SessionSpace to directly created session scopes
SessionMetadata is activated for session scopes and now requires ISessionSpace, but this seed is only supplied by SessionLifecycleService. The shared TestAgent harness creates its session directly with root.createChild(LifecycleScope.Session, ...) and later resolves ISessionMetadata without providing this token, so harness-backed agent and conversation tests fail during dependency injection. Register an app-level implementation or add the same seed to every direct session-scope factory.
Useful? React with 👍 / 👎.
| (await this.storage.read(key, 'state.json')) ?? | ||
| (await this.storage.read(`${key}/session-meta`, 'state.json')); |
There was a problem hiding this comment.
Disambiguate legacy metadata from valid child keys
Because session-meta remains a valid key component, a record stored at a/session-meta is also returned by get('a') through this legacy fallback. As a result, create('a') falsely reports already-exists, and the filesystem walker similarly reports the child under the wrong key; the host adapter duplicates this behavior. Reserve and reject the sentinel component or disambiguate legacy metadata without interpreting an otherwise opaque key.
Useful? React with 👍 / 👎.
| private readonly storage: FileStorageService; | ||
|
|
||
| constructor(private readonly root: string) { | ||
| this.storage = new FileStorageService(root); |
There was a problem hiding this comment.
Protect node-backed session files with private modes
With a normal 022 umask and a caller-supplied root beneath a traversable directory, this default FileStorageService creates intermediate directories as 0755 and state.json as 0644, exposing session titles, prompts, and custom metadata to other local users. The application bootstrap explicitly configures the same storage implementation with 0700 directories and 0600 files, while nodeSessionSpace() offers no mode option. Use private defaults or expose secure mode configuration.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1a5d06deb6
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| return record; | ||
| }, | ||
| update: async (key, patch, opts) => { | ||
| const current = await read(key); |
There was a problem hiding this comment.
Serialize read-modify-write updates
When two callers update the same key concurrently, both can finish this read before either write occurs, so each merges against the same old record and the later write silently discards fields from the earlier patch. This is reproducible with memorySessionSpace() and affects core consumers that issue independent updates; serialize operations per key or provide an atomic backend mutation primitive so concurrent patches cannot lose data.
AGENTS.md reference: AGENTS.md:L211-L213
Useful? React with 👍 / 👎.
Requirement or Bug
核心维护者需要在不依赖 workspace、cwd 或 v2 DI 的前提下复用 session catalog 的增删改查能力,同时保留现有 session 生命周期、
state.json格式和 KAP 行为。本 PR 在 core 提供 OSS 风格的 key-based SessionSpace,并让 v2 的权威 session 读写通过同一实现完成。Bug Reproduction Steps
N/A
Root Cause
N/A
Code Changes
核心思路是把“通用 session CRUD”与“workspace/cwd、live SessionScope、派生索引和 fork/copy”分开。SessionSpace 使用不透明 key 寻址,
list(prefix?)只返回 key,不隐式读取所有 record;不传 prefix 时执行全量枚举。当前磁盘布局可以直接映射为 root=sessions、key=<workspaceId>/<sessionId>,core 不解释 key 中的 workspace 含义。flowchart TD Core[core SessionSpace] --> Memory[Memory backend] Core --> Node[Node backend] Lifecycle[v2 SessionLifecycle] -->|SessionScope seed| Metadata[v2 SessionMetadata] Lifecycle --> Adapter[HostSessionSpace adapter] Metadata --> Adapter Adapter --> Core Adapter --> Docs[v2 AtomicDocumentStore] Adapter --> HostFs[v2 HostFileSystem]关键决策:
create/get/update/delete/list、结构化错误、Memory 和 Node backend;Node 支持 canonical/legacystate.json和整个 session 容器删除。SessionMeta保持显式磁盘字段并结构化兼容 coreSessionRecord,避免改变生成的 state manifest;现有isCustomTitle、legacy 路径、显式updatedAt和touchUpdatedAt: false语义保留。session.jsonl。阅读顺序建议:先看
packages/core/src/session/model.ts了解记录与接口,再看packages/core/src/session/space.ts的公共 CRUD 语义、packages/core/src/session/backend/node.ts的物理布局,最后看packages/agent-core-v2/src/session/sessionSpace/sessionSpaceService.ts和sessionLifecycleService.ts的 v2 接线。Memory backend、类型迁移和测试可随后阅读。Behavior Changes and Affected Users
state.jsonfields, legacy reads, index behavior, KAP and lifecycle semantics are unchanged; no migration is needed现有 CLI、Desktop、SDK、ACP 和 KAP 调用方没有可感知的破坏性变化。没有修改 KAP、wire/state/config manifests、SDK、ACP 或 CLI 契约文件,也不需要数据迁移。
验证覆盖:
pnpm lint以 0 退出;相对loop-refact的显式 base duplication 检查无新增 clone。stateManifest兼容检查通过。剩余tool.test、config 快照和 skillmodel-tool三项失败与 loop-refact 自身的 LLM loop/tool 改动处于同一风险范围,但不在本 PR 的 SessionSpace diff 内,基线归属尚待确认。未完成的验证
远程 Linux 和 Windows 环境两轮初始化均因 SSH 连接超时失败,因此远程全量回归、kap-server sessions 端到端和真实冷重启测试未执行。这些项目在本 PR 中不作为已通过验证声明。
Checklist