fix(discord): chunk long editMessage payloads and guard progress null race

- editMessage now splits >2000-char text: edits the tracked message with the
  first chunk and appends the rest as follow-up messages, instead of throwing
  Discord "Invalid Form Body … Must be 2000 or fewer" when promoting a long
  owner result over a progress message.
- syncTrackedProgressMessage captures latestProgressText in a local before the
  editMessage await, fixing a race where a concurrent resetProgressState()
  nulled it and crashed with "null is not an object (this.latestProgressText.length)".
- Add editMessage regression tests (in-place edit vs. chunked overflow).

Co-Authored-By: Claude Opus 4 <noreply@anthropic.com>
This commit is contained in:
Codex
2026-06-03 22:10:26 +09:00
parent f28399021a
commit c001905678
3 changed files with 75 additions and 4 deletions

View File

@@ -596,15 +596,19 @@ export class MessageTurnController {
return;
}
// Capture the value before the await: a concurrent resetProgressState()
// can null `latestProgressText` while editMessage is in flight, which used
// to throw "null is not an object (evaluating 'this.latestProgressText.length')".
const progressText = this.latestProgressText;
if (
!this.progressMessageId ||
!this.options.channel.editMessage ||
!this.latestProgressText
!progressText
) {
return;
}
const rendered = this.renderProgressMessage(this.latestProgressText);
const rendered = this.renderProgressMessage(progressText);
try {
await this.options.channel.editMessage(
@@ -616,7 +620,7 @@ export class MessageTurnController {
this.progressEditFailCount = 0;
this.logOutboundAudit('progress-edit', {
messageId: this.progressMessageId,
textLength: this.latestProgressText.length,
textLength: progressText.length,
renderedLength: rendered.length,
});
} catch (err) {