Skip to content

fix(coderd/taskname): parse task name JSON with trailing text#25005

Merged
johnstcn merged 2 commits into
coder:mainfrom
maschwenk:maschwenk/fix-image-ui
May 7, 2026
Merged

fix(coderd/taskname): parse task name JSON with trailing text#25005
johnstcn merged 2 commits into
coder:mainfrom
maschwenk:maschwenk/fix-image-ui

Conversation

@maschwenk
Copy link
Copy Markdown
Contributor

Anthropic task name responses can include valid JSON followed by a closing fence or extra text, which made json.Unmarshal fail with trailing-character errors and forced fallback naming.

This updates task name JSON extraction to accept the first JSON value after optional fences and adds regression coverage for fenced and bare JSON with trailing content.

@github-actions github-actions Bot added the community Pull Requests and issues created by the community. label May 6, 2026
@maschwenk maschwenk marked this pull request as ready for review May 6, 2026 17:30
Copy link
Copy Markdown
Member

@johnstcn johnstcn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice find!

Comment thread coderd/taskname/taskname.go Outdated
Comment on lines 106 to 116
// Only strip when there is a newline separating the fence line
// from the body. Without one we cannot reliably tell the fence
// from the content.
if idx := strings.Index(s, "\n"); idx != -1 {
s = s[idx+1:]
s = strings.TrimSuffix(s, "```")
if fenceIdx := strings.Index(s, "\n```"); fenceIdx != -1 {
s = s[:fenceIdx]
} else {
s = strings.TrimSuffix(s, "```")
}
s = strings.TrimSpace(s)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this one of the rare situations where a regex would be conceptually simpler? :)

@johnstcn
Copy link
Copy Markdown
Member

johnstcn commented May 7, 2026

Smoke-tested on dogfood ✅

@johnstcn johnstcn merged commit 87d580d into coder:main May 7, 2026
26 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators May 7, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

community Pull Requests and issues created by the community.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants