Skip to content

refactor(core): shared utility module — eliminate 6 families of duplicated functions #785

Closed

Description

@Sinity

Problem

6 families of functions are duplicated across the codebase with divergent behavior or copy-paste identity:

  1. _make_ref_id() — two implementations produce different IDs (16-char vs 32-char hex, with/without prefix)
  2. normalize_role() — canonical version in archive/message/roles.py maps "model"→"assistant"; surfaces copy in payloads.py just returns str()
  3. chunked() — character-for-character identical in 3 modules
  4. iter_conversation_id_pages — same name, different SQL in 2 modules
  5. _topo_sort_message_tuples vs topo_sort_messages — same algorithm on different types
  6. replace_action_events — triplicated across 3 modules

Proposed fix

Create polylogue/core/common.py or similar shared module. Move canonical implementations there. Delete all copies. For functions that differ only in data type, make them generic.

Acceptance criteria

  • _make_ref_id() produces consistent IDs everywhere
  • normalize_role() normalized everywhere (delete surfaces copy)
  • chunked() has one implementation
  • No duplicated function families remain

Ref: deep audit R4, P3-2.

Activity

  1. Sinity commented on May 3, 2026

    @Sinity
    OwnerAuthor

    Consolidated into #784 (single-source definitions). Duplicated function elimination is part of the same architectural fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions