Skip to content

Commit 3997027

Browse files
VJ-yadavclaude
andcommitted
fix: address second round of CodeRabbit findings
- Add 30s timeout to gitlabApi fetch via AbortController to prevent indefinite hangs on network stalls - Paginate MR notes (loop pages of 100) so dedup marker detection works on active MRs with >100 notes - Fix ternary precedence in tool title rendering — part.state.title was being ignored due to || binding with the ternary condition Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
1 parent b9e83dd commit 3997027

1 file changed

Lines changed: 19 additions & 9 deletions

File tree

‎packages/opencode/src/cli/cmd/gitlab.ts‎

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,14 @@ async function gitlabApi<T>(
105105
"Content-Type": "application/json",
106106
}
107107

108+
const controller = new AbortController()
109+
const timeout = setTimeout(() => controller.abort(), 30_000)
108110
const res = await fetch(url, {
109111
method: options.method ?? "GET",
110112
headers,
113+
signal: controller.signal,
111114
...(options.body ? { body: JSON.stringify(options.body) } : {}),
112-
})
115+
}).finally(() => clearTimeout(timeout))
113116

114117
if (!res.ok) {
115118
if (res.status === 401) {
@@ -159,11 +162,19 @@ async function fetchMRNotes(
159162
mrIid: number,
160163
token: string,
161164
): Promise<GitLabNote[]> {
162-
return gitlabApi<GitLabNote[]>(
163-
instanceUrl,
164-
`/projects/${projectId}/merge_requests/${mrIid}/notes?sort=asc&per_page=100`,
165-
token,
166-
)
165+
const all: GitLabNote[] = []
166+
let page = 1
167+
while (true) {
168+
const batch = await gitlabApi<GitLabNote[]>(
169+
instanceUrl,
170+
`/projects/${projectId}/merge_requests/${mrIid}/notes?sort=asc&per_page=100&page=${page}`,
171+
token,
172+
)
173+
all.push(...batch)
174+
if (batch.length < 100) break
175+
page += 1
176+
}
177+
return all
167178
}
168179

169180
async function postMRNote(
@@ -458,9 +469,8 @@ function subscribeSessionEvents(session: { id: SessionID; title: string; version
458469
if (part.type === "tool" && part.state.status === "completed") {
459470
const [tool, color] = TOOL[part.tool] ?? [part.tool, UI.Style.TEXT_INFO_BOLD]
460471
const title =
461-
part.state.title || Object.keys(part.state.input).length > 0
462-
? JSON.stringify(part.state.input)
463-
: "Unknown"
472+
part.state.title ||
473+
(Object.keys(part.state.input).length > 0 ? JSON.stringify(part.state.input) : "Unknown")
464474
console.log()
465475
printEvent(color, tool, title)
466476
}

0 commit comments

Comments
 (0)