Skip to content

Recount harness: bind the loader's msgs the history restore now estimates from - #12747

Merged
danielhanchen merged 2 commits into
mainfrom
ci-recount-estimate
Oct 5, 2026
Merged

danielhanchen merged 2 commits into
mainfrom
ci-recount-estimate

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Summary

Repo tests (CPU, studio) is red on main and on every PR based on it (for example #12739 and #12744). Five cases in tests/studio/test_new_chat_context_recount.py fail with:

ReferenceError: msgs is not defined
    at hydrateThreadUsage (harness.ts:8819)

Cause

#9475 (show estimated context usage before model load) changed the history loader's restore to

const shownUsage = restoredUsage ?? estimateContextUsage(msgs);

The product change is intended: a reopened thread with no usable saved usage now shows a text estimate right away instead of an empty bar until the recount answers. The test is what is behind. It slices that block out of runtime-provider.tsx and replays it inside hydrateThreadUsage, which declares the loader's other locals (remoteId, savedUsage, store, ...) but never msgs. Imported helpers such as estimateContextUsage are followed in automatically by run_harness; loader locals are not.

Changes

  • hydrateThreadUsage binds msgs from props.messages (empty by default, so the existing cases keep their expectations).
  • New test_history_hydration_shows_an_estimate_until_the_recount_lands pins what feat(studio): show estimated context usage before model load #9475 added. While the recount is held, the bar shows the estimate (100 tokens for 400 characters, estimated: true) when nothing saved is usable. The recount's exact count then replaces it. Saved usage for the loaded model is shown as is and is not recounted.
  • New test_the_harness_binds_every_loader_local_the_history_restore_reads: reads the locals declared in load() above the slice and fails if the block reads one that hydrateThreadUsage does not declare, so the next local the block starts reading fails with its name rather than as a ReferenceError inside a pricing assertion.

Verification

  • Main (0108742f1e): 5 failed, 54 passed. This branch: 63 passed.
  • Removing the msgs binding fails the new guard and the estimate cases, plus the five original cases.
  • Replacing restoredUsage ?? estimateContextUsage(msgs) with restoredUsage in the product fails the two estimate cases.

…estimates from

#9475 made the history restore fall back to estimateContextUsage(msgs) when no saved
usage is usable. The harness replays that block inside hydrateThreadUsage, which never
declared msgs, so every history-hydration case threw 'msgs is not defined' on main.

Bind msgs from props, pin the estimate-then-recount behaviour, and guard that every
loader local the sliced block reads is declared by the harness.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

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

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-05T17:19:58.995445Z 331fb07 Manual request
ℹ️ 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.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 5, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@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: 465d4b16b0

ℹ️ 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".

start = provider.index(restore)
loader = provider.rindex("async load() {", 0, start)
above = provider[loader:start]
declared_above = set(re.findall(r"\b(?:const|let)\s+([A-Za-z_$][\w$]*)", above))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Include destructured locals in the binding guard

This declaration regex only recognizes simple bindings such as const msgs, so the guard does not actually cover every loader local: the existing const { remoteId } = ... is already read by the sliced restore block but absent from declared_above. If a future restore change reads another destructured loader local, the new test will pass while hydrateThreadUsage still throws a ReferenceError; collect object/array destructuring bindings as well.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, the guard missed destructured locals, so remoteId was never actually checked. Fixed in 331fb07: it now collects object and array destructuring names (with a small test of its own) and requires seeing both msgs and remoteId. Renaming the harness's remoteId binding now fails the guard by name.

The binding guard only collected 'const name' declarations, so a destructured loader
local such as remoteId was never checked. Collect object and array destructuring
names as well, and require the guard to see remoteId.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

Reviewed commit: 331fb07a92

ℹ️ 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".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant