Repository navigation
feat(say): automatically merge compatible recent messages - #42
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4e21604e2d
ℹ️ 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".
| if (merged && (merged.images || []).length <= 20) { | ||
| const item = await this.update(latest.id, merged); | ||
| return {...item, autoMerged: true}; |
There was a problem hiding this comment.
Make automatic merges atomic to prevent lost publications
When two compatible publications arrive concurrently within the merge window, both can read the same latest entry and compute independent replacements; the second update() then overwrites the first publication's content. This also occurs within a single process, not just across instances: using the service test fixture, creating a caption followed by two image publications through Promise.all() reports both as successfully merged into #1, but persists only the second image. The API route and distinct QQ messages can invoke this path concurrently. Protect the read/merge/write operation with database concurrency control, retrying against the current entry or creating a separate entry on conflict, so acknowledged publications are not silently lost.
Useful? React with 👍 / 👎.
Add an admin-configurable automatic merge window (default 10 seconds, 0 disables, maximum 86400). The shared creation path checks the latest Say and applies existing merge rules, preserving its ID and original creation time. Publishing feedback reports the merged ID.
Require matching author, source, visibility and comment settings. Skip commented entries, unsupported combinations and merges exceeding 20 images.
Automatic merges use a database conditional UPDATE against the original content and state snapshot. If another request changes that snapshot, publish the incoming message as a separate entry instead of overwriting the winning update. Do not rely solely on second-resolution timestamps or process-local locks.
Validation: Say suite 164 passed, 2 optional tests skipped; git diff --check passed. Regression tests cover simultaneous images through one service and independent service instances sharing storage, verifying that all acknowledged content remains stored. Other tests cover the merge window and eligibility guards. Tests use the model fixture; real database concurrency and production channel delivery have not been exercised.