-
Notifications
You must be signed in to change notification settings - Fork 30
[Cleanup] Extract duplicated message-merge logic in syncFromGateway #228
Copy link
Copy link
Open
Labels
area/coreTask & Session Core WGTask & Session Core WGgood first issueGood for newcomersGood for newcomerskind/cleanupCategorizes issue or PR as related to code cleanupCategorizes issue or PR as related to code cleanup
Description
What problem are you trying to solve?
syncFromGateway in session-sync has two branches (hasLocalData / !hasLocalData) that contain nearly identical message mapping and persistence logic (~50 lines of copy-paste). This makes the function harder to maintain — a fix applied to one branch can easily be missed in the other.
Where
packages/core/src/services/session-sync.ts — the syncFromGateway function, around lines 280-330.
What needs to be done
- Open
packages/core/src/services/session-sync.ts - Find the
syncFromGatewayfunction - Identify the duplicated pattern between the
hasLocalDataand!hasLocalDatabranches — both do:- Map
collapsedMessagesintoMessage[]with sessionKey/agentId assignment - Call
messageStore.bulkLoad(taskId, mapped) - Persist each message via
deps.persistence.persistMessage()
- Map
- Extract the common logic into a local helper function (e.g.
loadAndPersistMessages) - Call the helper from both branches, passing only the differing parameters
- Run
pnpm checkto verify nothing breaks
Why does this matter?
Duplicated logic is a maintenance hazard — when one branch gets updated, the other often gets forgotten. This is a straightforward extract-function refactor.
Primary area
Task execution
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
area/coreTask & Session Core WGTask & Session Core WGgood first issueGood for newcomersGood for newcomerskind/cleanupCategorizes issue or PR as related to code cleanupCategorizes issue or PR as related to code cleanup