Skip to content

Refactor (packages/app/src/context/server-session-v2-reducer.ts): Function with many parameters - #189

Open
zrusekko-cmu wants to merge 3 commits into
CMU-313:mainfrom
zrusekko-cmu:refactor/update-content-parameters
Open

Refactor (packages/app/src/context/server-session-v2-reducer.ts): Function with many parameters#189
zrusekko-cmu wants to merge 3 commits into
CMU-313:mainfrom
zrusekko-cmu:refactor/update-content-parameters

Conversation

@zrusekko-cmu

@zrusekko-cmu zrusekko-cmu commented Sep 8, 2026

Copy link
Copy Markdown

P1B: Starter Task: Refactoring PR

1. Issue

Link to the associated GitHub issue:
#139

Full path to the refactored file:
packages/app/src/context/server-session-v2-reducer.ts

What do you think this file does?
(Your answer does not have to be 100% correct; give a reasonable, evidence‑based guess.)
From my understanding, the purpose of the file server-session-v2-reducer.ts is that it is used to keep track of a session's message history as new events come in. The file processes events like text, reasoning, and tool calls and updates the conversation state accordingly.

What is the scope of your refactoring within that file?
(Name specific functions/blocks/regions touched.)
The scope of my refactoring within the file server-session-v2-reducer.ts is that I refactored the updateContent helper function to group its four targeting parameters (messageID, sessionID, type, and ordinal) into a single target object parameter. The updateContent helper function is used by the session.text.delta, session.text.ended, session.reasoning.delta, and session.reasoning.ended cases in createV2SessionReducer, so I updated those four call sites to use the refactored parameter structure as well.

Which Qlty‑reported issue did you address?
(Name the rule/metric and include the BEFORE value; e.g., “Cognitive Complexity 18 in render()”.)
The Qlty-reported issue that I addressed was: Function with many parameters (count = 6) for updateContent at line 463. Specifically:

packages/app/src/context/server-session-v2-reducer.ts
 463  Function with many parameters (count = 6): updateContent

2. Refactoring

How did the specific issue you chose impact the codebase’s maintainability?
The updateContent helper function accepted six parameters, making function calls harder to read and making the function interface more cumbersome to understand and maintain.

What changes did you make to resolve the issue?
To resolve this issue, I introduced an UpdateContentTarget<T> interface bundling messageID, sessionID, type, and ordinal, changed updateContent to accept three parameters: (source, target, apply), instead of six separate arguments, updated all four call sites in createV2SessionReducer to pass a target object with the relevant fields.

How do your changes improve maintainability? Did you consider alternatives?
My changes improved maintainability because grouping the related targeting information into one object makes the function signature clearer and makes call sites easier to read and extend. I considered splitting updateContent into separate functions for text content and reasoning content, but chose the target object because it keeps the shared logic in one place while directly addressing the parameter count issue.

3. Validation

How did you validate that the change is correct?
To validate that the change is correct, I ran the existing test suite and added new tests covering the reasoning branch, ordinal-targeting among multiple same-type content blocks, and mixed-type isolation (to confirm the bundled target fields are still threaded through correctly), then confirmed bun lint and bun test pass and re-ran Qlty to confirm the smell is resolved.

Screenshot of running bun lint on changed files:
Screenshot 2026-09-07 at 11 26 36 PM

Attach a screenshot of the test coverage showing the lines were executed by the tests.

Before changes:
Screenshot 2026-09-07 at 11 20 44 PM

After changes:
Screenshot 2026-09-07 at 11 21 29 PM

Attach a screenshot showing the tests that cover the change passing during CI

CI Workflow from Commit:
Screenshot 2026-09-07 at 11 00 35 PM

CI Workflow Run History:
Screenshot 2026-09-07 at 11 02 21 PM

Attach a screenshot of qlty smells --no-snippets <full/path/to/file.ts> showing fewer reported issues after the changes.

Before changes:
Screenshot 2026-09-07 at 11 09 10 PM

After changes:
Screenshot 2026-09-07 at 11 09 46 PM

@zrusekko-cmu zrusekko-cmu changed the title Refactor/update content parameters Refactor (packages/app/src/context/server-session-v2-reducer.ts:463): Function with many parameters Sep 8, 2026
@zrusekko-cmu zrusekko-cmu changed the title Refactor (packages/app/src/context/server-session-v2-reducer.ts:463): Function with many parameters Refactor (packages/app/src/context/server-session-v2-reducer.ts): Function with many parameters Sep 8, 2026
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.

1 participant