Skip to content

feat: per-workflow state isolation with project/ namespace (v10.2)#27

Open
volkz wants to merge 1 commit into
romiluz13:mainfrom
volkz:feat/per-workflow-state-isolation
Open

feat: per-workflow state isolation with project/ namespace (v10.2)#27
volkz wants to merge 1 commit into
romiluz13:mainfrom
volkz:feat/per-workflow-state-isolation

Conversation

@volkz

@volkz volkz commented Jun 12, 2026

Copy link
Copy Markdown

Problem

When two Claude Code windows work on the same repo simultaneously, they both write to the same flat activeContext.md — last writer wins, state gets clobbered. There is no isolation between parallel workflows on the same repo.

Solution

Adds a three-tier memory structure that eliminates cross-workflow state collision:

.cc10x/v10/
├── project/                    ← NEW: long-lived cross-workflow state
│   ├── activeContext.md        (architecture decisions, domain patterns, ongoing blockers)
│   ├── patterns.md
│   └── progress.md
├── workflows/
│   ├── <wf-id>.json            (existing hook artifact — unchanged)
│   ├── <wf-id>.events.jsonl    (existing — unchanged)
│   └── <wf-id>/                ← NEW: per-workflow isolated state
│       ├── activeContext.md    (current focus, active phase, in-flight tasks)
│       ├── patterns.md
│       └── progress.md
├── activeContext.md             (kept — backward-compat fallback)
├── patterns.md
└── progress.md

Two parallel Claude Code windows on the same repo each write exclusively to their own workflows/<wf-id>/ directory while sharing read-only access to project/ for durable project context.

Changes

scripts/cc10x_hooklib.py

  • Adds project_state_dir() — returns .cc10x/v10/project/, creates it on demand
  • Adds workflow_state_dir(workflow_id) — returns .cc10x/v10/workflows/<wf-id>/, creates it on demand

scripts/cc10x_pretooluse_guard.py

  • Replaces the static protected-file set with _protected_memory_paths(), which dynamically covers all three tiers: root-flat, project/, and any existing workflows/<wf-id>/ directories
  • Guard now audits/blocks writes to per-workflow memory files — parallel agents can no longer bypass it

scripts/cc10x_context_migration.py

  • Adds _migrate_flat_to_project() — one-time intra-v10 migration that copies existing root-flat memory files into project/ on the first SessionStart after upgrading. Idempotent via a .project-namespace-migrated marker. Copies (not moves) to preserve the backward-compat fallback.
  • Adds project and workflows to the source-discovery skip-list in _discover_sources() so the new namespace subdirectories are never treated as legacy migration sources

skills/cc10x-router/SKILL.md

  • §2 Memory Load: updates the 4-step load to a 6-step two-tier load — always load project/ first, then load workflows/{wf}/ when a workflow_uuid is already known (resume path). Defines the merge precedence rule.
  • §6 Workflow Task Graphs: adds step 4 — immediately after artifact creation, initialize the per-workflow state directory with mkdir -p .cc10x/v10/workflows/{workflow_uuid}
  • §13 Memory Finalization: replaces the flat write list with an explicit write routing table. MEMORY_NOTES.patternsproject/patterns.md. MEMORY_NOTES.learnings + verificationworkflows/{wf}/. Cross-workflow promotions clearly defined.

skills/session-memory/SKILL.md

  • Updates Load-Bearing Boundaries to document the three-tier namespace
  • Updates Memory Surfaces with per-tier descriptions and when to use each
  • Updates Always Load with the ordered three-tier load sequence and merge rule
  • Updates Red Flags to reference all three tier paths

Backward Compatibility

  • Root-flat files are preserved (copy, not move) as a fallback layer
  • Existing workflow artifact schema is unchangedstate_root still points at .cc10x/v10/
  • The heading contract (required sections, stable anchors) is identical across all three tiers — no new templates needed
  • Repos that have never generated a workflow_uuid continue working via the root-flat fallback until their first new workflow

Test Plan

  • Fresh install: project/ created on first workflow; per-wf dir created after UUID generation in §6
  • Existing install: cc10x_context_migration.py copies root-flat → project/ on SessionStart; .project-namespace-migrated marker prevents repeat runs
  • Parallel windows: two Claude Code sessions on the same repo each write to distinct workflows/<wf>/ dirs; project/ is shared read context
  • Pre-tool-use guard: write to project/activeContext.md from a write agent is audited/blocked
  • Pre-tool-use guard: write to workflows/<wf>/activeContext.md from a write agent is audited/blocked
  • Memory finalization: MEMORY_NOTES.patterns lands in project/patterns.md; workflow-local items stay in workflows/<wf>/
  • _discover_sources() does not treat project/ or workflows/ as migration sources
  • Repos with no workflow_uuid context continue to use root-flat fallback without errors

Adds a three-tier memory structure that eliminates cross-workflow state
clobber when two Claude Code windows work on the same repo simultaneously.

New layout:
  .cc10x/v10/
  ├── project/              ← NEW: long-lived cross-workflow state
  │   ├── activeContext.md  (architecture, decisions, durable patterns)
  │   ├── patterns.md
  │   └── progress.md
  ├── workflows/
  │   ├── <wf-id>.json      (existing hook artifact)
  │   ├── <wf-id>.events.jsonl (existing)
  │   └── <wf-id>/          ← NEW: per-workflow isolated state
  │       ├── activeContext.md  (current focus, active phase)
  │       ├── patterns.md
  │       └── progress.md
  ├── activeContext.md       (kept — backward-compat fallback)
  ├── patterns.md
  └── progress.md

Changes:
- cc10x_hooklib.py: add project_state_dir() and workflow_state_dir(wf_id) helpers
- cc10x_pretooluse_guard.py: expand write guard to cover all three tiers dynamically
- cc10x_context_migration.py: add flat→project promotion on first SessionStart;
  add project/workflows to source-discovery skip-list
- cc10x-router/SKILL.md: update §2 (two-tier memory load), §6 (wf state dir init),
  §13 (split memory finalization with write routing table)
- session-memory/SKILL.md: update memory surfaces, load order, load-bearing boundaries

Backward compatibility:
- Root-flat files are preserved (copy, not move) as fallback
- Existing workflow artifact schema unchanged; state_root still points at .cc10x/v10/
- Heading contract identical across all three tiers
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.

2 participants