Skip to content

Persist initialized js_repl bindings after failed cells#13482

Merged
fjord-oai merged 1 commit intomainfrom
fjord/codex_variables
Mar 5, 2026
Merged

Persist initialized js_repl bindings after failed cells#13482
fjord-oai merged 1 commit intomainfrom
fjord/codex_variables

Conversation

@fjord-oai
Copy link
Copy Markdown
Contributor

@fjord-oai fjord-oai commented Mar 4, 2026

Summary

  • Change js_repl failed-cell persistence so later cells keep prior bindings plus only the current-cell bindings whose initialization definitely completed before the throw.
  • Preserve initialized lexical bindings across failed cells via module-namespace readability, including top-level destructuring that partially succeeds before a later throw.
  • Preserve hoisted var and function bindings only when execution clearly reached their declaration site, and preserve direct top-level pre-declaration var writes and updates through explicit write-site markers.
  • Preserve top-level for...in / for...of var bindings when the loop body executes at least once, using a first-iteration guard to avoid per-iteration bookkeeping overhead.
  • Keep prior module state intact across link-time failures and evaluation failures before the prelude runs, while still allowing failed cells that already recreated prior bindings to persist updates to those existing bindings.
  • Hide internal commit hooks from user js_repl code after the prelude aliases them, so snippets cannot spoof committed bindings by calling the raw import.meta hooks directly.
  • Add focused regression coverage for the supported failed-cell behaviors and the intentionally unsupported boundaries.
  • Update js_repl docs and generated instructions to describe the new, narrower failed-cell persistence model.

Motivation

We saw js_repl drop bindings that had already been initialized successfully when a later statement in the same cell threw, for example:

const { context: liveContext, session } =
  await initializeGoogleSheetsLiveForTab(tab);
// later statement throws

That was surprising in practice because successful earlier work disappeared from the next cell.

This change makes failed-cell persistence more useful without trying to model every possible partially executed JavaScript edge case. The resulting behavior is narrower and easier to reason about:

  • prior bindings are always preserved
  • lexical bindings persist when their initialization completed before the throw
  • hoisted var / function bindings persist only when execution clearly reached their declaration or a supported top-level var write site
  • failed cells that already recreated prior bindings can persist writes to those existing bindings even if they introduce no new bindings

The detailed edge-case matrix stays in docs/js_repl.md. The model-facing project_doc guidance is intentionally shorter and focused on generation-relevant behavior.

Supported Failed-Cell Behavior

  • Prior bindings remain available after a failed cell.
  • Initialized lexical bindings remain available after a failed cell.
  • Top-level destructuring like const { a, b } = ... preserves names whose initialization completed before a later throw.
  • Hoisted function bindings persist when execution reached the declaration statement before the throw.
  • Direct top-level pre-declaration var writes and updates persist, for example:
    • x = 1
    • x += 1
    • x++
    • short-circuiting logical assignments only persist when the write branch actually runs
  • Non-empty top-level for...in / for...of var loops persist their loop bindings.
  • Failed cells can persist updates to existing carried bindings after the prelude has run, even when the cell commits no new bindings.
  • Link failures and eval failures before the prelude do not poison @prev.

Intentionally Unsupported Failed-Cell Cases

  • Hoisted function reads before the declaration, such as foo(); ...; function foo() {}
  • Aliasing or inference-based recovery from reads before declaration
  • Nested writes inside already-instrumented assignment RHS expressions
  • Destructuring-assignment recovery for hoisted var
  • Partial var destructuring recovery
  • Pre-declaration undefined reads for hoisted var
  • Empty top-level for...in / for...of loop vars
  • Nested or scope-sensitive pre-declaration var writes outside direct top-level expression statements
@fjord-oai
Copy link
Copy Markdown
Contributor Author

@codex review

Copy link
Copy Markdown
Contributor

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

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: 5d171d75b8

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

@fjord-oai
Copy link
Copy Markdown
Contributor Author

@codex review

Copy link
Copy Markdown
Contributor

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

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: ef3cf904c3

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

@fjord-oai
Copy link
Copy Markdown
Contributor Author

@codex review

Copy link
Copy Markdown
Contributor

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

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: 3e91ef4c43

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

@fjord-oai fjord-oai force-pushed the fjord/codex_variables branch from 9bd0222 to eb3efc7 Compare March 4, 2026 19:53
@fjord-oai
Copy link
Copy Markdown
Contributor Author

@codex review

Copy link
Copy Markdown
Contributor

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

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: eb3efc7419

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

@fjord-oai
Copy link
Copy Markdown
Contributor Author

@codex review

Copy link
Copy Markdown
Contributor

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

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: decab8f082

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

@fjord-oai fjord-oai force-pushed the fjord/codex_variables branch from decab8f to 47e5a09 Compare March 4, 2026 22:58
@fjord-oai
Copy link
Copy Markdown
Contributor Author

@codex review

Copy link
Copy Markdown
Contributor

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

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: 47e5a09213

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

@fjord-oai fjord-oai force-pushed the fjord/codex_variables branch 3 times, most recently from be936ec to 1df7ba7 Compare March 5, 2026 00:14
@fjord-oai
Copy link
Copy Markdown
Contributor Author

@codex review

Copy link
Copy Markdown
Contributor

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

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: 1df7ba79d6

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

@fjord-oai fjord-oai force-pushed the fjord/codex_variables branch from 1df7ba7 to 89b5dd4 Compare March 5, 2026 00:56
@fjord-oai
Copy link
Copy Markdown
Contributor Author

@codex review

Copy link
Copy Markdown
Contributor

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

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: 89b5dd4d3e

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

@fjord-oai fjord-oai force-pushed the fjord/codex_variables branch from 89b5dd4 to 3047d3f Compare March 5, 2026 01:18
@fjord-oai
Copy link
Copy Markdown
Contributor Author

@codex review

Copy link
Copy Markdown
Contributor

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

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: 3047d3f318

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

@fjord-oai fjord-oai force-pushed the fjord/codex_variables branch from 3047d3f to 6730786 Compare March 5, 2026 03:47
@fjord-oai
Copy link
Copy Markdown
Contributor Author

@codex review

Copy link
Copy Markdown
Contributor

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

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: 6730786b99

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

@fjord-oai fjord-oai force-pushed the fjord/codex_variables branch from 6730786 to 1cfa56b Compare March 5, 2026 04:15
@fjord-oai
Copy link
Copy Markdown
Contributor Author

@codex review

Copy link
Copy Markdown
Contributor

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

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: 1cfa56befa

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

@fjord-oai fjord-oai force-pushed the fjord/codex_variables branch from 1cfa56b to 9976e63 Compare March 5, 2026 04:29
@fjord-oai
Copy link
Copy Markdown
Contributor Author

@codex review

Copy link
Copy Markdown
Contributor

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

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: 9976e6347b

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

@fjord-oai fjord-oai force-pushed the fjord/codex_variables branch from 9976e63 to a0b4bd7 Compare March 5, 2026 04:40
@fjord-oai
Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown
Contributor

Codex Review: Didn't find any major issues. Swish!

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

@fjord-oai fjord-oai force-pushed the fjord/codex_variables branch 2 times, most recently from ded4bf7 to 450e596 Compare March 5, 2026 18:10
@fjord-oai fjord-oai force-pushed the fjord/codex_variables branch from 450e596 to 7c62fcf Compare March 5, 2026 18:42
@fjord-oai fjord-oai merged commit 657841e into main Mar 5, 2026
31 checks passed
@fjord-oai fjord-oai deleted the fjord/codex_variables branch March 5, 2026 19:01
@github-actions github-actions bot locked and limited conversation to collaborators Mar 5, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

2 participants