Skip to content

fix(workspace): sync workspace catalog across v1/v2 and soft-delete - #1701

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

fix(workspace): sync workspace catalog across v1/v2 and soft-delete#1701
sailist merged 1 commit into
MoonshotAI:mainfrom
sailist:fix-workspace-catalog-sync

Conversation

@sailist

@sailist sailist commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator

Related Issue

No linked issue — the problem is explained below.

Problem

The workspace catalog (<homeDir>/workspaces.json, shared by the v1 TUI engine and the agent-core-v2 server) drifts from where sessions actually live:

  • Sessions created by the TUI only append to session_index.jsonl; their directories never land in workspaces.json, so the web UI can only show them as unmanaged "derived" workspaces.
  • The v2 server rebuilds the catalog from the session index only when the file is missing or corrupt, so workspaces created after the first materialization never show up.
  • v2 workspace removal is a hard delete: the next catalog rebuild resurrects removed workspaces as long as sessions still reference the directory. (v2's save also silently dropped the v1 deleted_workspace_ids field on write.)

What changed

  • v1 (TUI/SDK): KimiCore now registers the cwd in workspaces.json when a session is created (best-effort, never fails session creation). The read/modify/write lives in a new shared workspaceRegistryFile module that WorkspaceRegistryService also delegates to, so there is a single implementation of the file format.
  • v2 startup sync: the registry merges session_index.jsonl into the catalog once per fresh load — adding only paths the file does not already know — and kap-server awaits one sync pass during boot, so the catalog is complete before the server accepts traffic.
  • Soft delete: v2 delete now tombstones the id in the v1-compatible deleted_workspace_ids field instead of dropping it silently; the session-index merge never resurrects a tombstoned id, while an explicit createOrTouch (TUI session create, web "add workspace", v2 session create) clears the tombstone and brings the workspace back.

User-visible effect: the web sidebar lists every workspace that has sessions (including TUI-only ones), and a removed workspace stays removed across server restarts until the user works in that directory again.

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.
  • Ran gen-docs skill, or this PR needs no doc update.

- register the cwd in workspaces.json when a v1 (TUI/SDK) session is
  created, via a shared workspaceRegistryFile read/write/touch module
- merge session_index.jsonl into the catalog once at v2 startup
  (awaited during kap-server boot), adding only paths absent from
  workspaces.json
- make v2 workspace delete a soft delete through the v1-compatible
  deleted_workspace_ids field: the session-index merge never resurrects
  tombstoned ids, while an explicit createOrTouch clears the tombstone
@changeset-bot

changeset-bot Bot commented Jul 14, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 73ad361

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@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@73ad361
npx https://pkg.pr.new/@moonshot-ai/kimi-code@73ad361

commit: 73ad361

@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: 73ad361e91

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

Comment on lines +227 to +230
await this.store.save({
workspaces: [...cache.values()],
deletedIds: [...deletedIds],
});

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 Merge disk state before saving the cached catalog

When the v2 server has already loaded the registry, a v1 process can now update the same workspaces.json via the new touchWorkspaceRegistry path, but this save writes only the stale in-memory cache. In the scenario where v2 loads the catalog, the v1 TUI creates or reopens another workspace, and then v2 handles any create/update/delete, this overwrite drops the v1-added workspace or tombstone and breaks the cross-engine sync this change is meant to provide. Re-read and merge the current file (or otherwise coordinate writes) before persisting.

Useful? React with 👍 / 👎.

} from '../session/provider-manager';
import { SessionAPIImpl } from '../session/rpc';
import { normalizeWorkDir, SessionStore } from '../session/store/index';
import { touchWorkspaceRegistry } from '../services/workspace/workspaceRegistryFile';

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Keep rpc from importing the services facade

packages/agent-core/src/services/AGENTS.md says the services subtree is an upper facade and that the runtime must not import back into services/; core-impl.ts is under src/rpc and now imports a helper from ../services/..., reversing that boundary. Move the shared workspace-file helper to a lower-level module that both rpc and the service facade can depend on, otherwise this path can pull facade dependencies into the runtime and reintroduce cycles as the service layer evolves.

Useful? React with 👍 / 👎.

@sailist
sailist merged commit 07c3632 into MoonshotAI:main Jul 14, 2026
15 checks passed
@github-actions github-actions Bot mentioned this pull request Jul 14, 2026
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