{"record":{"id":"b02e79ea9a681013","repo":"BigPizzaV3/CodexPlusPlus","slug":"expected-one-callback-binding","errorCode":null,"errorMessage":"Expected one callback binding","messagePattern":"Expected one callback binding","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codex-plus-core/src/native_browser.rs","lineNumber":264,"sourceCode":"        }\n    })();\n    if result.is_err() {\n        let _ = fs::remove_file(&temp);\n    }\n    result\n}\n\nfn transform(source: &[u8], control: &Path, contract: &RuntimeContract) -> Result<Vec<u8>> {\n    ensure!(\n        sha(source) == contract.service_sha,\n        \"Unsupported native browser service hash\"\n    );\n    transform_binding(source, control)\n}\n\nfn transform_binding(source: &[u8], control: &Path) -> Result<Vec<u8>> {\n    let text = std::str::from_utf8(source)?;\n    ensure!(\n        text.matches(ANCHOR).count() == 1,\n        \"Expected one callback binding\"\n    );\n    ensure!(\n        !text.contains(\"cppNativeIdentificationReader\"),\n        \"Conflicting adapter\"\n    );\n    let path = serde_json::to_string(&control.to_str().context(\"Non-Unicode control path\")?)?;\n    let replacement = format!(\n        \"new nf(r,this.clientApi,()=>ze(this.runtime),this.turnEndedTracker,cppNativeIdentificationReader(this.runtime,cD,ze,{path}))\"\n    );\n    Ok(format!(\"{}\\n{HELPER}\", text.replacen(ANCHOR, &replacement, 1)).into_bytes())\n}\n\nfn selected_key(descriptor: &Value, root: &Path) -> Result<String> {\n    let server = &descriptor[\"mcpServers\"][\"cua_repl\"];\n    let node = PathBuf::from(\n        server[\"command\"]","sourceCodeStart":246,"sourceCodeEnd":282,"githubUrl":"https://github.com/BigPizzaV3/CodexPlusPlus/blob/b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6/crates/codex-plus-core/src/native_browser.rs#L246-L282","documentation":"transform_binding rewrites a pinned bundled browser-service script by replacing a single known callback-binding anchor string with an instrumented adapter. This error is thrown when the anchor string ANCHOR ('new nf(r,...,cD)') is not found exactly once in the source — zero occurrences means the service file has already been transformed or replaced by a different version, and multiple occurrences mean an unexpected bundle layout. It is a pre-flight invariant check so the blind string replacement never corrupts the file.","triggerScenarios":"Calling transform/transform_binding on a browser-service.mjs whose text contains 0 or 2+ matches of the anchor: (1) the service hash check passed but the bundle internally differs, (2) transform was run twice so the anchor was already replaced, (3) an upstream bundle update changed the minified identifier 'nf'/'cD' while still matching the pinned SHA file.","commonSituations":"Applying the opt-in adaptation twice to the same install; a partial/failed previous transform left modified content; upstream Codex shipped a new browser-desktop bundle version that the pinned SHA catalog has not caught up with; hand-edited or vendor-patched service file.","solutions":["Check whether the file was already transformed: if it contains 'cppNativeIdentificationReader', restore the original bundled service file before re-running transform.","Restore the pristine service file matching ORIGINAL_SHA (reinstall/repair the Codex bundled plugin cache) and retry.","If a newer upstream bundle legitimately changed, update ANCHOR and the pinned SHA contract in native_browser.rs rather than editing the file by hand.","Enable debug logging of matches(ANCHOR).count() to confirm whether it is 0 (already transformed/missing) or >1 (bundle drift)."],"exampleFix":"// before: blindly re-applying to an already-adapted file\ntransform(source, control, &contract)?;\n// after: detect prior adaptation and restore original first\nif text.contains(\"cppNativeIdentificationReader\") {\n    source = restore_original_service()?; // or skip: already adapted\n}\ntransform(source, control, &contract)?;","handlingStrategy":"validation","validationCode":"let text = std::fs::read_to_string(&service_path)?;\nif text.matches(ANCHOR).count() != 1 {\n    // already transformed (0) or bundle drift (>1): restore original before applying\n    restore_original_service(&service_path)?;\n}","typeGuard":"fn is_transformable(source: &[u8]) -> bool {\n    std::str::from_utf8(source)\n        .map(|t| t.matches(ANCHOR).count() == 1 && !t.contains(\"cppNativeIdentificationReader\"))\n        .unwrap_or(false)\n}","tryCatchPattern":"match transform(source, control, &contract) {\n    Ok(patched) => install(patched),\n    Err(e) if e.to_string().contains(\"Expected one callback binding\") => {\n        restore_original_service()?; // then retry once\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Always restore the pristine bundled service before re-applying the adaptation","Check the tool's adaptation status instead of re-running apply blindly","Pin the Codex plugin version so the bundle cannot drift under the pinned SHA contract","After upstream updates, verify the service SHA before transforming"],"tags":["rust","transform","invariant-violation","bundle-drift"],"backgroundTag":"internal-invariant-violation","analyzedSha":"b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6","analyzedAt":"2026-09-19T23:35:21.129Z","contentChangedAt":"2026-09-19T23:35:21.129Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}