Skip to content

bug: parallel agent execution overwrites existing test files (3,743 lines lost) #334

@gandalf-at-lerian

Description

@gandalf-at-lerian

Problem

During ring:dev-cycle execution (Gates 0 RED-GREEN for sort mappers), 3 backend-engineer-golang agents running in parallel overwrote existing test files, deleting 3,743 lines of pre-existing tests unrelated to the migration.

Root Cause

Gate 0 (Implementation) dispatches agents per execution unit. When multiple tasks run in parallel and touch test files in the same package, each agent uses Write/Create which overwrites the entire file. There is no file locking, merge strategy, or baseline snapshot.

Invariant (from @Garzão)

Tests may ONLY be removed if the code being tested was removed. In all other scenarios, tests MUST be preserved — only modified to reflect changes in the code under test.

This invariant is not currently enforced anywhere in the dev-cycle or agent prompts.

Proposed Fix (3 layers)

Layer 1: Agent-level protection (minimal fix)

Add explicit instructions to backend-engineer-golang agent prompt:

  • NEVER delete or overwrite existing _test.go files entirely. Use Edit tool to modify specific test functions, never Write/Create on existing test files.
  • NEVER remove test functions unless the code under test was deleted in the same task.
  • When adding tests, create task-scoped test files (e.g., sort_mapper_migration_test.go) rather than modifying shared test files.
  • Before writing any test file, read the existing file first and preserve all existing test functions.

Layer 2: Pre/post-execution snapshot (defense in depth)

Before dispatching parallel agents in Gate 0, the orchestrator should:

  1. Snapshot all _test.go files in affected packages (git stash or file copy)
  2. After all agents complete, diff against baseline
  3. If any test file lost lines vs baseline → revert that file and re-dispatch the offending agent sequentially

Layer 3: Parallel execution conflict detection

During Step 1 (initialization), the orchestrator should:

  1. Analyze which files each task/subtask will likely touch (based on requirements + codebase structure)
  2. If multiple tasks target the same package → force sequential execution for those tasks
  3. Allow parallel execution only for tasks with non-overlapping file scopes

Affected Components

  • dev-team/skills/dev-cycle/SKILL.md — orchestrator needs snapshot + conflict detection
  • dev-team/agents/backend-engineer-golang.md — agent needs test preservation rules
  • dev-team/skills/dev-implementation/SKILL.md — skill dispatching agents needs parallel safety
  • Potentially all backend-engineer-* agents (same pattern applies to TypeScript)

Priority

High — data loss (test deletion) undermines the entire quality gate system. The dev-cycle has 5 testing gates (3-7) that become meaningless if tests are silently deleted during implementation.

Reported by

@Carlao-LERIAN in #the-ring-feedbacks

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions