René's URL Explorer Experiment


Title: BUG:sometime new message and old message all in same id · Issue #205 · coder/agentapi · GitHub

Open Graph Title: BUG:sometime new message and old message all in same id · Issue #205 · coder/agentapi

X Title: BUG:sometime new message and old message all in same id · Issue #205 · coder/agentapi

Description: An occasional bug in the agentapi caused old message history and new user messages to be mixed together in the same SSE message body. data: {"id":68,"role":"agent","message":"old + new"} Note! The "old + new" above "old" refers to a very...

Open Graph Description: An occasional bug in the agentapi caused old message history and new user messages to be mixed together in the same SSE message body. data: {"id":68,"role":"agent","message":"old + new"} Note! The ...

X Description: An occasional bug in the agentapi caused old message history and new user messages to be mixed together in the same SSE message body. data: {"id":68,"role":"agent",&qu...

Opengraph URL: https://github.com/coder/agentapi/issues/205

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"BUG:sometime new message and old message all in same id","articleBody":"\nAn occasional bug in the agentapi caused old message history and new user messages to be mixed together in the same SSE message body.\n\ndata: {\"id\":68,\"role\":\"agent\",\"message\":\"old + new\"}\n\nNote!\n\nThe \"old + new\" above\n\n\"old\" refers to a very, very large collection of historical messages, not a streaming update of the screen.\n\n\n\n![Image](https://github.com/user-attachments/assets/cacb5a86-3018-48ad-8cd8-c9c7fc99dbc9)\n\nBug 1: A \"ghost update\" at the start of sendMessage\n\n  Before appending the user message, sendMessage calls updateLastAgentMessageLocked once:\n\n  // pty_conversation.go:386-391\n  c.lock.Lock()\n  screenBeforeMessage := c.cfg.AgentIO.ReadScreen()\n  now := c.cfg.Clock.Now()\n  c.updateLastAgentMessageLocked(screenBeforeMessage, now)  // ← user msg NOT yet appended\n  c.writingMessage = true\n  c.lock.Unlock()\n\n  At this point c.messages still ends with the agent message (id=68), so:\n\n  // line 324\n  shouldCreateNewMessage := len(c.messages) == 0 ||\n      c.messages[len(c.messages)-1].Role == ConversationRoleUser\n  // = false  ← overwrites existing slot instead of creating a new one\n\n  Any content change here writes into messages[68] — no new ID is created.\n\n  ---\n  Bug 2: screenDiff set-based matching bleeds historical content in\n\n  // diff.go:32-38\n  firstNonMatchingLine := len(newLines)\n  for i, line := range newLines[dynamicHeaderEnd+1:] {\n      if !oldLinesMap[line] {      // ← set lookup by line content\n          firstNonMatchingLine = i\n          break\n      }\n  }\n  newSectionLines := newLines[firstNonMatchingLine:]  // ← takes EVERYTHING from that line onward\n\n  oldLinesMap is a content-based set of old screen lines (unordered). The algorithm finds the first line not in that set, then takes all subsequent lines — including any historical content that reappears later on screen.\n\n  When the terminal accumulates output without clearing, the new screen looks like:\n\n  [historical response lines]   ← some line here is NOT in oldLinesMap\n  [new user input echo]\n  [new agent response lines]\n\n  So screenDiff returns \"historical_content\\nnew_content\" as a single blob.\n\n  ---\n  How the two bugs combine\n\n  ┌─────────────────────────────────────────────────────────────┬──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┬─────────────────────────────────────────────┐\n  │                            Step                             │                                                        State                                                         │                   Effect                    │\n  ├─────────────────────────────────────────────────────────────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼─────────────────────────────────────────────┤\n  │ sendMessage starts, calls updateLastAgentMessageLocked      │ writingMessage=false, last message is agent (id=68), shouldCreateNewMessage=false                                    │ Any content difference overwrites id=68     │\n  ├─────────────────────────────────────────────────────────────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼─────────────────────────────────────────────┤\n  │ screenDiff(screenBeforeLastUserMessage, currentScreen) runs │ New screen contains old response lines + new response lines; set-match finds a boundary in the middle of old content │ Returns \"historical + new content\"          │\n  ├─────────────────────────────────────────────────────────────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼─────────────────────────────────────────────┤\n  │ Write path                                                  │ shouldCreateNewMessage=false → takes else branch: messages[last] = conversationMessage                               │ id=68 now contains both old and new content │\n  └─────────────────────────────────────────────────────────────┴──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┴─────────────────────────────────────────────┘\n\n  Only after this does the user message get appended (id=69), and the snapshot loop eventually creates a proper new agent message (id=70). But id=68 has already been corrupted and emitted via SSE.\n\n  ---\n  Fix directions\n\n  Fix 1 — Remove the redundant updateLastAgentMessageLocked call at the start of sendMessage. The screen is stable at this point (that's why stableSignal fired), so this call produces no useful work:\n\n  // In sendMessage, remove this line from the first lock block:\n  - c.updateLastAgentMessageLocked(screenBeforeMessage, now)\n\n  Fix 2 — Replace the set-based screenDiff with a positional diff. Instead of \"find the first line whose content isn't in a set\", compare line-by-line from the end of the old screen forward, so historical content that reappears mid-screen doesn't shift\n  the boundary:\n\n  // Current (buggy): content-set lookup\n  if !oldLinesMap[line] { firstNonMatchingLine = i; break }\n\n  // Better: compare the tail of newLines against the tail of oldLines positionally,\n  // or use a suffix/LCS approach so repeated content doesn't cause false boundaries.","author":{"url":"https://github.com/mrchanglinux-spec","@type":"Person","name":"mrchanglinux-spec"},"datePublished":"2026-03-20T16:10:25.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/205/agentapi/issues/205"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:001cd80d-d5f2-30e2-3f09-6e2ef2861bfa
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idB23E:297ED:63396E:8FFCD6:6A4E0C3C
html-safe-noncef6e169e27e7a47e639bb11ee7df76730828a4403d693bc6a8ebc2a25f9e3f13c
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMjNFOjI5N0VEOjYzMzk2RTo4RkZDRDY6NkE0RTBDM0MiLCJ2aXNpdG9yX2lkIjoiNTIxMTkzNDkwODQ0NDcwNzkwMCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmacc35d0a6209b5ab3710165c6ee3dfc651479279c5c959fc71c64110c5c3472d07
hovercard-subject-tagissue:4108743790
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/coder/agentapi/205/issue_layout
twitter:imagehttps://opengraph.githubassets.com/fb058b54968cbdb32626a736e4f93c8acfd86521da71ca555213a56c7d88221f/coder/agentapi/issues/205
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/fb058b54968cbdb32626a736e4f93c8acfd86521da71ca555213a56c7d88221f/coder/agentapi/issues/205
og:image:altAn occasional bug in the agentapi caused old message history and new user messages to be mixed together in the same SSE message body. data: {"id":68,"role":"agent","message":"old + new"} Note! The ...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamemrchanglinux-spec
hostnamegithub.com
expected-hostnamegithub.com
Nonedf0492960db29b4938cb72070351d6b1d0c6c0767b27ceb8394bbf4fcc0223c6
turbo-cache-controlno-preview
go-importgithub.com/coder/agentapi git https://github.com/coder/agentapi.git
octolytics-dimension-user_id95932066
octolytics-dimension-user_logincoder
octolytics-dimension-repository_id961832048
octolytics-dimension-repository_nwocoder/agentapi
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id961832048
octolytics-dimension-repository_network_root_nwocoder/agentapi
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release51470c353b8a1f52a88d3e3cc2014b17ab8cc1ce
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/coder/agentapi/issues/205#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fcoder%2Fagentapi%2Fissues%2F205
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
GitHub Starshttps://stars.github.com
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fcoder%2Fagentapi%2Fissues%2F205
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=coder%2Fagentapi
Reloadhttps://github.com/coder/agentapi/issues/205
Reloadhttps://github.com/coder/agentapi/issues/205
Reloadhttps://github.com/coder/agentapi/issues/205
Please reload this pagehttps://github.com/coder/agentapi/issues/205
coder https://github.com/coder
agentapihttps://github.com/coder/agentapi
Notifications https://github.com/login?return_to=%2Fcoder%2Fagentapi
Fork 130 https://github.com/login?return_to=%2Fcoder%2Fagentapi
Star 1.4k https://github.com/login?return_to=%2Fcoder%2Fagentapi
Code https://github.com/coder/agentapi
Issues 36 https://github.com/coder/agentapi/issues
Pull requests 4 https://github.com/coder/agentapi/pulls
Actions https://github.com/coder/agentapi/actions
Projects https://github.com/coder/agentapi/projects
Security and quality 1 https://github.com/coder/agentapi/security
Insights https://github.com/coder/agentapi/pulse
Code https://github.com/coder/agentapi
Issues https://github.com/coder/agentapi/issues
Pull requests https://github.com/coder/agentapi/pulls
Actions https://github.com/coder/agentapi/actions
Projects https://github.com/coder/agentapi/projects
Security and quality https://github.com/coder/agentapi/security
Insights https://github.com/coder/agentapi/pulse
BUG:sometime new message and old message all in same idhttps://github.com/coder/agentapi/issues/205#top
https://github.com/mrchanglinux-spec
mrchanglinux-spechttps://github.com/mrchanglinux-spec
on Mar 20, 2026https://github.com/coder/agentapi/issues/205#issue-4108743790
https://private-user-images.githubusercontent.com/269765762/566943852-cacb5a86-3018-48ad-8cd8-c9c7fc99dbc9.jpeg?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3ODM1MDAxMzYsIm5iZiI6MTc4MzQ5OTgzNiwicGF0aCI6Ii8yNjk3NjU3NjIvNTY2OTQzODUyLWNhY2I1YTg2LTMwMTgtNDhhZC04Y2Q4LWM5YzdmYzk5ZGJjOS5qcGVnP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI2MDcwOCUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNjA3MDhUMDgzNzE2WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9M2NjMDU3MzI1NjdmMTIxYjgxYjA1YThkMDYwYzgzOTM5Yjg2Yjk2MDcxZjU5MjNkNzVmNTcyNzk3ODQ3NDhiYiZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmcmVzcG9uc2UtY29udGVudC10eXBlPWltYWdlJTJGanBlZyJ9.nxE89_alxivBQttxYOQrzlB1rEcUlxLyqMHEMSLOzsE
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.