CodeWhale icon indicating copy to clipboard operation
CodeWhale copied to clipboard

Sub-agent state persists to `.deepseek/` instead of `.codewhale/` — lingering pre-rebrand path

Open yekern opened this issue 5 months ago • 4 comments


name: Bug report — Sub-agent state file still writes to .deepseek/ after rebrand about: Worker state JSON persisted to old branded directory, not .codewhale/ labels: bug, branding

Description

CodeWhale 0.8.x creates two hidden directories in the project root:

  • .codewhale/ — session config, constitution, MCP config (correct, post-rebrand)
  • .deepseek/state/subagents.v1.json — sub-agent worker state (legacy, should live under .codewhale/)

When sub-agents are spawned via the agent tool, worker state is written to .deepseek/state/subagents.v1.json instead of .codewhale/state/subagents.v1.json. This is a leftover path from before the rebrand.

Steps to reproduce

  1. codewhale — enter any project
  2. Trigger a sub-agent in chat (e.g. via agent tool)
  3. After the sub-agent finishes or is cancelled, inspect the project root

Expected behavior

  • All runtime state is written to .codewhale/ (e.g. .codewhale/state/subagents.v1.json)
  • .deepseek/ is no longer created (or only read once during migration)

Actual behavior

  • .codewhale/ already contains config.toml, constitution.json, mcp.json
  • But every sub-agent run creates .deepseek/state/subagents.v1.json
  • Two directories coexist, causing confusion about which is authoritative

Impact

  • Project root has two dot-directories; users are unsure which one is the real runtime dir
  • Deleting .deepseek/ loses sub-agent history, but it is recreated on the next run
  • Incomplete rebrand — the project still looks like a DeepSeek project to outsiders

Environment

  • OS: Linux (Ubuntu 22.04)
  • codewhale version: 0.8.66
  • Install method: release binary
  • Model/provider: deepseek-v4-pro / DeepSeek
  • Shell: zsh

Details

Current layout:

.codewhale/
├── config.toml
├── constitution.json
└── mcp.json

.deepseek/
└── state/
    └── subagents.v1.json   # still written here

Expected layout:

.codewhale/
├── config.toml
├── constitution.json
├── mcp.json
└── state/
    └── subagents.v1.json   # should be here

Root cause analysis (verified in v0.8.66)

Culprit

crates/tui/src/tools/subagent/mod.rs:3233–3251 — the default_state_path function.

fn default_state_path(workspace: &Path) -> Result<PathBuf> {
    let workspace = normalize_subagent_workspace(workspace);
    // Prefer .codewhale, fall back to .deepseek for project-local state
    let primary = checked_subagent_state_path(
        &workspace,
        &Path::new(".codewhale")
            .join("state")
            .join(SUBAGENT_STATE_FILE),    // .codewhale/state/subagents.v1.json
    )?;
    if primary.exists() {
        return Ok(primary);
    }
    // ⚠️ BUG: when .codewhale/state/subagents.v1.json does NOT exist,
    // .deepseek/ is returned as the *write* path, not a read-only fallback.
    checked_subagent_state_path(
        &workspace,
        &Path::new(".deepseek")
            .join("state")
            .join(SUBAGENT_STATE_FILE),    // .deepseek/state/subagents.v1.json
    )
}

Why .codewhale/state/subagents.v1.json is never created

Step File : line What happens
1 mod.rs:3236 Build primary path .codewhale/state/subagents.v1.json
2 mod.rs:3242 primary.exists() → false on first run → fallback to .deepseek
3 mod.rs:3425 new_shared_subagent_manager_with_timeout calls default_state_path
4 mod.rs:3438 Result set as state_path via with_state_path
5 mod.rs:3389 write_json_atomic calls fs::create_dir_all(parent), creating .deepseek/state/
6 mod.rs:3394 All agent state written to .deepseek/state/subagents.v1.json

Because the primary path check (primary.exists()) is the gate, and .codewhale/state/ is never pre-created by any other code path, the fallback branch is always taken on fresh projects. The .codewhale/ root directory exists (created for config.toml, constitution.json, mcp.json), but its state/ subdirectory does not — so the file never lands there.

Additional references

  • crates/tui/src/project_context.rs:1619–1627 — test still creates .deepseek/state/subagents.v1.json as fixture (legacy path not cleaned up in tests either)
  • crates/config/src/lib.rs:1598 — comment acknowledges legacy $WORKSPACE/.deepseek/config.toml fallback
  • crates/config/src/lib.rs:3245–3248 — v0.8.44 migration strategy comment about ~/.deepseek/ → ~/.codewhale/ (user-level state, separate from this project-level bug)

Fix direction

  1. Always write to .codewhale/state/subagents.v1.json — this is the canonical post-rebrand path
  2. On load, try .codewhale/state/subagents.v1.json first; if absent, read from .deepseek/state/subagents.v1.json and migrate existing data to the canonical path
  3. .deepseek/ should only be read once for one-time migration; it must never be created or written to on new installs
  4. Update project_context.rs:1619 test to use .codewhale/state/subagents.v1.json

问题描述

CodeWhale 0.8.x 在项目根目录创建两个隐藏目录:

  • .codewhale/ — 会话配置、constitution、MCP 配置(品牌化后正确)
  • .deepseek/state/subagents.v1.json — 子任务运行时状态(遗留路径,应归入 .codewhale/)

当通过 agent 工具创建子任务时,worker 状态被写入 .deepseek/state/subagents.v1.json 而非 .codewhale/state/subagents.v1.json。这是品牌化重构前遗留的路径。

复现步骤

  1. codewhale — 进入任意项目
  2. 在对话中触发子任务(例如调用 agent 工具)
  3. 子任务完成或被取消后检查项目根目录

期望行为

  • 所有运行时状态统一写入 .codewhale/(如 .codewhale/state/subagents.v1.json)
  • .deepseek/ 不再被创建(或仅在首次迁移旧数据时读取)

实际行为

  • .codewhale/ 已有 config.toml、constitution.json、mcp.json
  • 但每次使用子任务仍会创建 .deepseek/state/subagents.v1.json
  • 两个目录共存,用户无法判断哪个是真正的运行时目录

影响范围

  • 项目根有两个点目录,用户不确定哪个有效
  • 删除 .deepseek/ 导致子任务历史丢失,但下次运行又会重建
  • 品牌化不彻底,第三方看来仍是 DeepSeek 项目

环境信息

  • OS: Linux (Ubuntu 22.04)
  • codewhale version: 0.8.66
  • Install method: release binary
  • Model/provider: deepseek-v4-pro / DeepSeek
  • Shell: zsh

当前目录结构

.codewhale/
├── config.toml
├── constitution.json
└── mcp.json

.deepseek/
└── state/
    └── subagents.v1.json   # 仍在此处写入

期望目录结构

.codewhale/
├── config.toml
├── constitution.json
├── mcp.json
└── state/
    └── subagents.v1.json   # 应移至此处

根因分析(v0.8.66 已验证)

肇事代码

crates/tui/src/tools/subagent/mod.rs:3233–3251 — default_state_path 函数。

fn default_state_path(workspace: &Path) -> Result<PathBuf> {
    let workspace = normalize_subagent_workspace(workspace);
    // Prefer .codewhale, fall back to .deepseek for project-local state
    let primary = checked_subagent_state_path(
        &workspace,
        &Path::new(".codewhale")
            .join("state")
            .join(SUBAGENT_STATE_FILE),    // .codewhale/state/subagents.v1.json
    )?;
    if primary.exists() {
        return Ok(primary);
    }
    // ⚠️ BUG:当 .codewhale/state/subagents.v1.json 不存在时,
    // .deepseek/ 被当作写入路径返回,而非只读兼容路径。
    checked_subagent_state_path(
        &workspace,
        &Path::new(".deepseek")
            .join("state")
            .join(SUBAGENT_STATE_FILE),    // .deepseek/state/subagents.v1.json
    )
}

.codewhale/state/subagents.v1.json 为何永远不会被创建

步骤 文件 : 行号 行为
1 mod.rs:3236 构造主路径 .codewhale/state/subagents.v1.json
2 mod.rs:3242 primary.exists() → 首次运行为 false → fallback 到 .deepseek
3 mod.rs:3425 new_shared_subagent_manager_with_timeout 调用 default_state_path
4 mod.rs:3438 结果通过 with_state_path 设为 state_path
5 mod.rs:3389 write_json_atomic 调用 fs::create_dir_all(parent) 创建 .deepseek/state/
6 mod.rs:3394 所有 agent 状态写入 .deepseek/state/subagents.v1.json

主路径的存在性检查 (primary.exists()) 是唯一闸门,而 .codewhale/state/ 子目录没有被任何其他代码路径预先创建,因此在全新项目上 永远进入 fallback 分支。.codewhale/ 根目录存在(由 config.toml、constitution.json、mcp.json 的创建逻辑保证),但其 state/ 子目录不存在,导致文件永远不会落在正确位置。

其他引用点

  • crates/tui/src/project_context.rs:1619–1627 — 测试仍使用 .deepseek/state/subagents.v1.json 作为 fixture(遗留路径在测试中同样未清理)
  • crates/config/src/lib.rs:1598 — 注释提及 legacy $WORKSPACE/.deepseek/config.toml 兼容
  • crates/config/src/lib.rs:3245–3248 — v0.8.44 迁移策略注释 ~/.deepseek/ → ~/.codewhale/(用户级状态,与本 project-level bug 独立)

修复方向

  1. 始终写入 .codewhale/state/subagents.v1.json — 品牌化后的权威路径
  2. 加载时优先读取 .codewhale/state/subagents.v1.json;若不存在,读取 .deepseek/state/subagents.v1.json 并将已有数据迁移至权威路径
  3. .deepseek/ 仅限一次性迁移读取,新安装不应再创建或写入该路径
  4. 同步更新 project_context.rs:1619 测试,使用 .codewhale/state/subagents.v1.json

yekern avatar Jul 01 '26 05:07 yekern

Thanks @yekern for the report.

This issue is staying open for maintainer triage. CodeWhale gets better because people bring us real edge cases from real machines, providers, regions, and workflows.

If you can add a reproduction, logs, version output, screenshots, or the provider/model involved, that makes it much easier for us to verify and harvest the fix. Maintainers may comment /lgtmi to mark recurring issue reporters as approved so this intake note is skipped next time.

github-actions[bot] avatar Jul 01 '26 05:07 github-actions[bot]

Update: this report has been pulled into the v0.8.67 milestone and the fix has been harvested into the draft release branch via PR #3861.

  • harvested PR: #3865 by @yekern
  • release branch commit: 9f1e5c682 (fix(tui): persist sub-agent state to .codewhale/ instead of .deepseek/)
  • behavior: new writes use .codewhale/state/subagents.v1.json; legacy .deepseek/state/subagents.v1.json is read only as a migration fallback when the canonical file is missing

Verification run locally on the release branch:

  • cargo test -p codewhale-tui --bin codewhale-tui --locked subagent -- --nocapture - 249 passed
  • cargo test -p codewhale-tui --bin codewhale-tui --locked project_context_pack_ignores_agent_state_and_binary_noise -- --nocapture - 1 passed
  • cargo fmt --all -- --check
  • git diff --check
  • RUSTFLAGS="-D warnings" cargo test -p codewhale-tui --bin codewhale-tui --locked --no-run
  • cargo test -p codewhale-config --lib - 326 passed
  • cargo test -p codewhale-tui --bin codewhale-tui --locked setup -- --nocapture - 106 passed
  • cargo test -p codewhale-tui --bin codewhale-tui --locked constitution -- --nocapture - 40 passed

Keeping this open until the release branch lands on main and the fix is available from the mainline/release path.

Hmbown avatar Jul 01 '26 06:07 Hmbown

Metadata-only correction after the contributor-credit lint check: the same fix is now commit ec67ec7f on the release branch, replacing the earlier 9f1e5c682 SHA. The file tree is unchanged; only the harvested commit author metadata was canonicalized through .github/AUTHOR_MAP.

Hmbown avatar Jul 01 '26 06:07 Hmbown

Resolved on the v0.8.67 release branch (claude/v0.8.67-constitution-setup-174rj9) by commit ec67ec7ff — "fix(tui): persist sub-agent state to .codewhale/ instead of .deepseek/".

Verified: sub-agent state now writes .codewhale/state/ with a one-time .deepseek/ read-migration fallback.

This closes with the release branch; reopening is trivial if the merge strategy changes.

Hmbown avatar Jul 02 '26 04:07 Hmbown