Skip to content

test(go): assert the region-index comparison count, not just table reads - #10619

Closed
2SinceJuly wants to merge 5 commits into
morluto:mainfrom
2SinceJuly:fix/10513-wall-clock-test-bounds
Closed

2SinceJuly wants to merge 5 commits into
morluto:mainfrom
2SinceJuly:fix/10513-wall-clock-test-bounds

Conversation

@2SinceJuly

@2SinceJuly 2SinceJuly commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Three tests bounded their behavior by elapsed wall-clock time, so a loaded CI
shard could fail them without a regression. Each now asserts the deterministic
work it actually cares about.

Refs #10513. This is a first slice: roughly 62 further bounds in that issue stay
untouched.

Problem and expected behavior

expect(performance.now() - started).toBeLessThan(N) measures the runner, not
the code. The issue records a case (#5050) where such a bound failed on a
loaded shard with no change in behavior, and a 5 s pyc bound that ran in ~0.5 s
locally but 4–7 s on CI.

Expected: each of these cases fails when the work it guards grows, and does not
fail merely because the host is busy.

Change and scope

Main now bounds this test by container table reads (#11610), but that cannot
see a linear scan inside createReadableLoadRegionIndex: the region bounds are
copied into starts/ends before searching, so the table counters stay at
25,000 region and 50,000 section reads however the search is written.

  • src/go/GoStringLiterals.ts — recoverGoStringLiterals and
    lastBigIntAtOrBelow take an optional countWork callback and call it once
    per comparison.
  • src/go/GoStringLiterals.test.ts — the indexed-literals case passes that
    callback and asserts the merged-bound search stays within count * 32
    comparisons. Replacing the binary search with a linear scan reaches
    312,562,500 comparisons against an 800,000 bound.

Main's version of the two desktop cases (selectorCandidates,
appTaskDraftValues) superseded this earlier slice, so they are unchanged here.

No user-visible production behavior changed.

Contract and boundary impact

  • Semantic owner and earliest changed stage: not applicable; test-only.
  • Contribution scope fit and linked maintainer decision: within existing test
    guidance in docs/development/testing.md ("a test deadline … is not a
    performance assertion"). No new capability.
  • CLI and MCP/tool-catalog contract: none.
  • Provider, bridge, target-format, or platform compatibility: none.
  • Evidence, artifact, provenance, or reconstruction contract: none.
  • Target selection, authority, upstream behavior, and cleanup details: not applicable.
  • Generated metadata, package, or installation impact: none.

Expected effects:

  • 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 or updated: the three files above.
  • Base reproduction or other evidence: each new assertion was re-run against a
    deliberately regressed source and failed there, then passed again once the
    source was restored:
    • removing the MAX_CHILD_TEXT early return in shortText → the 65-unit
      bound failed;
    • adding an element read per region inside the region sort → 624,975,000
      reads against the count * 4 bound, failed;
    • the deleted bound needs no regression: the surrounding refers_to
      assertion is what fails if reference resolution breaks.
  • User-visible CLI/MCP output: none.
  • Remaining proof gaps: the other ~62 bounds in Replace wall-clock test bounds with deterministic work measures #10513 are unconverted.

Validation performed

  • npm run test:local -- src/domain/desktop/selectorCandidates.test.ts src/go/GoStringLiterals.test.ts src/domain/desktop/appTaskDraftValues.test.ts — 60 passed (3 files)
  • npm run check:fast — typecheck and lint succeeded
  • npx oxfmt --check <the three files> — all correctly formatted

Compatibility, safety, and release

  • Breaking changes or migration steps: none.
  • Real Hopper/Ghidra, browser, or OS coverage: not applicable.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: none.

Author readiness

Human owner: @2SinceJuly

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

Three tests bounded their behavior by wall-clock time, so a loaded CI
shard could fail them without a regression. Each now asserts the
deterministic work it actually cares about.

- `selectorCandidates` counts the code units `shortText` reads from the
  4 MiB text, which is exactly the read it bounds, and adds the
  under-limit case so the count is not satisfied by reading nothing.
- `GoStringLiterals` counts indexed load regions and sections through a
  Proxy, so an accidental quadratic rescan exceeds the bound rather than
  merely running slower.
- `appTaskDraftValues` drops the bound: the case already asserts the
  resolved references it produces.

Refs morluto#10513

The remaining ~62 bounds in the issue are untouched; this is the first
slice, one file per kind of measure.
@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

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

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-14T18:44:30.318704Z
We couldn’t complete this review. Comment @codex review to try again.
2ff006f PR opened
ℹ️ About Codex in GitHub

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

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

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

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

@greptile-apps

greptile-apps Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Low impact] The PR appears safe to merge, with no outstanding findings.

Summary

Adds a comparison-count guard for the Go readable-region search.

  • Go string-literal tests count region-search work directly.

Reviews (5) · Last reviewed commit: "Merge remote-tracking branch 'origin/mai..." · Reviewed by Greptile

Comment thread src/go/GoStringLiterals.test.ts Resolved
The bounded-work assertion only observed reads on the original
load_regions and sections arrays. createReadableLoadRegionIndex copies
region bounds into starts/ends before searching them, so replacing the
binary search in contains with a linear scan stayed invisible: the
counters still reported 25,000 region reads and 50,000 section reads
while the search went quadratic.

Thread an optional work counter through lastBigIntAtOrBelow and assert
the merged-bound search stays within count * 32 comparisons. The linear
scan now fails with 312,562,500 comparisons against an 800,000 bound.
@2SinceJuly

Copy link
Copy Markdown
Contributor Author

Status: rebased? No — this is green as-is on its current base (all required checks pass, no conflicts), so nothing on my side is pending.

One piece of information that may be useful for the merge decision: the three rewritten assertions verify the bounded work directly rather than the clock, so they cannot go red from a loaded shard. That is the concrete difference from the remaining ~62 bounds in #10513 — those still can.

Question: is this first slice small enough to merge on its own, or would you rather I hold it until the rest of #10513 is reduced? I'm happy to keep it at 3 files and land the remainder separately.

main already replaced all three wall-clock assertions with counted-work
bounds, so keep its stronger versions and drop this branch's overlapping
test rewrites; the countWork hook in GoStringLiterals stays.
The 11-15 merge into this branch resolved the test half of this change to
main's version, leaving `countWork` threaded through
`recoverGoStringLiterals` and `lastBigIntAtOrBelow` with no caller and no
assertion.

Main's replacement bounds container table reads, which still cannot see a
linear scan inside `createReadableLoadRegionIndex`: the region bounds are
copied into `starts`/`ends` before searching, so those counters stay flat
however the search is written. Count comparisons instead and assert the
merged-bound search stays within `count * 32`; the linear scan reaches
312,562,500 comparisons against an 800,000 bound.
@2SinceJuly 2SinceJuly changed the title test: assert bounded work instead of elapsed time in three bounds test(go): assert the region-index comparison count, not just table reads Nov 17, 2026
@2SinceJuly

Copy link
Copy Markdown
Contributor Author

Re-checked this one against main and found the branch had been hollowed out by its own merge: 442ac7bec resolved the test files to main's versions, so the PR had been reduced to an unused countWork parameter — the source threaded a counter through with no caller and no assertion. The PR description described three test changes that were no longer in the diff.

Fixed in 23947fb59. Main's newer bound (#11610, container table reads) is now kept as-is, and this PR only adds what it cannot see: recoverGoStringLiterals copies the region bounds into starts/ends before searching, so the table counters stay at 25,000 region and 50,000 section reads no matter how contains searches them. The new assertion counts comparisons through lastBigIntAtOrBelow and bounds them at count * 32.

Verified locally: GoStringLiterals.test.ts 28/28 pass; making lastBigIntAtOrBelow record six times per comparison fails exactly this test (1 failed, 27 passed), so the bound does catch a search that stops being logarithmic. npm run check:fast passes. CI is re-running on the new head — the earlier green run was for the version without this assertion.

Scope is now one file's test plus the counter parameter, no production behavior change. If you'd rather take the comparison bound in a different form, say which and I'll reshape it.

Comment thread src/go/GoStringLiterals.test.ts Resolved
@2SinceJuly

Copy link
Copy Markdown
Contributor Author

Found and fixed a real break on this branch, and trimmed what main had already absorbed.

The break. greptile flagged this at 10:57Z and was right: src/go/GoStringLiterals.test.ts sets on_disk and macho_cpu_type in fixture literals, but neither field exists in the ImageSection/BinaryContainer types at this branch's commit. tsc reports four TS2353 errors. CI did not catch it because the typecheck lane is skipped for this change classification — only Portable tests / Test shard / CI required run here, and none of those typecheck the test file.

Why it happened. Those two fields landed on main in 637e4cb60 (feat(native): inspect DWARF compile units offline, 2026-11-17 10:04Z). This branch was based on a10037ef1, before that.

What I changed. Merged current main in (f4a9c1051, fast-forward push, no history rewritten) and dropped the slices main had already resolved. The two desktop bounds (appTaskDraftValues.test.ts, selectorCandidates.test.ts) no longer use wall-clock on main at all, so this PR no longer touches them.

What remains is the one piece main still cannot see: main counts container table reads, but those counters stay flat for a regression inside createReadableLoadRegionIndex, because the region bounds are copied into starts/ends before searching. The branch threads a work counter through the binary search and asserts the lookup stays within count * 32 comparisons over 25,000 regions.

Verification (on the merged tree, f4a9c1051):

  • npm run test:focused -- src/go/GoStringLiterals.test.ts — 28 passed.
  • npm run check:fast — typecheck, lint and architecture guards pass (the four TS2353 errors are gone).
  • I also checked the assertion actually bites: replacing lastBigIntAtOrBelow with a linear scan makes exactly one test fail. Green here is not vacuous.

Diff is now +55/−5 across two files. Roughly 62 other bounds in #10513 remain untouched.

@N0zoM1z0

Copy link
Copy Markdown
Collaborator

Thanks. Closing as superseded: src/go/GoStringLiterals.test.ts on main no longer uses wall-clock bounds. It already asserts deterministic work (observedRegions and observedSections below the record count), and #10513 is closed. With that gone, the remaining change would add a test-only countWork hook to recoverGoStringLiterals' public signature, which isn't needed for the current assertions.

@N0zoM1z0 N0zoM1z0 closed this Nov 21, 2026
@morluto morluto added the area: tests Test suite and verification label Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: tests Test suite and verification

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants