Skip to content

fix(workspace): re-read the catalog on every v2 registry operation - #1706

Merged
sailist merged 1 commit into
MoonshotAI:mainfrom
sailist:fix-workspace-catalog-rmw
Jul 14, 2026
Merged

fix(workspace): re-read the catalog on every v2 registry operation#1706
sailist merged 1 commit into
MoonshotAI:mainfrom
sailist:fix-workspace-catalog-rmw

Conversation

@sailist

@sailist sailist commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator

Related Issue

Follow-up to #1701 (merged) — addresses the two Codex review findings on that PR.

Problem

Two issues in #1701's implementation, flagged by Codex's automated review:

  1. (P1) Stale-cache overwrite across engines. The v2 registry loaded workspaces.json once into an in-memory cache and wrote that snapshot back wholesale on every mutation. When a v1 process (the TUI's new touchWorkspaceRegistry path) updated the same file between the v2 load and a later v2 create/update/delete, the v2 write clobbered the v1-added workspace entries and deletion tombstones — breaking the cross-engine sync the change was meant to provide.
  2. (P2) Layering violation. The shared workspaces.json helper lived in services/workspace, but services/ is agent-core's upper facade: the rpc runtime must not import back into it, and core-impl.ts did exactly that.

What changed

  • No write cache in the v2 registry. Every list/get/createOrTouch/update/delete is now a fresh read-modify-write of workspaces.json under the existing promise-chain mutex — the same per-op read model v1 already uses on both sides (WorkspaceRegistryService and touchWorkspaceRegistry). The session-index merge stays once per process behind a flag, still inside the mutex, so it cannot interleave with a mutation. The cross-process lost-update window shrinks from the process lifetime to a single read-modify-write, with the next startup merge as the healer.
  • Moved the shared file helper from services/workspace/workspaceRegistryFile.ts to session/store/workspace-registry-file.ts (same layer as session-index.ts, kebab-case per directory convention) and updated all importers; the services/ facade no longer re-exports it.
  • Regression tests: external (v1-style) writes landing between a v2 load and a v2 mutation are preserved for createOrTouch (entries + tombstones), delete (tombstones accumulate), and update (operates on current file state, misses externally removed ids).

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill, or this PR needs no changeset (amends fix(workspace): sync workspace catalog across v1/v2 and soft-delete #1701's unreleased behavior; that PR's changeset already describes the final user-visible change).
  • Ran gen-docs skill, or this PR needs no doc update.

- drop the in-memory write cache in the v2 registry: every list/get/
  mutation is a fresh read-modify-write of workspaces.json under the op
  mutex, so v1 writers (touchWorkspaceRegistry) are never clobbered by a
  stale snapshot; the session-index merge stays once per process behind
  a flag (Codex P1)
- move the shared workspaces.json helper from services/workspace (the
  upper facade) to session/store, so the rpc runtime no longer imports
  back into services/ (Codex P2)
@pkg-pr-new

pkg-pr-new Bot commented Jul 14, 2026

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@05397ba
npx https://pkg.pr.new/@moonshot-ai/kimi-code@05397ba

commit: 05397ba

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 05397ba1b9

ℹ️ 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".


private cache: Map<string, Workspace> | undefined;
private deletedIds: Set<string> | undefined;
/** Whether the once-per-process session-index sync already ran. */

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Keep v2 comments in the file header

packages/agent-core-v2/AGENTS.md requires comments in this package to live solely in the top-of-file /** */ block and never beside functions, methods, or statements. This new inline field comment violates that convention (as do the new helper docblocks below), so please move any necessary rationale into the file header or let the merged name carry it.

Useful? React with 👍 / 👎.

@sailist
sailist merged commit 9e6d53b into MoonshotAI:main Jul 14, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant