← Back to Pull requests

Prefix remaining template variables that can clash with user-defined names (Optional follow-up to #1908) #1910

Closed
unknown closed this pull request without merging on Oct 30, 2026 09:23 UTC
View on GitHub
unknown unknown commented on Oct 29, 2026 13:54 UTC
Author

Follow-up to #1908, as offered in #1906: I went through the other code generation templates and looked for local variables without a leading underscore in templates that contain user code. Three more clash with user-defined names:

| Template | Name | What happened |
|---|---|---|
| Cython synapses_create_generator.pyx | newsize, oldsize | connect(condition="j < newsize") with newsize in the namespace failed to compile and silently created 0 synapses (#1898) |
| C++ synapses_create_generator.cpp | newsize | Same expression: compile error redefinition of 'newsize' with a different type |
| Cython summed_variable.pyx | vectorisation_idx | The template assigned vectorisation_idx = _idx, while every other Cython template uses _vectorisation_idx = _idx. A constant called vectorisation_idx in a summed variable was overwritten ([10.] instead of [20.] in the example below), and _vectorisation_idx stayed at 1 inside the loop |

This PR renames them to _newsize, _oldsize and _vectorisation_idx. The remaining unprefixed names are either in helper functions or support code that never contains user code (e.g. data_ptr in _flush_buffer, objects.cpp, network.cpp), or in templates without user expressions (synapses_push_spikes.pyx, synapses_create_array.cpp), so I left them alone to keep this focused. Happy to prefix those too for consistency if you prefer.

Test

New test_connect_and_summed_names_of_template_variables in test_synapses.py, next to the test from #1908 (standalone compatible): connect(condition="j < newsize"), connect(j="k for k in range(oldsize)"), and a summed variable x_pre * vectorisation_idx, with those names in the namespace.

On macOS (arm64, Apple clang 21.0.0, Python 3.13.15, Cython 3.3.0, numpy 2.5.4):

  • Without the template changes: passes on numpy; fails on cython (assert 0 == 10) and on cpp_standalone (redefinition of 'newsize').

  • With the changes: passes on numpy, cython and cpp_standalone.

  • Tests matching synapse or summed or connect or subgroup (including long tests) on numpy, cython and cpp_standalone: all passed (numpy 118, cython 116 + 2 skipped, cpp_standalone 91 + 4 standalone-specific).

  • ruff format --check (v0.14.2) reports no changes.
  • Before (on master) and after (this branch), running connect(condition="j < newsize"), connect(j="k for k in range(oldsize)") and the summed variable from the test:

    <img width="1702" height="602" alt="image" src="https://github.com/user-attachments/assets/619b9116-6b39-4878-94d3-c9a283450f73" />

    after:

    <img width="1684" height="358" alt="image" src="https://github.com/user-attachments/assets/d87a8b83-ee0f-4b1c-a3a0-c299e7231c9c" />

    Diff: 343 lines (+257 / -86) across 4 files Reviewer: mstimberg Review duration: 1168m
    All Vouch review confidence checks passed
    Residual risk 0.17 = Change Risk (0.42) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.42 · 343 lines diff across 4 files
    0.42
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.349
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #1910"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 42.3% (MEDIUM) · Higher = larger blast radius
    42.3%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 16.7% · Safe to merge
    16.7%