Skip to content

fix: write back the CURRENT message text, not a copy taken before the… - #222

Merged
MagicalAstrogy merged 1 commit into
betafrom
mag/pick_async
Aug 31, 2026
Merged

fix: write back the CURRENT message text, not a copy taken before the…#222
MagicalAstrogy merged 1 commit into
betafrom
mag/pick_async

Conversation

@MagicalAstrogy

Copy link
Copy Markdown
Owner

see #221

… parse (回写当前消息文本,而非解析前的副本) (#221)

* fix: write back the current message text, not a copy taken before the parse

handleVariablesInMessage read chat_message.message into a local at the top
of the function and wrote that local back at the end, four awaits later.
setChatMessages has no append mode, so what reads as "append
<StatusPlaceHolderImpl/>" is a wholesale overwrite of mes and the active
swipe from a snapshot that can be seconds old. Any edit another extension
made to the message during those awaits is silently reverted; nothing
fails and nothing is logged.

The dominant part of the window is updateVariables(), which emits
VARIABLE_UPDATE_ENDED, and the emitter awaits every listener in turn.
Measured 2832 ms between snapshot and write on a live chat.

mag_before_message_update does not cover the case: it is emitted only when
has_variable_modified is true, while the write is gated on the role alone,
so a reply whose parse changed no variable is written back stale with no
event to hook.

Two changes:

- Re-read the message after updateVariables(), so everything below - the
  event seam included - works from the current text.
- Re-anchor once more at write time, and when the resulting text is
  identical to what is already there, call setChatMessages WITHOUT a
  `message` field. That drops the pointless overwrite while keeping the
  refresh: the variables were still replaced, and a status implementation
  that reads message_data at iframe init would otherwise keep showing the
  pre-update values.

The seam still fires under exactly the same condition and still receives a
mutable message_content; the placeholder is still appended once for
non-user messages; the <status_current_variable> strip is untouched.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* misc: 缩短 await 距离,完善 BEFORE_MESSAGE_UPDATE 保证。增加测试用例。

* misc: 调整review意见

* misc: add changelog

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
Co-authored-by: MagicalAstrogy <103271693+MagicalAstrogy@users.noreply.github.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Aug 31, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-08-31T02:35:03.990661Z 1af7c66 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

Copy link
Copy Markdown
Contributor

🔍 PR Test Report

🧪 Test Results

✅ All tests passed!

Type Passed Failed Total
Test Suites 31 0 31
Tests 725 0 778

📊 Coverage Report

Metric Coverage Details
Lines 67.74% 1544/2279
Statements 67.57% 1582/2341
Functions 72.12% 207/287
Branches 63.95% 740/1157

Coverage Thresholds

  • ✅ Lines: 67.74% (Passed, threshold: 50%)
  • ✅ Statements: 67.57% (Passed, threshold: 50%)
  • ✅ Functions: 72.12% (Passed, threshold: 50%)
  • ✅ Branches: 63.95% (Passed, threshold: 50%)

Generated at 2026-08-31T02:31:06.067Z

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1af7c66e7f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/function/update_variables.ts
Comment thread src/function/update_variables.ts
@MagicalAstrogy

Copy link
Copy Markdown
Owner Author

LGFM

@MagicalAstrogy
MagicalAstrogy merged commit 7fe9ae7 into beta Aug 31, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants