All blocks Review this — it's stuck in a recursion loop. session.ts (before)typescript AI session/refresh.ts (after)suggested
Block
Code review thread
A code review pattern: paste in code, the assistant returns a critique with markdown commentary and a side-by-side before/after.
Snippet → review with diff
function refreshSession(token: string) {
if (!token) throw new Error('no token');
const decoded = verifyToken(token);
if (decoded.expired) {
return refreshSession(decoded.refreshToken);
}
return decoded;
}The cycle is the recursive call — refreshSession calls itself with the refresh token, which goes back through verifyToken. Fix: decode without verifying, then exchange the refresh token via a separate code path.
// session/refresh.ts — extracted to break the cycle
function refreshSession(token: string) {
const decoded = decodeToken(token);
if (decoded.expired) {
return exchangeRefreshToken(decoded.refreshToken);
}
return decoded;
}<!-- User message: prose + the snippet inside one bubble -->
<pk-message class="justify-end">
<div class="flex flex-col gap-2 max-w-full min-w-0">
<pk-message-content
class="bg-primary text-primary-foreground"
content="Review this — it's stuck in a recursion loop."
/>
<pk-code-block>
<pk-code-block-group class="border-b px-3 py-1.5 text-[11px]">
<span class="font-mono">session.ts (before)</span>
<span class="uppercase tracking-wider">typescript</span>
</pk-code-block-group>
<pk-code-block-code [code]="before" language="ts" />
</pk-code-block>
</div>
</pk-message>
<!-- Assistant: markdown commentary + suggested fix -->
<pk-message>
<pk-message-avatar src="" alt="Assistant" fallback="AI" />
<div class="flex flex-1 flex-col gap-3">
<pk-message-content
[markdown]="true"
content="The cycle is the recursive call — **fix:** decode without verifying, then exchange via a separate code path."
/>
<pk-code-block>
<pk-code-block-group class="border-b px-3 py-1.5 text-[11px]">
<span class="font-mono">session/refresh.ts (after)</span>
<span class="text-primary uppercase">suggested</span>
</pk-code-block-group>
<pk-code-block-code [code]="after" language="ts" />
</pk-code-block>
</div>
</pk-message>