---
title: "Discussion on \"The Agent Converted the If/Else Chain to a Lookup Map and Dropped the Side Effect\" | Hashnode"
description: "Discussion on \"The Agent Converted the If/Else Chain to a Lookup Map and Dropped the Side Effect\". An agent converts an if/else chain to a lookup map for cleanliness. TypeScript is green, tests pass, but one branch's logging and metrics call quietly disappears."
url: "https://hashnode.com/posts/agent-if-chain-to-lookup-map-drops-side-effect/6ad2c08c020cc1cf77f5e713"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [The Agent Converted the If/Else Chain to a Lookup Map and Dropped the Side Effect](https://blogs.powerduck.com/agent-if-chain-to-lookup-map-drops-side-effect?utm_source=hashnode&utm_medium=feed)

An agent converts an if/else chain to a lookup map for cleanliness. TypeScript is green, tests pass, but one branch's logging and metrics call quietly disappears.

Oct 17 · 3 min read · blogs.powerduck.com  
Read the article

-   [#aiagents](https://hashnode.com/tag/aiagents)
-   [#refactoring](https://hashnode.com/tag/refactoring)
-   [#coding](https://hashnode.com/tag/coding)
-   [#javascript](https://hashnode.com/tag/javascript)

## Written by

[Powerduck](https://hashnode.com/@powerduck)

@powerduck · hon

  
[View profile](https://hashnode.com/@powerduck)

## Responses 2

Markdown supported · ⌘↵ to post

[YouBeyond](https://hashnode.com/@youbeyondai)

[Oct 17](https://hashnode.com/posts/agent-if-chain-to-lookup-map-drops-side-effect/6ad2c08c020cc1cf77f5e713/comment/6ad3204e08c7fa5720dfdd20)

There is another behavior change in this example: the original function returns a fresh object, while the lookup returns a shared object. If a caller mutates title or cta, later calls can inherit it. Would you add a test that changes one returned result and verifies the next call is unchanged, alongside the telemetry assertions? (AI-assisted comment.)

[StackShortlist](https://hashnode.com/@veristria)

[Oct 17](https://hashnode.com/posts/agent-if-chain-to-lookup-map-drops-side-effect/6ad2c08c020cc1cf77f5e713/comment/6ad2d089dfddf791b1e9bd4f)

The trial\_expired\_viewed metric going flat for two weeks is a sharp example, since nothing in TypeScript or the three existing tests could flag a missing logger call. Asking the agent to list every side effect per branch before it touches the shape seems like a cheap guard. A test that asserts the metric increments for that one status would have caught it on the first run.
