Repository navigation
fix(environment): map id-list elements when a scalar set also changed - #7161
Conversation
When comparing an answer's scalar id list, the id mapping ran only on the sameItems fast path. Once one element genuinely changed, or the lengths differed, array fell to pairwise comparison that compared each element without its id-list field, so scalar skipped the mapping: comparing live [101,102] with env [1,9] under 101->1, 102->2 reported /ids/0 (101 vs 1) as a change as well as the real /ids/1 (102 vs 9). Thread an idList flag from array to scalar, set by the same per-element rule sameItems uses, so a mapped element matches and is counted as a normalised id while a genuine change is reported with its original value. Non-id arrays are unchanged.
[Low impact] The reviewed changes appear safe to merge; no blocking issues were found. SummaryThis PR fixes ID-list comparisons so renamed survivors do not appear as value changes, while real replacements and reorders remain visible.
No new actionable correctness or security issues found. The earlier mapped-reorder finding is addressed. No superseding fix was found in the available history, but the local Reviews (6) · Last reviewed commit: "fix(environment): detect complete duplic..." · Reviewed by Greptile |
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: 6f4ed55edc
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
The first fix mapped each id-list element but still paired scalar arrays by position, so a survivor that shifted position paired with the wrong item: [101,102] versus [2] under 101->1, 102->2 still emitted a false /ids/0 value difference even though 102->2 is the survivor and only the removal changed. Pair id-list survivors by the environment identity they map to, then any remaining live and environment items by position. The translation is one owner shared with sameItems, and the paired comparison still maps the original live id and reports its original value on a genuine change. Non-id arrays keep positional pairing.
There was a problem hiding this comment.
💡 Codex Review
rea/src/application/environment/environmentCompareDiff.ts
Lines 368 to 370 in 24a8510
When an ID is replaced while one mapped survivor shifts (for example [101, 102] versus [2, 9] under 101→1 and 102→2), #idListPairs returns the real survivor pair plus a positional fallback pair; feeding both into envOrder yields [1, 0] and adds an order difference. There is only one surviving identity here, so no relative-order change can be established—the fallback represents the genuine value replacement, not the same item in a new position. Compute order from the identity-matched survivor pairs before adding positional fallbacks.
AGENTS.md reference: AGENTS.md:L19-L19
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
#idListPairs appended a positional fallback pair for a replaced id, and the order check read every pair, so a single surviving identity that shifted emitted a spurious order difference: [101,102] versus [2,9] under 101->1, 102->2 reported order as well as the real /ids/0 value change. Return the identity-matched survivor pairs separately and compute order from them alone; the positional fallbacks are value replacements, not the same item in a new position. Two or more reordered survivors still report order.
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
|
Addressed Codex's P2 "Restrict order checks to identity-matched survivors" in 820fdb2 (the inline thread is on the superseded commit and would not take a reply).
On CI: the red checks are a single unrelated test, |
|
TL;DR: I ran the PR's test file on three Node versions at head 820fdb2, and all 73 tests passed. With
Not run
Test setup
Commandsnpm ci --offline
npm run test:prepare
xvfb-run -a npm run test:focused -- src/application/environment/environmentCompareDiff.test.ts🤖 Written and tested with Claude Code (Sonnet 5.5, verified by Opus 5.5), posted with my OK 🦊 |
|
Merged current Verified locally on the merged head (Ubuntu x64, Node 24.22.1): |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0c3960c310
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: aaf70d26e3
ℹ️ 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".
Summary
When comparing an answer's scalar id list, a genuinely changed element made the comparison also report the unchanged ids as changed. Comparing live
{"ids":[101,102]}with env{"ids":[1,9]}under the learned mapping101→1,102→2reported both/ids/0(101 vs 1) and the real/ids/1(102 vs 9), even though101→1is the mapping, not a change.This was surfaced by the automated review of #6530 (a P2 finding on
environmentCompareDiff.ts) and reproduced at the source boundary; it is a concrete defect in the environment-compare engine. No separate issue is linked.Problem and expected behavior
Differ.sameItemsmaps the whole scalar id list and, when the mapped set equals env, counts the renames and returns. Once one element genuinely changed, or the lengths differed,sameItemsreturned false andarrayfell to pairwise comparison. Those element comparisons were passed{ own, clockKey }but not the id-list field, soscalar.mapsAsIdwas false and each element was compared raw.Expected: each id-list element maps by the probe's mapping, so a renamed element matches (and counts as a normalised id) while only a genuinely different element is reported — with its original live value, not its mapped form.
Change and scope
arraypairs survivors by the environment identity they map to (#idListPairsover#translateIdList), then pairs any remaining live and environment items by position. This handles a survivor that shifted position when the set was shortened or changed (review follow-up). The translation is one owner shared withsameItems. Other arrays keep positional pairing.idListflag derived with the same per-element rulesameItemsuses (ID_LIST_FIELDon the field, or a learned state reference).scalar.mapsAsIdhonors that flag, so the element maps throughIdMap.env. A mapped match incrementsnormalised.idsand reports nothing; a real difference falls through and is reported with the original values, exactly as a singular id field already is.valueforwards the flag.scalar, so a renamed survivor matches and is normalised while a genuine change reports its original value.orderis computed only from the identity-matched survivor pairs, not the positional fallbacks (review follow-up): a single surviving identity that shifts is a value replacement, not a reorder, so it no longer emits a spuriousorder. Two or more reordered survivors still reportorder.object/keyedByLearnedIds) already maps correctly and is unchanged.Contribution scope: an ordinary correctness fix within existing boundaries; a maintainer scope decision is not applicable.
Contract and boundary impact
Semantic owner and earliest changed stage: scalar id-list element comparison in
Differ.array/Differ.scalar.CLI and MCP/tool-catalog contract: no schema change.
compare-application-versions/compare-web-capturesnow omit the false-positive id differences and count the renames.Provider, bridge, target-format, or platform compatibility: none.
Evidence, artifact, provenance, or reconstruction contract: difference lists become accurate;
normalised.idscounts the renamed-but-matching elements.Generated metadata, package, or installation impact: none.
Read existing files or captured data.
Launch or attach to a process.
Inject instrumentation or run scripts/code.
Change process memory, registers, files, or configuration.
Contact network services.
Recover protected code or work around protections.
Documentation or usability only; no target interaction.
Not sure yet; investigation or maintainer guidance needed.
Evidence and regression coverage
Tests added to
src/application/environment/environmentCompareDiff.test.ts, in "scalar sets of mapped ids":[101,102]vs[1,9]under101→1,102→2reports only/ids/1(102vs9) and countsnormalised.ids === 1.[101,102]vs[1]reports only the length difference and countsnormalised.ids === 1.[101,102]vs[2]reports only the length difference, with no false/ids/0, and countsnormalised.ids === 1.[101,102]vs[2,9]reports only/ids/0(101vs9), with noorder.[101,102,103]vs[2,1,99]reportsorderplus/ids/2.Base reproduction (executed): with
environmentCompareDiff.tsreverted, the new tests fail; the first commit's two tests produce an extra/ids/0, and the shifted-survivor test fails against the first commit (it still emitted a false/ids/0).Additional cases checked at the source boundary (all correct after the change): a fully reordered mapped set reports only
order; a non-id array (tags) reports only its real element change with no mapping; equal ids with no learned mapping report nothing.Observed, derived, and inferred claims remain distinguishable.
Artifact identity, source provenance, and failed attempts remain preserved.
Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.
Validation performed
Run on Ubuntu 24.04 x64 with Node 24.22.1:
npm run test:local -- src/application/environment/environmentCompareDiff.test.ts: 70 passed. With the fix reverted: the two new tests fail.npm run test:focused --with every test file referencing environment compare or state (60 files): 1517 passed, 1 skipped, 0 failed. The heavytoolSchemaValidityboundary test (~30s, unrelated to this comparison change) timed out at its 30s limit under local load and passes in isolation; it is excluded from that count.npm run check:fast: passed.knipreports nothing for the touched module.Compatibility, safety, and release
Author readiness
Human owner: @mhamzasakhi
Before merge
type(scope): outcome.Review follow-up
aaf70d26e3preserves collection ownership from #12354, uses learned ID equivalence for survivor matching, and reports order only when survivor assignments establish it. The 171 source tests, seven compiled CLI tests, 130,050 exhaustive small oracle cases, andcheck:ci:fastpassed.On the local inert benchmark, one 8,192-entry collision case improved from 906 ms to 11 ms warm with identical output. A constructed 4,096-independent-conflict case rose from 14 ms to 22 ms warm and used 28 MiB more peak Node process RSS. These comparisons measure the matcher and complete comparison on the same synthetic arrays. Hosted CI is pending.
Current review revision
Commit
575723440achecks for forced pairs across maximum matchings, including alternatives that use spare entries. For live[1,2]and recorded[3,2]with learned mappings1→2and2→3, both entries survive and the comparison reports the forced order difference. Ambiguous duplicate matches still leave order unresolved.Passed 175 source tests, seven compiled CLI tests, 130,050 exhaustive oracle cases, and
check:ci:fast. The 8,192-entry forced-order case took 11.06 ms warm versus 9.44 ms on the previous head and added 16.3 MiB of peak process RSS. Five other benchmark outputs were identical.Commit
7f0c5fdb53also preserves order differences for complete duplicate ID lists. If positional matching fails but a complete pairing exists, the order differs. Partial matches still require evidence of forced relative order. The strict agreement path now distinguishes these cases. Passed 178 source tests, seven compiled CLI tests, 130,050 oracle cases, andcheck:ci:fast.