Skip to content

[backport] Backport sweep for 9.2 - #5619

Open
valkeyrie-ops[bot] wants to merge 36 commits into
9.2from
agent/backport/sweep/9.2
Open

valkeyrie-ops[bot] wants to merge 36 commits into
9.2from
agent/backport/sweep/9.2

Conversation

@valkeyrie-ops

@valkeyrie-ops valkeyrie-ops Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Backport sweep for 9.2

Automated cherry-picks from PRs marked "To be backported".

Applied

Source PR Title Detail
#4889 Allow EXEC without conditions from a database the user cannot access
#5090 Keep an IFEQ/IFNE value spelled GET when propagating SET GET
#4971 Skip pubsub channel defrag while a pending reply holds a reference
#5476 Fix RDB checker infinite loop on an RDB truncated inside a module value
#5079 Count delete misses and expired-key deletes in hotkey tracking
#5596 Limit the Lua debugger to the client that runs the session
#5143 Keep slot imports loaded during a swapdb full sync
#5684 Fix wrong maxlen value in the script debugger on 32-bit builds
#5660 Purge hot-key state only when a slot leaves this node's shard
#5556 Refuse to load a replicaof cycle from nodes.conf
#5584 Fix double free of the key iterator on AOF rewrite write error conflicts resolved by Claude Code
#5269 Validate cluster module message lengths before allocation
#5644 Prevent size_t underflow in used_memory_dataset calculation
#5471 Fix valkey-check-rdb --stats crash on keys before SELECTDB and huge DB IDs
#2933 Don't require node-id to be null terminated in VM_GetClusterNodeInfo
#5669 Keep reply blocks until the IO write completion is processed
#5682 Abort dual channel sync cleanly when main link write fails after $ENDOFF
#5369 Sanitize FUNCTION LIST error replies
#5690 Send tracking invalidation on SWAPDB
#5611 Propagate BITFIELD when OVERFLOW FAIL only creates or grows the key
#4941 Skip post-snapshot keys when expediting for MOVE and COPY in forkless BGSAVE conflicts resolved by Claude Code
#5617 Accept RDB_OPCODE_UPDATE in valkey-check-rdb
#4973 Fix AOF/slot-migration dropping deleted stream PEL entries
#4541 Reject module cross-slot BlockClientOnKeys in cluster mode
#5446 Don't let a retried election demote a primary others see as up
#5511 Fix integer precision loss in HINCRBY propagation
#5689 Read replica compression state only when the IO write is idle
#5713 Fix crash in VM_GetClientInfoById for a client without a connection
#5529 Fix killAppendOnlyChild reaping children other than the AOF rewrite child
#5106 Pin forkless save paths to the dir the save started in conflicts resolved by Claude Code
#5113 Wait synchronously when a write inside EXEC hits an unforeseen key
#5144 Don't finalize a full sync that was cancelled while loading from disk
#5655 Skip the pending channel reply defrag test in log-req-res mode

AI resolution details are posted as comments on this PR when available.

Skipped

These candidates were evaluated but contribute no change to this branch, e.g. the fix targets code that does not exist here. No backport commit was created for them.

Source PR Title Reason
#5705 Fix stale config name in forkless BGSAVE snapshot test The change does not apply to this branch: resolving the conflict matched the existing code, so the cherry-pick added nothing.

Needs attention

These candidates could not be applied automatically and need a maintainer to follow up.

1 candidate(s)
Source PR Title Outcome Reason
#5534 Fix slot export accepting a slot claim from a node other than the target error merge SHA 5804dbf does not match the aggregate patch of the source commits (6c11c7f..c570268). The pull request was either rebase-merged (its merge SHA is only the final rewritten commit) or the base branch advanced over the same lines before the merge. Backport it manually.

Generated by valkey-ci-agent using Claude Code.

@valkeyrie-ops valkeyrie-ops Bot added the backport Backport PR opened by valkey-ci-agent label Nov 26, 2026
@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 094c77c0-6850-4e40-9192-9cc59847de36

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@codecov

codecov Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 89.36170% with 40 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.76%. Comparing base (d1a5517) to head (bcb92c5).

Files with missing lines Patch % Lines
src/module.c 0.00% 21 Missing ⚠️
src/scripting_engine.c 55.55% 8 Missing ⚠️
src/rdb.c 37.50% 5 Missing ⚠️
src/cluster_legacy.c 94.28% 2 Missing ⚠️
src/forkless.c 66.66% 2 Missing ⚠️
src/defrag.c 85.71% 1 Missing ⚠️
src/valkey-check-rdb.c 95.45% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              9.2    #5619      +/-   ##
==========================================
+ Coverage   81.63%   81.76%   +0.13%     
==========================================
  Files         199      201       +2     
  Lines      105022   105326     +304     
==========================================
+ Hits        85736    86124     +388     
+ Misses      19286    19202      -84     
Files with missing lines Coverage Δ
src/acl.c 92.56% <100.00%> (+<0.01%) ⬆️
src/aof.c 82.25% <100.00%> (+1.54%) ⬆️
src/bgiteration.c 97.61% <100.00%> (+0.44%) ⬆️
src/bitops.c 96.22% <100.00%> (+<0.01%) ⬆️
src/cluster.c 93.08% <100.00%> (+<0.01%) ⬆️
src/cluster_migrateslots.c 93.47% <100.00%> (-0.01%) ⬇️
src/db.c 96.26% <100.00%> (+0.28%) ⬆️
src/functions.c 96.97% <100.00%> (ø)
src/networking.c 93.19% <100.00%> (+0.09%) ⬆️
src/object.c 92.28% <100.00%> (-0.19%) ⬇️
... and 17 more

... and 14 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

sarthakaggarwal97 added a commit to sarthakaggarwal97/valkey-ci-agent that referenced this pull request Dec 1, 2026
The agent's commits were made as valkeyrie-bot[bot], a name with no
GitHub account behind it, and most had no DCO sign-off. Its own fixes
and repair commits had none, and a backport kept only what its upstream
commit carried: sometimes nothing, sometimes a sign-off under another
email than its author's. The DCO check therefore fails on the sweep pull
requests (valkey-io/valkey#5619, valkey-io/valkey#5499), on the CI-sweep
pull requests (valkey-io/valkey#5441) and on the fixes opened into
unstable (valkey-io/valkey#5437, valkey-io/valkey#5440,
valkey-io/valkey#5443), and a maintainer has to override it.

Every commit the agent makes is now committed and signed off by
valkeyrie-ops[bot], the App that opens its pull requests. The identity
and the sign-off line are in scripts/common/identity.py, and
proc.set_commit_identity gives them to a clone.

- A commit the agent writes (a CI fix, a sweep's repair commit, a
  revert, a release cut) has the App as its author.
- A commit it cherry-picks (a backport, an upstream fix ported to a
  backport branch) keeps its author and its own sign-off, and gets the
  App's as its committer. The DCO check takes a sign-off from a
  commit's author or its committer.
- An open sweep branch from before this is signed off once, the next
  time it is rebased. Other open pull requests keep their commits.

The pull requests the CI-fix bot opens now say that their commit
carries the bot's sign-off and that a maintainer adds their own before
merging. Nothing checks for the maintainer's.

The registry edit that onboards a release branch is unchanged: it is
github-actions[bot]'s commit and is already signed off.

Signed-off-by: Sarthak Aggarwal <sarthagg@amazon.com>
sarthakaggarwal97 added a commit to valkey-io/valkey-ci-agent that referenced this pull request Dec 1, 2026
* Sign off every commit the agent makes as valkeyrie-ops

The agent's commits were made as valkeyrie-bot[bot], a name with no
GitHub account behind it, and most had no DCO sign-off. Its own fixes
and repair commits had none, and a backport kept only what its upstream
commit carried: sometimes nothing, sometimes a sign-off under another
email than its author's. The DCO check therefore fails on the sweep pull
requests (valkey-io/valkey#5619, valkey-io/valkey#5499), on the CI-sweep
pull requests (valkey-io/valkey#5441) and on the fixes opened into
unstable (valkey-io/valkey#5437, valkey-io/valkey#5440,
valkey-io/valkey#5443), and a maintainer has to override it.

Every commit the agent makes is now committed and signed off by
valkeyrie-ops[bot], the App that opens its pull requests. The identity
and the sign-off line are in scripts/common/identity.py, and
proc.set_commit_identity gives them to a clone.

- A commit the agent writes (a CI fix, a sweep's repair commit, a
  revert, a release cut) has the App as its author.
- A commit it cherry-picks (a backport, an upstream fix ported to a
  backport branch) keeps its author and its own sign-off, and gets the
  App's as its committer. The DCO check takes a sign-off from a
  commit's author or its committer.
- An open sweep branch from before this is signed off once, the next
  time it is rebased. Other open pull requests keep their commits.

The pull requests the CI-fix bot opens now say that their commit
carries the bot's sign-off and that a maintainer adds their own before
merging. Nothing checks for the maintainer's.

The registry edit that onboards a release branch is unchanged: it is
github-actions[bot]'s commit and is already signed off.

Signed-off-by: Sarthak Aggarwal <sarthagg@amazon.com>

* Pass the App's identity with each commit command

A sweep commits in the clone its validation builds and tests in, and
git took the committer, and the name `commit -s` signs with, from that
clone's config, set once after cloning. A test that rewrote the config
changed whose commit and sign-off the next one was.

Every git command that commits now gets the identity in its environment
(proc.commit_env), which git reads before any config, and a clone is no
longer given one. A cherry-pick, a rebase and an amend still keep the
commit's author.

A CI fix written before the sign-offs keeps its unsigned commit when its
CI-sweep branch is rebuilt. The docs now say so.

Signed-off-by: Sarthak Aggarwal <sarthagg@amazon.com>

---------

Signed-off-by: Sarthak Aggarwal <sarthagg@amazon.com>
@valkeyrie-ops

valkeyrie-ops Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

Automatic follow-up on this backport's CI.

No fix for test-fedoralatest-tls-module-no-tls (run). No change is justified. Every step inside a defrag cycle and everything the event loop ran between cycles is bounded well below 5 ms, so the single 7 ms cycle needs the server process to have been stalled for about 5 ms or more. The log cannot show whether that stall fell before the cycle or inside it, and the only test change that would pass is the looser wall-clock limit already rejected. My earlier edit to validate_latency is reverted.

@valkeyrie-ops

valkeyrie-ops Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor Author

Automatic follow-up on this backport's CI.

#5684 fixes test-ubuntu-32bit (run). Backport it to 9.2.

It also fixes test-alpine-32bit.

@valkeyrie-ops

valkeyrie-ops Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

Automatic follow-up on this backport's CI.

No fix for test-fedoralatest-tls-module (run). No change is made. The log holds one 9 ms active-defrag-cycle sample and nothing that shows where the time went, so neither a test change nor a product change can be justified from it. I removed the test edits from the rejected attempt.

@valkeyrie-ops

valkeyrie-ops Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

Automatic follow-up on this backport's CI.

A fix for reply-schemas-validator (run) could not be run here, so it was not pushed.

Proposed patch
diff --git a/tests/unit/memefficiency.tcl b/tests/unit/memefficiency.tcl
index dea3b0330..d32195ce3 100644
--- a/tests/unit/memefficiency.tcl
+++ b/tests/unit/memefficiency.tcl
@@ -714,7 +714,7 @@ run_solo {defrag} {
             assert_equal [list unsubscribe $chan 0] [$listener read]
             assert_equal [list $chan 0] [r pubsub numsub $chan]
             $listener close
-        }
+        } {0} {logreqres:skip} ;# copy avoidance encodes the reply buffers, which breaks req-res logging
     }
 
     proc test_tracking_table {type} {

@valkeyrie-ops

valkeyrie-ops Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

Automatic follow-up on the scheduled test run of 9.2, the branch this pull request is into.

No fix for test-ubuntu-lttng (run). No candidate passed its test and review in 3 rounds. Last: A reviewer rejected the patch: The diagnosis matches the log and code as far as it goes: one active-defrag-cycle sample of 6 ms in a 115 ms defrag at cpu=56%, and computeDefragCycleUs does lengthen a cycle in proportion to the wait with no cap. But nothing in the log shows a late timer or a stall, so the mechanism is a hypothesis, and the patch is a looser threshold with a carve-out: one sample at or over 5 ms raises the limit from 5 to 20 ms. The 20 is not something the server guarantees; its only basis is a timer 13 ms late, which is circular. By the author's own account a later timer or two delays in one defrag still fail, so the cause of the report is not removed, only made rarer. It also makes every 5 ms caller accept a single 6 to 20 ms cycle it used to reject, including main dictionary, stream and tracking table, where the two similar keys argument does not apply. The claim that a non-incremental stage always exceeds 20 ms rests on unmeasured, hardware-dependent estimates from this runner, and the author's own figure for the big hashes (22 and 21 ms) sits right at the cap. So it is not shown that every newly accepted outcome is correct behaviour. I would approve a change that first establishes what produced the long cycle and then bounds the check by what the server guarantees, for example by judging a cycle's overrun past its intended end rather than its absolute length, or by verifying that big keys are scanned incrementally without wall-clock time. Failing that, I would approve a raised limit only with measured timer lateness and measured one-go times showing the new value separates the two.

madolson and others added 9 commits December 2, 2026 09:05
…4889)

This is a regression from #4019, first released in 9.2.0-rc1. A user
whose ACL only allows `db=1` can no longer run `MULTI` / `SELECT 1` /
`SET x 1` / `EXEC` from a connection that starts in DB 0, which works in
9.1. `EXEC` now fails with `EXECABORT ... NOPERM No permissions to
access database`. #4019 gave `EXEC` key-specs for its new condition
keys, so the ACL check treats every `EXEC` as a keyed command and
requires access to the pre-transaction DB, even a bare `EXEC` that reads
nothing from it. Each queued command is still checked against its own DB
when it runs, so this only applies the DB check to `EXEC` when it has
arguments.

<details>
<summary>AI generated details</summary>

## Problem

`ACLSelectorCheckCmd` denies any command for which `shouldRestrictCmd()`
is true when the selector cannot access `dbid` (`src/acl.c:2296`).
`shouldRestrictCmd()` includes `doesCommandHaveKeys(cmd)`. Before
0adf657 (#4019), `EXEC` had no key-specs and only the `SLOW` and
`TRANSACTION` categories, so it was never DB-restricted. #4019 added a
key-spec for the `IFEQ`/`IFNE`/`NX`/`XX` keys, and changed
`ACLCheckAllPerm` to pass `c->db->id` for `EXEC` (`src/acl.c:2541`).
That is the DB the client was in before `MULTI`, because queued
`SELECT`s have not run yet. That DB is correct for condition keys, since
`checkExecConditions` reads them from `c->db` (`src/multi.c:286`). It is
wrong for a bare `EXEC`, which reads nothing there. The queued commands
are re-checked against their own DB as they run (`src/multi.c:380`).

The existing #4019 test passes a condition key, so it never checks an
`EXEC` without one.

Affected: 9.2.0-rc1 and the `9.2` branch. In 9.1 and earlier,
`exec.json` has no key-specs and the same transaction succeeds.

Behavior for user `db=1 +@ALL ~*`, connection starting in DB 0:

| Input | Before | After |
|---|---|---|
| `MULTI` / `SELECT 1` / `SET x 1` / `EXEC` | `EXECABORT ... NOPERM ...
database` | `OK OK` |
| `MULTI` / `EXEC` | `EXECABORT ... NOPERM ... database` | empty array |
| `EXEC` without `MULTI` | `EXECABORT ... NOPERM ... database` | `ERR
EXEC without MULTI` |
| `MULTI` / `SELECT 1` / `SET x 1` / `EXEC XX x` | `EXECABORT ... NOPERM
... database` | unchanged |
| `MULTI` / `SELECT 1` / `SET x 1` / `EXEC foo` (malformed) | `EXECABORT
... NOPERM ... database` | unchanged |
| `SELECT 1` / `MULTI` / `SET x 1` / `EXEC` | `OK` | unchanged |

With selectors `(db=1 +@ALL ~*) (db=0 +@ALL ~public*)`, `EXEC IFEQ
secret v` from DB 0 is still `NOPERM ... key`.

## Fix

Skip the active-DB check only when the command is `EXEC` and `argc ==
1`. With any arguments, `EXEC` stays restricted to the active DB,
including malformed ones, which keeps the base behavior.

## Alternative considered

Only DB-restrict `NO_MANDATORY_KEYS` commands when the invocation
actually has keys. That would also lift the DB restriction on `EVAL`,
`EVALSHA`, and `FCALL` with zero keys, which are DB-restricted today.
That is an ACL change to commands this regression does not touch, and it
needs its own review.

## Testing

New test in `tests/unit/acl-v2.tcl`. It also checks that `EXEC XX <key>`
from DB 0 is still denied. With only the `src/acl.c` hunk reverted:

```
[ok]: EXEC conditions require read permission (4 ms)
[ok]: EXEC condition keys check permissions on the active database (2 ms)
[exception]: Executing test client: EXECABORT Transaction discarded because of: NOPERM No permissions to access database.
 in valkey::__dispatch__ at tests/support/valkey.tcl:116
 in $r2 at tests/unit/acl-v2.tcl:169
```

Dropping the `argc == 1` guard, so that every `EXEC` skips the check,
fails both this test and the existing #4019 test:

```
[err]: EXEC condition keys check permissions on the active database in tests/unit/acl-v2.tcl
Expected '' to match '*NOPERM*key*'
[err]: EXEC without conditions is not restricted to the active database in tests/unit/acl-v2.tcl
Expected '' to match '*NOPERM*database*'
```

Based on upstream/unstable `8f67ab136`, so the base branch here is
`upstream-unstable-8f67ab136`.

</details>

This was generated by AI but verified, with love, by a human.

---------

Signed-off-by: Madelyn Olson <madelyneolson@gmail.com>
Backport-Source-PR: 4889
Signed-off-by: valkeyrie-ops[bot] <284117741+valkeyrie-ops[bot]@users.noreply.github.com>
When SET has GET and no expiry, the primary propagates it with every
argument after the value that spells GET removed. The IFEQ/IFNE
comparison value is free-form, so a comparison value of `GET` was
removed too, and replicas and the AOF then diverge from the primary. The
fix keeps the argument that is the comparison value.

Signed-off-by: Madelyn Olson <madelyneolson@gmail.com>
Backport-Source-PR: 5090
Signed-off-by: valkeyrie-ops[bot] <284117741+valkeyrie-ops[bot]@users.noreply.github.com>
…4971)

With reply copy avoidance, a queued SUBSCRIBE/UNSUBSCRIBE reply keeps a
reference to a RAW channel object until it is written. A subscriber that
stops reading keeps that reference, so the next pubsub defrag pass
aborts on the refcount assert in defragPubsubScanCallback.

Only move the channel when its refcount is exactly subscribers + 1, and
skip it for this cycle otherwise. The assert becomes >=, so a missing
reference still aborts.

This also makes channel name defrag work again. Since the switch to
hashtable, the callback used activeDefragStringOb(), which skips any
object with refcount != 1, so channels were never moved. The old object
is now freed only after every client's reference points at the new one,
because the loop looks clients up by the old pointer.

---------

Signed-off-by: Yechiel Merzbach <yechielm@amazon.com>
Co-authored-by: Ran Shidlansik <ranshid@amazon.com>
Backport-Source-PR: 4971
Signed-off-by: valkeyrie-ops[bot] <284117741+valkeyrie-ops[bot]@users.noreply.github.com>
…ue (#5476)

In check mode, rdbLoadCheckModuleValue() walks a module value's opcodes until
RDB_MODULE_OPCODE_EOF, but the opcode chain had no final branch. An RDB cut
between two fields inside a module value made rdbLoadLen() return RDB_LENERR
forever, so valkey-check-rdb, and server startup on a truncated RDB, hung at
100% CPU.

Report a short read on RDB_LENERR and corruption on any other unknown opcode,
and stop the loop.

Backport-Source-PR: 5476
Signed-off-by: valkeyrie-ops[bot] <284117741+valkeyrie-ops[bot]@users.noreply.github.com>
The delete hook ran inside the `ref != NULL` branch of
dbGenericDeleteWithDictIndex(), so only a delete that actually removed
something was charged. Two client-issued DEL/UNLINK were therefore
invisible:

- Delete miss: the key is not there, so the hook never ran.
- The key is logically expired: the removal goes through the expire
  path, and delGenericCommand() skips the DB_FLAG_KEY_DELETED delete.

Both are still a client operating on the key name, which is the rule
lookupKey() already applies to misses -- and what makes create/delete
churn keys show up at all.

Charge the miss case in dbGenericDeleteWithDictIndex() and the expire
case in delGenericCommand().

hotkeys was introduced in #3708.

Also with this change, a miss scenario for GETDEL will be counted twice.
This is an area for future optimization: we could skip the DEL operation
when the GET returns null, thereby avoiding an extra lookup.

---------

Signed-off-by: Binbin <binloveplay1314@qq.com>
Backport-Source-PR: 5079
Signed-off-by: valkeyrie-ops[bot] <284117741+valkeyrie-ops[bot]@users.noreply.github.com>
`SCRIPT DEBUG YES/SYNC` set the Lua engine's global `ldb.active` flag at
enable time. From then on, every EVAL from any client ran under the
debugger, and the debugger read its commands from the connection that
last ran SCRIPT DEBUG. One client could then step through another
client's script and run commands with that client's permissions.

Only mark the Lua debugger active when the debugging client's own
session starts (ldbStart() already does this), and bind each session to
the connection of the client running the script instead of the last
client that enabled debugging.

---------

Signed-off-by: Yana Molodetsky <yamolodu@amazon.com>
Co-authored-by: Ran Shidlansik <ranshid@amazon.com>
Backport-Source-PR: 5596
Signed-off-by: valkeyrie-ops[bot] <284117741+valkeyrie-ops[bot]@users.noreply.github.com>
A replica with `repl-diskless-load swapdb` that full syncs while its
primary is importing a slot via `CLUSTER MIGRATESLOTS` aborts on
`kvstore.c:955`. The swapdb load keeps the old dataset in `server.db`
and loads into a temporary db, but loading the RDB's slot import marked
the slots as importing in `server.db`, which usually still holds keys in
those slots. This marks the db being loaded instead, and stops the
replica from failing the import it just loaded when it attaches to the
new primary after the swap.

Signed-off-by: Madelyn Olson <madelyneolson@gmail.com>
Backport-Source-PR: 5143
Signed-off-by: valkeyrie-ops[bot] <284117741+valkeyrie-ops[bot]@users.noreply.github.com>
`ds.maxlen` is a `size_t`, but `sdscatfmt`'s `%U` expects an `unsigned
long long`. On a 32-bit build `size_t` is 4 bytes, so the debugger's
`maxlen` replies read 4 bytes of stack garbage and print a wrong value
(e.g. "truncated at 6595234844957999164 bytes"). Cast to `unsigned long
long` at both `%U` sites, matching the convention in `src/networking.c`.

Fixes #5681

Signed-off-by: Yana Molodetsky <yamolodu@amazon.com>
Backport-Source-PR: 5684
Signed-off-by: valkeyrie-ops[bot] <284117741+valkeyrie-ops[bot]@users.noreply.github.com>
### Problem

With hot-key detection on, a cluster failover stalls every node in the
cluster.

`clusterDelSlot()` purged hot-key state for its slot. Each purge walks
the whole top-k summary and hashes every key name in it. A failover
reassigns every slot of the shard, and every node runs that reassignment
slot by slot: the promoted replica claims the slots, and all other nodes
learn of it through gossip. So each node scanned its summary up to
16,384 times on the main thread. This includes nodes in other shards
that hold no entries for those slots.

A failover also moves no keys, so the purge discarded valid data on
every node of the shard.

### Change

Purge only when a slot leaves this node's shard.

`clusterDelSlot()` no longer purges, because it only knows the old
owner. The callers that know the new owner purge only when the slot
leaves this node's shard:

- `clusterUpdateSlotsConfigWith()` and `CLUSTER SETSLOT <slot> NODE`
purge only when the slot moves out of this node's shard.
- A slot this node was importing that is then reassigned to a third
shard is also purged in `clusterUpdateSlotsConfigWith()`. The
per-reassignment helper cannot see it (the previous owner is the import
source, in another shard), so it is purged where the abandoned importing
state is cleared, guarded so an import finalized within this shard keeps
its entries.
- `CLUSTER DELSLOTS` purges each slot it unassigns.
- `CLUSTER FLUSHSLOTS` now purges everything, as `CLUSTER RESET` already
did.

In a failover no slot changes shard, so no node purges or scans
anything: `HOTKEYS GET` keeps its data on the promoted replica, its
siblings and the demoted primary. No config changes, and recording a key
access is unchanged.

Known gaps (tolerated, the same tolerance the design already accepts for
RENAME/MOVE): a shard-mate primary that announces it joined another
shard as a replica leaves stale entries on its former replicas until
they age out, at most two windows. Likewise, `CLUSTER FORGET` of a node
whose slot this node was importing leaves the slot unassigned without
purging; the operator has to reassign it anyway, and that path purges
correctly.

### Testing

New `tests/unit/cluster/hotkeys.tcl`:

- After `CLUSTER FAILOVER`, the promoted, sibling and demoted nodes all
keep their hot-key entries. Fails on `unstable`.
- After `SETSLOT` to another shard, the moved slot's entries are gone
and other slots' entries are kept.
- An importing node drops the moved slot's entries when a third shard
claims it, and keeps another slot's entries.

### Backport

9.2 has the same unconditional purge in `clusterDelSlot()` and the same
call sites; the patch applies cleanly there.

Hot-key detection was added in #3708.

---------

Signed-off-by: Alon Arenberg <alonare@amazon.com>
Backport-Source-PR: 5660
Signed-off-by: valkeyrie-ops[bot] <284117741+valkeyrie-ops[bot]@users.noreply.github.com>
@valkeyrie-ops
valkeyrie-ops Bot force-pushed the agent/backport/sweep/9.2 branch from 57c6695 to 5e075c7 Compare December 2, 2026 09:11
Baraa-Hasheesh and others added 9 commits December 3, 2026 02:10
Followup for #5452

An older version could save a replicaof cycle (A -> B -> A) to
nodes.conf from stale gossip. A later replica claim naming a node in the
cycle as its primary then makes clusterNodeGetPrimary() loop forever.

The file alone can't tell which link is stale, so fail to start with a
corrupted config error.

Signed-off-by: Bara' Hasheesh <bara.hasheesh@gmail.com>
Backport-Source-PR: 5556
Signed-off-by: valkeyrie-ops[bot] <284117741+valkeyrie-ops[bot]@users.noreply.github.com>
## Problem
`rewriteAppendOnlyFileRio()` releases `kvs_it` at the end of each db
without clearing it. When a write error lands on the `SELECT` of a later
non-empty db, `goto werr` runs before `kvs_it` is reassigned, so the
error path releases the previous db's iterator a second time
(use-after-free and double free in the AOF rewrite child).

This path is only used when `aof-use-rdb-preamble` is `no`. The rewrite
fails either way and the old AOF is kept, but the child runs on a
corrupted heap and can crash instead of exiting with a write error.

The bug was introduced by 0270abd (redis/redis#11695). It is in every
Valkey release since 8.0.0.

## Fix

The fix sets `kvs_it = NULL` after each release, as the loop did before
0270abd.

Signed-off-by: Bara' Hasheesh <bara.hasheesh@gmail.com>
Backport-Source-PR: 5584
Signed-off-by: valkeyrie-ops[bot] <284117741+valkeyrie-ops[bot]@users.noreply.github.com>
Signed-off-by: valkeyrie-ops[bot] <284117741+valkeyrie-ops[bot]@users.noreply.github.com>
## Summary

Prevent 32-bit length overflow when constructing Valkey cluster module
messages.

## Problem

`createModuleMsgBlock()` calculates the serialized message length using
`uint32_t`, while `createClusterMsgSendBlock()` adds the allocation
prefix using the same width.

For sufficiently large module payload lengths, the allocation-size
calculation can wrap, causing the allocated buffer to be smaller than
the space required for the message.

The related Pub/Sub length-validation issue was addressed in #5030. This
PR applies corresponding validation to the cluster module-message path.

## Changes

- Add `clusterModuleMessageLengthValid()` to validate the payload
against the complete cluster send-block allocation size.
- Use the normal cluster-message header as a conservative upper bound,
protecting both normal and lightweight message formats.
- Reject oversized payloads before allocating, copying, or broadcasting
messages.
- Propagate rejection through the existing module API error path without
changing the public API signature.
- Document the additional error condition.
- Add boundary regression tests and a module API integration test
verifying safe rejection without sending a message.

## Testing

- [x] Build Valkey successfully.
- [x] Run `./runtest --single unit/moduleapi/cluster`.
- [] Run `ClusterModuleTest.*` GoogleTest cases in CI.
- [x] Confirm existing cluster-module message tests continue to pass.

The oversized-payload regression uses a synthetic length and a small
buffer. It does not allocate a multi-gigabyte payload.

### Local validation
./runtest --single unit/moduleapi/cluster — 50 passed, 0 failed.
Memory-leak check passed. The GoogleTest arithmetic boundary cases and
broader regression suite remain pending CI validation.

## Scope

This is a narrowly scoped correctness fix. It does not change the
cluster wire protocol, modify normal message serialization, or introduce
a new public API.

The issue was discussed privately with the Valkey security maintainers,
who confirmed that the affected module API operates within Valkey's
trusted-module boundary and recommended a public bug-fix PR against
`unstable`.

---------

Signed-off-by: SHUVA JYOTI KAR <shuva.jyoti.kar.87@gmail.com>
Signed-off-by: SHUVA JYOTI KAR <33064034+shuvajyotikar13@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Backport-Source-PR: 5269
Signed-off-by: valkeyrie-ops[bot] <284117741+valkeyrie-ops[bot]@users.noreply.github.com>
Clamp used_memory_dataset (used_memory - used_memory_overhead) at 0 instead
of letting the size_t subtraction wrap when the overhead is larger.

Backport-Source-PR: 5644
Signed-off-by: valkeyrie-ops[bot] <284117741+valkeyrie-ops[bot]@users.noreply.github.com>
…B IDs (#5471)

`valkey-check-rdb` starts with `selected_dbid = -1`. With `--stats`, a key that comes before any `SELECTDB` opcode makes `computeDatasetProfile()` index `rdbstate.stats[type + (-1) * OBJ_TYPE_MAX]`, before the start of the array, and crash. The server loads such keys into DB 0, so the checker now starts from DB 0 too.

The DB ID read from `SELECTDB` is a 64-bit length stored in an `int`, and `(databases + 1) * OBJ_TYPE_MAX` is computed as an `int`. `SELECTDB 4294967295` sets `selected_dbid` back to -1, and IDs near `INT_MAX` overflow the size computation. IDs above `INT_MAX` are now reported as "Invalid DB ID", and with `--stats`, IDs from `INT_MAX / OBJ_TYPE_MAX` on are reported as too large for `--stats`.

Both problems came with the RDB analysis reports (#1743), so they are in every release since 9.0.0.

Backport-Source-PR: 5471
Signed-off-by: valkeyrie-ops[bot] <284117741+valkeyrie-ops[bot]@users.noreply.github.com>
…2933)

The node ids returned by `ValkeyModule_GetClusterNodesList` are not null
terminated, but fixed-length buffers. When these are passed to
`ValkeyModule_GetClusterNodeInfo`, which until now required the node id
to be null terminated, the node lookup failed or potentially caused
undefined behavior when `strlen` read outside of allocated memory.

This error can be seen in the example module hellocluster.c included in
this repo.

This commit changes `ValkeyModule_GetClusterNodeInfo` and
`ValkeyModule_GetClusterNodeInfoForClient` to assumes the node id to be
exactly 40 bytes long and does not require it to be null terminated.
It's not a breaking change, since passing a valid null-terminated node
id still works as expected.

---------

Signed-off-by: Deepak Nandihalli <deepakrn@users.noreply.github.com>
Signed-off-by: Deepak Nandihalli <deepak.nandihalli@gmail.com>
Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
Co-authored-by: Viktor Söderqvist <viktor.soderqvist@est.tech>
Backport-Source-PR: 2933
Signed-off-by: valkeyrie-ops[bot] <284117741+valkeyrie-ops[bot]@users.noreply.github.com>
Follow-up to #4060.

`ioThreadWriteToClient()` stores `io_last_written` and then sets
`io_write_state = CLIENT_COMPLETED_IO`. #3324 removed the release fence
between the two stores. The main thread reads `io_write_state` with a
plain load and takes an acquire only when it dequeues the completion
from the outbox.

`trimReplyUnusedTailSpace()` and the `setDeferredReply()` merges run on
the main thread while a write completion is published but not yet
dequeued. #4060 lets them mutate reply blocks in `CLIENT_COMPLETED_IO`
when the bookmark pointer does not match. On a weakly ordered CPU
(aarch64), the main thread can see `CLIENT_COMPLETED_IO` with the
previous `io_last_written`, pass the pointer check, and reallocate the
block the IO thread just bookmarked. If the allocator reuses that
address for the next reply block, the stale `data_len` skips it: the
iovec is empty, the write is zero bytes, and the write handler is
re-armed forever. If the bookmark matches no block,
`_postWriteToClient()` frees every pending block as written and the
client loses whole replies. The stream stays valid RESP, shifted by the
lost replies.

The trim and both merges are now allowed only in `CLIENT_IDLE`, which
the main thread sets after dequeuing the completion (release/acquire
ordered), so the bookmark is visible by then. The pointer check stays,
because a partial main-thread write leaves a live bookmark in
`CLIENT_IDLE`. The release fence before both `CLIENT_COMPLETED_IO`
stores is restored, and `cur_tid` is stored before it.
`waitForClientIO()` relies on that fence, and `ioThreadAccept()` already
has it. While a completion is queued the trim is skipped, so the
deferred length goes into a new reply node.

Tests refuse the trim and both merges in `CLIENT_PENDING_IO` and
`CLIENT_COMPLETED_IO`. `TestStaleBookmarkSurvivesReorderedCompletion`
replays the reordered completion deterministically and fails with the
old guard.

---------

Signed-off-by: Lior Malovani <liormal@amazon.com>
Co-authored-by: Lior Malovani <liormal@amazon.com>
Backport-Source-PR: 5669
Signed-off-by: valkeyrie-ops[bot] <284117741+valkeyrie-ops[bot]@users.noreply.github.com>
…OFF (#5682)

On $ENDOFF, dualChannelReplHandleEndOffsetResponse() starts the PSYNC
handshake on the main link with dualChannelSetupMainConnForPsync(). If a
write on the main link fails there, that function calls
cancelReplicationHandshake(), which aborts the whole dual channel sync:
the RDB channel is closed, repl_rdb_transfer_s is NULL and
repl_rdb_channel_state is NONE. The caller then set a read handler on
the NULL repl_rdb_transfer_s and the replica crashed with SIGSEGV.

Return C_RETRY when the RDB channel state is NONE after the main channel
setup. C_ERR cannot be used: the error path would abort the sync a
second time and replicationAbortDualChannelSyncTransfer() asserts that a
sync is in progress.

Add an integration test with a fake primary that resets the main link
after +DUALCHANNELSYNC and then sends a valid $ENDOFF on the RDB
channel.

---------

Signed-off-by: Eran Liberty <eran.liberty@gmail.com>
Co-authored-by: valkey-review-bot[bot] <282604435+valkey-review-bot[bot]@users.noreply.github.com>
Co-authored-by: Ran Shidlansik <ranshid@amazon.com>
Backport-Source-PR: 5682
Signed-off-by: valkeyrie-ops[bot] <284117741+valkeyrie-ops[bot]@users.noreply.github.com>
tatikoma and others added 12 commits December 3, 2026 03:11
Sanitize CR/LF in FUNCTION LIST's error reply for an invalid argument, so it can't break the RESP stream.

Backport-Source-PR: 5369
Signed-off-by: valkeyrie-ops[bot] <284117741+valkeyrie-ops[bot]@users.noreply.github.com>
SWAPDB changes what clients read from both databases, but tracking
clients get no invalidation and keep stale cached values.
Send the same invalidation FLUSHDB does, to all tracking clients, since
the tracking table doesn't store a key's database.

---------

Signed-off-by: Kyuwon Jeong <jkw5033@gmail.com>
Backport-Source-PR: 5690
Signed-off-by: valkeyrie-ops[bot] <284117741+valkeyrie-ops[bot]@users.noreply.github.com>
…5611)

Fixes #5608.

`lookupStringForBitCommand()` creates or zero-pads the string before the
BITFIELD ops run, but `dirty` was only turned into `changes` inside the
branch that actually writes. If every write fails with `OVERFLOW FAIL`,
`changes` stays 0, so nothing is propagated and the key exists on the
primary but not on the replica or in the AOF.

This counts the creation/growth as one change in that case, the same way
SETBIT treats `dirty`. The command is propagated as is, and the replica
ends up with the same zero-padded string.

Side effects: a fully rejected BITFIELD that creates or grows the key
now behaves like SETBIT does. It fires the `setbit` keyspace event,
invalidates WATCH and client tracking on the key, and bumps `dirty`.

Tests in `tests/unit/bitfield.tcl`: the replication block covers a new
key and a grown key, plus a WATCH test (EXEC used to return PONG there,
now nil), and a new `appendonly yes` block checks the created key
survives `DEBUG LOADAOF`. All three fail without the bitops.c change and
pass with it:

```
./runtest --single unit/bitfield
```

`unit/bitops` and `unit/pubsub` also pass.

---------

Signed-off-by: xhon-pelushi <xhon@pelushi.com>
Backport-Source-PR: 5611
Signed-off-by: valkeyrie-ops[bot] <284117741+valkeyrie-ops[bot]@users.noreply.github.com>
… BGSAVE (#4941)

Fixes #4938.

With forkless BGSAVE, `MOVE` or `COPY` of a key that was created (or
recreated) after the save started expedited that key into the snapshot.
A new key then appeared in the RDB even though it did not exist at
BGSAVE time, and a recreated key was saved twice, so the RDB would not
load.

`expediteSingleKeyWithoutOptimization` now skips entries whose
`iterator_epoch` is newer than the consistent iterator's modification
id, since they are not part of the snapshot.

Added tests in `tests/integration/rdb.tcl` for a new key MOVE, a
recreated key MOVE and a recreated key COPY. They fail on the unfixed
source and pass with the change.

Signed-off-by: drakeo338 <paranoyouz@gmail.com>
Backport-Source-PR: 4941
Signed-off-by: valkeyrie-ops[bot] <284117741+valkeyrie-ops[bot]@users.noreply.github.com>
Signed-off-by: valkeyrie-ops[bot] <284117741+valkeyrie-ops[bot]@users.noreply.github.com>
Fixes #5610

valkey-check-rdb didn't know about `RDB_OPCODE_UPDATE` (242), so a
dump.rdb written by a replica after a forkless sync (with
`repl-diskless-load disabled`) was reported as `Invalid object type:
242` even though the server loads it fine.

This adds a case that parses the embedded RESP command with
`parseRespCommandFromReader`, same as `rdbLoad`, and skips it. Like
`rdbLoad` it's only accepted for RDB version 81+, older files still
fail. I made `rdbRioReader` / `rdbRioReadLine` non-static so the checker
can reuse them instead of copying them.

Added two tests to `integration/valkey-check-rdb` with a hand-built RDB
containing a `SET k v` inline command (one at version 81, one at an
older version). Also ran the repro from the issue locally: the replica's
dump.rdb had 200 inline commands, check-rdb rejected it before and says
OK now.

---------

Signed-off-by: Dean Chen <862469039@qq.com>
Backport-Source-PR: 5617
Signed-off-by: valkeyrie-ops[bot] <284117741+valkeyrie-ops[bot]@users.noreply.github.com>
Fixes #4935

## Summary
- AOF rewrite and `CLUSTER MIGRATESLOTS` rebuild consumer-group PELs as
`XCLAIM FORCE JUSTID`. That command skipped IDs whose stream entry was
already `XDEL`'d / trimmed, so pending ownership and delivery counts
diverged from the source.
- Keep the live XCLAIM cleanup (`nack != NULL` still drops a dangling
PEL entry). Only an obeyed `FORCE JUSTID` with an empty PEL (AOF client,
slot import, replica) may recreate the NACK.

Signed-off-by: quanyeyang <quanyemostima@gmail.com>
Backport-Source-PR: 4973
Signed-off-by: valkeyrie-ops[bot] <284117741+valkeyrie-ops[bot]@users.noreply.github.com>
If a module blocks a client on keys whose slots differ from the command's
slot, the blocked client is later checked by clientsCronHandleTimeout(),
which calls clusterRedirectBlockedClientIfNeeded(). There it hits the
slot == c->slot assertion (added in #2165), since we do not allow cross-slot
commands, and the server aborts.

A module can reach this through incorrect use of the API. Even though
it is a misuse, it should not be able to crash the server, so reject it
in moduleBlockClient() by checking each key against c->slot and reply with
an error instead of blocking. Modules that set
VALKEYMODULE_CLUSTER_FLAG_NO_REDIRECTION manage key distribution themselves,
so skip the validation for them, including the redirect check in
clusterRedirectBlockedClientIfNeeded().

This adds one more error path that aborts after the blocked handle has
been allocated. Such paths must reset bc->client to NULL, otherwise a
later VM_UnblockClient() dereferences will crash the server. Only the
Lua/MULTI path did this; apply the same to the other paths as well.

Detached handles from key-blocking calls must also be releasable with
VM_UnblockClient() even when no timeout callback was provided; otherwise
they leak.

Signed-off-by: Binbin <binloveplay1314@qq.com>
Backport-Source-PR: 4541
Signed-off-by: valkeyrie-ops[bot] <284117741+valkeyrie-ops[bot]@users.noreply.github.com>
A replica that still cannot reach its primary can get that primary voted
out after a partition heals, even though every other primary reaches it
again. This needs a first election that failed while the primary was cut
off, followed by a retry. The primary becomes a replica of the winner
and loses the writes the winner had not received.

Voters refuse a replica whose primary they see as up, unless the vote
request carries FORCEACK, a flag that skips that check. #2227 added it
so the best ranked replica can start its first election before the FAIL (failed)
mark reaches the voters, but the replica also sends it on every retry.
The other primaries clear the mark once it is older than twice the
cluster node timeout and they reach the primary again. The replica
cannot, so its retry, at least four node timeouts after the first
election, wins their votes.

Now the replica sends FORCEACK only while its FAIL mark is no older than
twice the cluster node timeout, the age at which primaries clear it. The
age restarts whenever the replica flags the primary again. The first
election after a FAIL and manual failover are unchanged. A retry after
an expired election always starts later than that, whatever the node
timeout, so the primaries judge it by their own view. Only the replica
knows how old its FAIL is, so the check lives there.

Fixes #5403

Signed-off-by: 1fanwang <1fannnw@gmail.com>
Backport-Source-PR: 5446
Signed-off-by: valkeyrie-ops[bot] <284117741+valkeyrie-ops[bot]@users.noreply.github.com>
Apple ARM64 uses 53-bit precision for long doble. Formatting the integer
result through long double can round large integers on a platform with
insufficient precision.

Signed-off-by: Masahiro Ide <masahiro.ide@lycorp.co.jp>
Backport-Source-PR: 5511
Signed-off-by: valkeyrie-ops[bot] <284117741+valkeyrie-ops[bot]@users.noreply.github.com>
Follow-up to #5669, as suggested in its review.

`clientHasPendingReplies()` reads a replica's compression state
(`out_buf`, `out_buf_pos`) whenever `io_write_state !=
CLIENT_PENDING_IO`. In `CLIENT_COMPLETED_IO` the main thread has not
dequeued the IO completion yet, and the dequeue is where it gets acquire
ordering. On a weakly ordered CPU (aarch64) it can see the new state
before the IO thread's writes to the compression buffer, including a
buffer that `sdsMakeRoomFor()` reallocated.

The read now requires `CLIENT_IDLE`, which the main thread sets after
the dequeue. `processClientIOWriteDone()` re-checks pending replies at
that point, so no write event is lost.

`getClientMemoryUsage()` keeps its `!= CLIENT_PENDING_IO` check. It sees
`CLIENT_COMPLETED_IO` only through `catClientInfoString()`, which calls
`waitForClientIO()` first. Its acquire fence pairs with the release that
#5669 restored before the `CLIENT_COMPLETED_IO` store, so that read is
ordered, and requiring `CLIENT_IDLE` there would only drop the staging
buffer from `tot-mem` while a completion is queued.

`TestReplicaCompressionStateIoGates` checks both functions in each write
state and fails if the pending-replies check goes back to `!=
CLIENT_PENDING_IO`.

---------

Signed-off-by: Lior Malovani <liormal@amazon.com>
Co-authored-by: Lior Malovani <liormal@amazon.com>
Backport-Source-PR: 5689
Signed-off-by: valkeyrie-ops[bot] <284117741+valkeyrie-ops[bot]@users.noreply.github.com>
…5713)

## Fix crash in `VM_GetClientInfoById` for a client without a connection

### Problem
A module command that asks for information about its own caller crashes
the server when it runs from a script, a function or `VM_Call`.

A typical case is an audit or rate-limiting module that logs or limits
by the caller's address:

```c
int AuditSet(ValkeyModuleCtx *ctx, ValkeyModuleString **argv, int argc) {
    ValkeyModuleClientInfo ci = VALKEYMODULE_CLIENTINFO_INITIALIZER_V1;
    ValkeyModule_GetClientInfoById(&ci, ValkeyModule_GetClientId(ctx));
    log_access(ci.addr, ci.port, argv[1]);
    ...
}
```

`AUDIT.SET k v` from a normal client works, but the following crashes
with SIGSEGV:

```
EVAL "return server.call('AUDIT.SET', KEYS[1], ARGV[1])" 1 k v
```

Inside the script the command runs through the script's fake client,
which has no connection, and `call()` makes it
`server.executing_client`. `VM_GetClientInfoById()` returns
`server.executing_client` when the id matches, and
`modulePopulateClientInfoStructure()` then dereferences `client->conn`
for the TLS flag and the peer address.

### Fix
`modulePopulateClientInfoStructure()` skips the TLS flag and the peer
address and port when the client has no connection. The structure is
zeroed first, so such clients report an empty address and port 0, and
still report their other flags (including `fake`), db and id.

### Testing
New test in `tests/unit/moduleapi/misc.tcl`, "test module clientinfo api
- called from a script", runs `test.clientinfo` through `EVAL` and
checks the returned info. Without the fix the server crashes with signal
11.

---------

Signed-off-by: Eran Liberty <eran.liberty@gmail.com>
Co-authored-by: Bara' Hasheesh <bara.hasheesh@gmail.com>
Backport-Source-PR: 5713
Signed-off-by: valkeyrie-ops[bot] <284117741+valkeyrie-ops[bot]@users.noreply.github.com>
@valkeyrie-ops valkeyrie-ops Bot added the ai-resolved-conflicts AI is used to resolve conflicts in automated backport PRs. label Dec 3, 2026
@valkeyrie-ops

valkeyrie-ops Bot commented Dec 3, 2026

Copy link
Copy Markdown
Contributor Author

AI backport resolution: source PR #4941

Skip post-snapshot keys when expediting for MOVE and COPY in forkless BGSAVE

1 AI-edited file

Claude Summary

The validation failure was a test-only API mismatch, and I fixed it in tests/integration/rdb.tcl; the fix has not been re-run, since validation is the caller's step.

First real error (log line 735, ./runtest --single integration/rdb):
ERR Unknown option or number of arguments for CONFIG SET - 'bgsave-default-method', raised from tests/integration/rdb.tcl:389. The build itself succeeded.

Cause: the backported test selects the save method with config set bgsave-default-method fork|forkless, which does not exist on 9.2. On this branch the equivalent setting is forkless-policy with values require-fork / prefer-forkless (src/config.c:3574).

Fix: in the new test block of tests/integration/rdb.tcl:

  • The outer loop is now foreach {policy bgsave_type} {require-fork fork prefer-forkless forkless}, the same idiom the neighbouring bgsave tests in that file use.
  • The config line is now r config set forkless-policy $policy.

Test names, scenarios and assertions are unchanged, so the source PR's fork and forkless coverage is preserved.

src/bgiteration.c needed no change: it compiled, and the fields and flag it relies on exist on 9.2 with the same meaning.

AI-edited files requiring review

Full backport commit diff: commit 57c5477f3d47.

Please review these AI resolutions for correctness before merging.

@valkeyrie-ops

valkeyrie-ops Bot commented Dec 3, 2026

Copy link
Copy Markdown
Contributor Author

AI backport resolution: source PR #5584

Fix double free of the key iterator on AOF rewrite write error

1 AI-edited file

Claude Summary

First real error: src/unit/test_aof.cpp failed to compile in make -C src test-unit because struct valkeyServer on 9.2 has no created_db_ids, created_db_count or created_db_capacity members (test_aof.cpp lines 47-49 and 53).

Fix: I removed those four lines from setupTwoDbs() in src/unit/test_aof.cpp. On 9.2, rewriteAppendOnlyFileRio walks 0..server.dbnum and checks dbHasNoKeys(j) against server.db[j], so the test only needs server.dbnum and server.db, which it already sets. This matches how src/unit/test_bgiteration.cpp sets up databases on this branch.

The src/aof.c change (kvs_it = NULL after the release) applied cleanly and is untouched. The test still exercises the same path: the second SELECT write fails after the db 0 iterator was released.

Nothing was built or run here, so the fix is unverified until validation re-runs. Those four were the only errors the compiler reported for the file; linking and the test run itself never happened in the failed validation.

AI-edited files requiring review

Full backport commit diff: commit d20e8c0f31c4.

Please review these AI resolutions for correctness before merging.

sarthakaggarwal97 and others added 5 commits December 3, 2026 22:57
killAppendOnlyChild() waits with waitpid(-1, ...), which reaps any child that has exited, not just the AOF rewrite child, and drops its status. If a forked SCRIPT DEBUG session has ended but serverCron hasn't reaped it yet, stopping AOF during a rewrite reaps it there. Its pid then stays in the debugger children list, so serverCron logs "waitpid() returned an error" on every tick, and on shutdown the stale pid, which may belong to an unrelated process by then, gets a SIGKILL.

This patch waits for server.child_pid only, like TerminateModuleForkChild() already does.

serverCron doesn't reap children while a script is running, so the new test ends the debug session while the server is in a busy script, and starts and kills the rewrite right after the script. Once the debug session child is reaped, it checks that the server doesn't try to kill it on shutdown.

This affects all versions.

Signed-off-by: Sarthak Aggarwal <sarthagg@amazon.com>
Backport-Source-PR: 5529
Signed-off-by: valkeyrie-ops[bot] <284117741+valkeyrie-ops[bot]@users.noreply.github.com>
Forkless BGSAVE stores its temp and final RDB paths relative to the cwd
and renames on a BIO thread after the iterator finishes. A `CONFIG SET
dir` in between makes the rename resolve against the new dir, so it
fails with ENOENT, the save reports `err`, and the cleanup unlink misses
too, leaving `temp-forkless-*.rdb` in the old dir. A fork-based save is
unaffected because the child keeps its cwd. This resolves both paths
against the cwd when the save starts.

Signed-off-by: Madelyn Olson <madelyneolson@gmail.com>
Backport-Source-PR: 5106
Signed-off-by: valkeyrie-ops[bot] <284117741+valkeyrie-ops[bot]@users.noreply.github.com>
Signed-off-by: valkeyrie-ops[bot] <284117741+valkeyrie-ops[bot]@users.noreply.github.com>
…5113)

During a forkless save, a command inside EXEC that writes a key EXEC did
not expedite aborts the server on `serverAssert(!(mustBlock &&
c->flag.multi && !c->flag.script))` in
`bgIteration_blockClientIfRequired()`. EXEC predicts the keys a
transaction will write, but it cannot see a `SWAPDB` run by a queued
script, and it does not remap the destination database of a `COPY ... DB
n` or `MOVE` after a queued `SWAPDB`. This uses the synchronous wait
that scripts already use for undeclared keys, so the command waits for
the save thread to hand the entry back instead of crashing.

Signed-off-by: Madelyn Olson <madelyneolson@gmail.com>
Backport-Source-PR: 5113
Signed-off-by: valkeyrie-ops[bot] <284117741+valkeyrie-ops[bot]@users.noreply.github.com>
…#5144)

A replica loading a disk-based full sync processes events from inside
`rdbLoad()`. If a cluster bus message handled there moves it to a new
primary (an ordinary failover, or `CLUSTER FAILOVER TAKEOVER` on another
replica), the sync being loaded is cancelled and a new handshake starts.
When the load returns, the replica finalizes the cancelled sync anyway.
It closes the new sync's temp file, reports the link as up with the new
primary's replication ID, and keeps the old primary's dataset with no
further resync. This patch treats a load that spans a
`cancelReplicationHandshake()` call as failed and leaves the newer
sync's state alone.

Signed-off-by: Madelyn Olson <madelyneolson@gmail.com>
Backport-Source-PR: 5144
Signed-off-by: valkeyrie-ops[bot] <284117741+valkeyrie-ops[bot]@users.noreply.github.com>
@valkeyrie-ops

valkeyrie-ops Bot commented Dec 5, 2026

Copy link
Copy Markdown
Contributor Author

AI backport resolution: source PR #5106

Pin forkless save paths to the dir the save started in

1 AI-edited file

Claude Summary

The build succeeded; the first real error is the new test failing in tests/integration/rdb.tcl, for both the fork and forkless variants. I applied a one-assertion fix in that file; it has not been run, since validation is re-run by the caller.

Cause: validation runs the suite with --log-req-res, which sets req-res-logfile to the relative path stdout.reqres. The server reopens that file on every logged command (src/logreqres.c:271), so after CONFIG SET dir $new_dir a stdout.reqres appears in the new directory. The test's final check that the new directory is completely empty then fails:

Expected '' to be equal to '.../tests/tmp/server.rdb-dir-change.9807.33/stdout.reqres'

The same line failed in both variants, and every assertion before it had passed, including the ones that the snapshot landed in the old dir with no temp file left behind. So this is a test-harness artifact, not a problem with the src/forkless.c change, which I left untouched.

Fix: the final assertion now ignores *.reqres files when checking that the new directory is empty, with a short comment explaining why. Any RDB or temp file landing there still fails the test, and without --log-req-res the check is unchanged.

I chose this over tagging the server logreqres:skip so the test keeps running in the req-res validation job. The relocated log still sits under tests/tmp/*/, so the req-res validator will pick it up.

AI-edited files requiring review

Full backport commit diff: commit bdea78d5115e.

Please review these AI resolutions for correctness before merging.

The Daily reply-schemas-validator job fails since the test "Active
Defrag pubsub with a pending channel reply" was added in #4971:

    Reply schema validation failed for CONFIG SET
    min-io-threads-avoid-copy-reply: 'OK' was expected (response: null)

The test runs "config set min-io-threads-avoid-copy-reply 1" on a server
without IO threads. After that, isCopyAvoidPreferred() returns 1 for
every reply, so each reply buffer starts with a binary payload header
(and holds object pointers for bulk strings) instead of plain RESP. The
req-res logger (reqresAppendResponse() in src/logreqres.c) copies the
reply buffer as is, so the .reqres file holds the header before "+OK"
and the validator cannot parse the reply.

The test needs copy avoidance for its whole body, so it cannot run in
log-req-res mode. Tag it with logreqres:skip, like the other tests that
set min-io-threads-avoid-copy-reply to 1 (tests/unit/networking.tcl and
tests/unit/obuf-limits.tcl). It still runs in all other jobs. The {0}
result pattern is the value that "$listener close" returns.

Fixes #5642

Signed-off-by: Eran Ifrah <eifrah@amazon.com>
Backport-Source-PR: 5655
Signed-off-by: valkeyrie-ops[bot] <284117741+valkeyrie-ops[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-resolved-conflicts AI is used to resolve conflicts in automated backport PRs. backport Backport PR opened by valkey-ci-agent

Projects

None yet

Development

Successfully merging this pull request may close these issues.