Skip to content

fix(environment): map id-list elements when a scalar set also changed - #7161

Merged
morluto merged 8 commits into
morluto:mainfrom
mhamzasakhi:fix/compare-id-list-mapping
Nov 19, 2026
Merged

morluto merged 8 commits into
morluto:mainfrom
mhamzasakhi:fix/compare-id-list-mapping

Conversation

@mhamzasakhi

@mhamzasakhi mhamzasakhi commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

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 mapping 101→1, 102→2 reported both /ids/0 (101 vs 1) and the real /ids/1 (102 vs 9), even though 101→1 is 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.sameItems maps 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, sameItems returned false and array fell to pairwise comparison. Those element comparisons were passed { own, clockKey } but not the id-list field, so scalar.mapsAsId was 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

  • For an id list, array pairs survivors by the environment identity they map to (#idListPairs over #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 with sameItems. Other arrays keep positional pairing.
  • Each element's comparison carries an idList flag derived with the same per-element rule sameItems uses (ID_LIST_FIELD on the field, or a learned state reference).
  • scalar.mapsAsId honors that flag, so the element maps through IdMap.env. A mapped match increments normalised.ids and reports nothing; a real difference falls through and is reported with the original values, exactly as a singular id field already is.
  • value forwards the flag.
  • Non-id arrays are unaffected: the flag is false unless the field is an id-list field or the element is a learned state reference.
  • The paired comparison passes the original live id to scalar, so a renamed survivor matches and is normalised while a genuine change reports its original value.
  • order is 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 spurious order. Two or more reordered survivors still report order.
  • Not included: object-keyed id comparison (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-captures now 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.ids counts 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":

    • "maps each id when one element genuinely changed, reporting only the real change": [101,102] vs [1,9] under 101→1,102→2 reports only /ids/1 (102 vs 9) and counts normalised.ids === 1.
    • "maps the surviving ids when the list length also differs": [101,102] vs [1] reports only the length difference and counts normalised.ids === 1.
    • "pairs a surviving id by its mapping when a removal shifts its position" (review follow-up): [101,102] vs [2] reports only the length difference, with no false /ids/0, and counts normalised.ids === 1.
    • "reports a replaced id as a value change, not an order change, when one survivor shifts" (review follow-up): [101,102] vs [2,9] reports only /ids/0 (101 vs 9), with no order.
    • "still reports an order change when two mapped survivors are reordered": [101,102,103] vs [2,1,99] reports order plus /ids/2.
  • Base reproduction (executed): with environmentCompareDiff.ts reverted, 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 heavy toolSchemaValidity boundary 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. knip reports nothing for the touched module.

Compatibility, safety, and release

  • Breaking changes or migration steps: none. Only false-positive id-list differences stop being reported; genuine differences and non-id arrays are unchanged.
  • Real Hopper/Ghidra, browser, or OS coverage: not applicable (pure comparison function). Linux only.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: no new reads, execution, or network access.

Author readiness

Human owner: @mhamzasakhi

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

Review follow-up

aaf70d26e3 preserves 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, and check:ci:fast passed.

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 575723440a checks for forced pairs across maximum matchings, including alternatives that use spare entries. For live [1,2] and recorded [3,2] with learned mappings 1→2 and 2→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 7f0c5fdb53 also 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, and check:ci:fast.

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.
@greptile-apps

greptile-apps Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5 Tier: plus

[Low impact] The reviewed changes appear safe to merge; no blocking issues were found.

Summary

This PR fixes ID-list comparisons so renamed survivors do not appear as value changes, while real replacements and reorders remain visible.

  • Mapped ID lists show only entries that really changed.
  • ID-list order appears only when surviving matches prove it changed.

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 main snapshot predates the PR base. Tests were not rerun.

Reviews (6) · Last reviewed commit: "fix(environment): detect complete duplic..." · Reviewed by Greptile

@mhamzasakhi
mhamzasakhi marked this pull request as ready for review October 26, 2026 11:14
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-19T15:12:47.289018Z 7f0c5fd New commits
ℹ️ 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.

@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: 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.

@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

const envOrder = pairs.map(([, right]) => right);
if (
envOrder.some((right, index) => index > 0 && right < envOrder[index - 1]!)

P2 Badge Restrict order checks to identity-matched survivors

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.
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@mhamzasakhi

Copy link
Copy Markdown
Contributor Author

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).

  • Root cause: #idListPairs appended a positional fallback pair for the replaced id, and the order check read every pair. With a single surviving identity (102→2), the fallback [0,1] made envOrder [1,0] and added a spurious order, although one identity cannot establish a relative-order change.
  • Fix: #idListPairs returns the identity-matched survivor pairs (ordered) separately from the full pairs; order is computed from ordered alone, before the positional fallbacks, which are value replacements rather than the same item in a new position.
  • Validation: [101,102] vs [2,9] now reports only /ids/0 (101 vs 9), no order, ids=1; [101,102,103] vs [2,1,99] still reports order (two survivors swapped) plus /ids/2. Two regression tests were added; the first fails on the previous commit. The 60 compare/environment test files pass (1518 tests); check:fast passes.

On CI: the red checks are a single unrelated test, pcapWorkspaceAllocation (ENOTDIR workspace handling, from #6229). It passes locally on this branch and on main; the CI runner returns "Private runtime parent is not a directory" instead of a raw ENOTDIR, so it looks like a runner-environment difference rather than a defect in this change.

@CassieFox23

Copy link
Copy Markdown
Contributor

TL;DR: I ran the PR's test file on three Node versions at head 820fdb2, and all 73 tests passed. With environmentCompareDiff.ts swapped back to the old version, 5 tests failed on all three. CI on that head has three failed test jobs, failing in test files this PR did not change, and the PR body's counts look out of date.

Check Node 22.23.4 Node 24.22.1 Node 26.12.1
Head 820fdb2 pass: 1 file, 73 tests pass: 1 file, 73 tests pass: 1 file, 73 tests
Red run (fix removed) fail: 5 failed, 68 passed fail: 5 failed, 68 passed fail: 5 failed, 68 passed
  • The red run means the head's test file run against src/application/environment/environmentCompareDiff.ts from a174892, the merge base (where the branch left main).
  • In the Node 24.22.1 log, the failures include maps each id when one element genuinely changed, reporting only the real change, maps the surviving ids when the list length also differs, pairs a surviving id by its mapping when a removal shifts its position and reports a replaced id as a value change, not an order change, when one survivor shifts.
  • So these 5 tests fail without the fix and pass with it.
  • The PR body says "70 passed" and "With the fix reverted: the two new tests fail." (PR body line 62). At 820fdb2 I see 73 passed, and 5 failures with the fix reverted. The body's counts look older than the head.
  • On 820fdb2 (run of 27 Oct), the CI checks Source tests, Portable tests and Test shard (7/8) failed, so CI required failed. 7 other shards were cancelled. A shard is one slice of the test suite.
  • The failures are in 6 test files, and this PR changed none of them. Two examples are src/domain/apple/appleApplication.test.ts and tests/boundary/filesystem/clientConfigurationBom.test.ts.
  • The head is 1,236 commits behind main b81da90. GitHub says the PR is mergeable, and its merge state is blocked.
  • One idea: update the body's counts. Then merge main and rerun CI, to see if those unrelated failures clear.

Not run

  • The 6 test files that failed in CI.
  • A merge with current main, b81da90.
Test setup
  • Box: Fedora 44 VM (4 vCPUs, 8 GB) on my Nobara 44 PC, Linux 7.2.11
  • Node: 22.23.4, 24.22.1, 26.12.1
  • Head / base: 820fdb2 / a174892 (merge base with main)
  • Red run: 820fdb2 with src/application/environment/environmentCompareDiff.ts from a174892
  • Install: npm ci --offline and npm run test:prepare on Node 24.22.1, exit 0, for both trees
Commands
npm 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 🦊

@mhamzasakhi

Copy link
Copy Markdown
Contributor Author

Merged current main into the branch to refresh it (it had drifted ~2 weeks). The earlier CI failures were from the stale base, not this change: the failing appleApplication / providerBinding bundle-root tests are unrelated to the environment-compare logic here and now pass after the merge.

Verified locally on the merged head (Ubuntu x64, Node 24.22.1): environmentCompareDiff.test.ts (all 73), plus the previously-failing appleApplication.test.ts and providerBinding.test.ts, all pass; check:fast passes. No conflicts; the compare area was untouched on main. Ready for another CI run whenever convenient.

@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: 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".

@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: 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".

@morluto
morluto enabled auto-merge (squash) November 19, 2026 15:08
@morluto
morluto merged commit 6a782c3 into morluto:main Nov 19, 2026
40 checks passed
@morluto morluto added bug Something isn't working area: setup Setup, packaging, upgrade, install, Doctor, and client registration labels Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: setup Setup, packaging, upgrade, install, Doctor, and client registration bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants