Skip to content

Comments

js_repl: block wrapped payload prefixes in grammar#12300

Merged
fjord-oai merged 1 commit intomainfrom
fjord/js_repl_seq---4ht_g82psfv2f9
Feb 20, 2026
Merged

js_repl: block wrapped payload prefixes in grammar#12300
fjord-oai merged 1 commit intomainfrom
fjord/js_repl_seq---4ht_g82psfv2f9

Conversation

@fjord-oai
Copy link
Contributor

@fjord-oai fjord-oai commented Feb 20, 2026

Summary

Tighten the js_repl freeform Lark grammar to block the most common malformed payload wrappers before they reach runtime validation.

What Changed

  • Replaced the overly permissive js_repl freeform grammar (start: /[\s\S]*/) with a structured grammar that still supports:
    • plain JS source
    • optional first-line // codex-js-repl: pragma followed by JS source
  • Added grammar-level filtering for common bad payload shapes by rejecting inputs whose first significant token starts with:
    • { (JSON object wrapper like {"code":"..."})
    • " (quoted code string)
    • ``` (markdown code fences)
  • Implemented the grammar without regex lookahead/lookbehind because the API-side Lark regex engine does not support look-around.
  • Added a unit test to validate the grammar shape and guard against reintroducing unsupported lookaround.

Why

js_repl is a freeform tool, but the model sometimes emits wrapped payloads (JSON, quoted strings, markdown fences) instead of raw JavaScript. We already reject those at runtime, but this change moves the constraint into the tool grammar so the model is less likely to generate invalid tool-call payloads in the first place.

Testing

  • cargo test -p codex-core js_repl_freeform_grammar_blocks_common_non_js_prefixes
  • cargo test -p codex-core parse_freeform_args_rejects_

Notes

  • This intentionally over-blocks a few uncommon valid JS starts (for example top-level { ... } blocks or top-level quoted directives like "use strict";) in exchange for preventing the common wrapped-payload mistakes.

git stack

git-stack-id: fjord/js_repl_seq---4ht_g82psfv2f9
git-stack-title: js_repl: block wrapped payload prefixes in grammar
@fjord-oai fjord-oai force-pushed the fjord/js_repl_seq---4ht_g82psfv2f9 branch from 4de6129 to 121f96e Compare February 20, 2026 15:48
@fjord-oai fjord-oai merged commit 73fd939 into main Feb 20, 2026
53 of 55 checks passed
@fjord-oai fjord-oai deleted the fjord/js_repl_seq---4ht_g82psfv2f9 branch February 20, 2026 18:47
@github-actions github-actions bot locked and limited conversation to collaborators Feb 20, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants