microsoft / microsoft/FluidFramework

Duplicate Code Detected: Protocol type definitions duplicated across protocol-definitions and driver-definitions

Open
#26,518 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
4.9k
Forks
586
Avg merge
1d 15h
Merged PRs (30d)
146

Description

🔍 Duplicate Code Detected: Protocol type definitions duplicated across protocol-definitions and driver-definitions

Analysis of commit 456709ace7f54858b3f94e8487eba71a5421ac32

Assignee: @copilot

Summary

Multiple protocol-type definition files appear to be copied verbatim between common/lib/protocol-definitions and packages/common/driver-definitions, creating a high risk of divergence and duplicated maintenance effort.

Duplication Details

Pattern: Identical exported protocol interfaces/types in two packages
  • Severity: High

  • Occurrences: 6 identical files (verbatim) + 6 additional overlapping files with strong similarity but non-identical content.

  • Locations (verbatim duplicates):

    • common/lib/protocol-definitions/src/clients.ts (lines 1-152)
    • packages/common/driver-definitions/src/protocol/clients.ts (lines 1-152)
    • common/lib/protocol-definitions/src/config.ts (lines 1-38)
    • packages/common/driver-definitions/src/protocol/config.ts (lines 1-38)
    • common/lib/protocol-definitions/src/sockets.ts (lines 1-178)
    • packages/common/driver-definitions/src/protocol/sockets.ts (lines 1-178)
    • common/lib/protocol-definitions/src/date.ts (lines 1-55)
    • packages/common/driver-definitions/src/protocol/date.ts (lines 1-55)
    • common/lib/protocol-definitions/src/scopes.ts (lines 1-32)
    • packages/common/driver-definitions/src/protocol/scopes.ts (lines 1-32)
    • common/lib/protocol-definitions/src/users.ts (lines 1-15)
    • packages/common/driver-definitions/src/protocol/users.ts (lines 1-15)
  • Overlapping but non-identical (likely drift risk / partial copy):

    • consensus.ts, index.ts, protocol.ts, storage.ts, summary.ts, tokens.ts in both directories.
  • Code Sample (excerpt from clients.ts, identical in both locations):

export type ConnectionMode = "write" | "read";

export interface ICapabilities {
	interactive: boolean;
}

export interface IClientDetails {
	capabilities: ICapabilities;
	type?: string;
	environment?: string;
	device?: string;
}

export interface IClient {
	mode: ConnectionMode;
	details: IClientDetails;
	permission: string[];
	user: IUser;
	scopes: string[];
	timestamp?: number;
}

Impact Analysis

  • Maintainability: Changes to protocol shapes must be duplicated and kept consistent across two packages; this is easy to miss during refactors.
  • Bug Risk: High risk of subtle type mismatches when one copy changes and the other does not (especially for non-identical-but-overlapping files like protocol.ts / tokens.ts).
  • Code Bloat: Multiple files duplicated across packages, increasing review surface and build artifacts.

Refactoring Recommendations

  1. Single source of truth via dependency/re-export

    • Make @fluidframework/driver-definitions depend on @fluidframework/protocol-definitions (or the reverse, whichever layering constraints allow), and re-export the shared types from one package.
    • Estimated effort: Medium
    • Benefits: Eliminates drift risk and reduces maintenance overhead.
  2. Generate one copy from the other (build step)

    • If layering constraints prevent direct dependency, consider generating the second set from the first during build (and fail CI if the generated output is modified).
    • Estimated effort: Medium/High
    • Benefits: Maintains separation while ensuring consistency.
  3. Enforce synchronization with a policy check

    • Add/extend an existing policy check to ensure the overlapping directory trees remain identical where intended.
    • Estimated effort: Low/Medium
    • Benefits: Prevents future divergence even if duplication remains temporarily.

Implementation Checklist

  • Confirm whether duplication is intentional for packaging/layering reasons
  • Decide ownership for the canonical protocol type definitions
  • Implement re-export or codegen strategy
  • Update any downstream imports
  • Ensure API docs / type tests still pass

Analysis Metadata

  • Analyzed Files: HEAD diff scan for .ts/.cjs/.mjs (non-test, non-workflow) + file-level comparison
  • Detection Method: Serena semantic overview + diff-based duplicate block detection
  • Commit: 456709ace7f54858b3f94e8487eba71a5421ac32
  • Analysis Date: 2026-02-23

AI generated by Duplicate Code Detector

To add this workflow in your repository, run gh aw add github/gh-aw/.github/workflows/duplicate-code-detector.md@94662b1dee8ce96c876ba9f33b3ab8be32de82a4. See usage guide.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by comparing the six listed duplicate file pairs under common/lib/protocol-definitions and packages/common/driver-definitions/src/protocol, then inspect the overlapping consensus.ts, index.ts, protocol.ts, storage.ts, summary.ts, and tokens.ts files. Confirm the intended package layering and canonical ownership before choosing a re-export, generation, or synchronization approach; done means downstream imports and API documentation/type tests still pass without unmanaged duplication.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
backend-api-design
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.