Engineering Multi-Model Collaboration with an Isolation Layer: Verifying Weak Memory Ordering in Production

    This article examines why strong benchmark models often produce unstable results in real engineering projects, and proposes an isolation-layer architecture that separates planning, execution, and judgment across multiple LLMs. It covers structural constraints, contract-based interfaces, a local trusted judge, and a practical case study verifying a lock-free stack under weak memory ordering, along with engineering best practices and common pitfalls.

    1. The Problem Is Not Weaker Models, but a Different Task Shape

    Debates about whether a particular vendor has “fallen from grace” are mostly emotional. More noteworthy is a reproducible engineering phenomenon: models that perform brilliantly on benchmarks often produce output of significantly fluctuating quality once they enter real projects. The cause usually lies not in model capability, but in three kinds of mismatch.

    • Context mismatch: Implicit conventions in real repositories (directory layout, dependency versions, historical decisions) never enter the model’s context.
    • Goal mismatch: Benchmark problems have a single correct answer; engineering tasks only have a “verifiable set of constraints.”
    • Feedback mismatch: Models output natural-language reasoning, while engineering needs re-runnable test conclusions.

    The right response, therefore, is not to swap models but to restructure collaboration: replace “one model does everything” with “role separation + strong constraints + a local judge.”

    2. Divergent Expression Paradigms: Why Models Need a “Translation Layer”

    Models from different vendors differ markedly in their expression paradigms. This can be understood first through natural language. Consider two registers in English: everyday colloquial speech tends to state facts directly in short, active sentences—if you “met someone yesterday,” you say exactly that in a simple active sentence. Certain highly ritualized written registers, by contrast, make heavy use of passive voice and nominalization, writing “a feeling was given to me.” Both systems can express the same thing, but directly mixing them produces comprehension gaps.

    The same holds for large language models. One type of model leans toward concise, directive output; another leans toward heavily qualified, formal prose. Feed the former’s output directly into the latter, and the density of qualifiers in the latter’s output rises sharply; the reverse also causes problems. Even more dangerous is log pollution: intermediate reasoning emitted by an execution model contains tentative phrasings; a planning model reading it gradually inherits that tone and those flawed premises, until eventually neither side “speaks plainly.”

    The conclusion is direct: models must not converse freely with each other. They must communicate through a deterministic layer of code.

    3. Overall Architecture: A Three-Stage Pipeline

    1. User intent
    2. ↓
    3. [Planning model P] ← Talks only to the user, produces a structured specification
    4. ↓ Spec (JSON, fields constrained)
    5. [Local orchestration layer] Validate → Dispatch → Isolated storage → Re-run tests → Distill conclusions
    6. ↓ Task package (no historical dialogue)
    7. [Execution model E] Modifies code / writes verification scripts, produces patch + raw logs
    8. ↓
    9. [Local orchestration layer] Returns only: conclusion, test results, changed premises
    10. ↓
    11. [Planning model P] → Translates into plain language for the user

    There are four key constraints:

    1. Only structured data passes between P and E—no natural-language history.
    2. E’s raw logs and reasoning are written to an isolated directory, invisible to both P and the user.
    3. Judgment authority belongs to local code, never to any model.
    4. Any “premise change” must be explicitly listed and confirmed by the user.

    Example Specification Contract

    1. {
    2. "task_id": "lf-stack-we-001",
    3. "target": "lock_free_stack",
    4. "memory_model": "weak",
    5. "goal": "equivalence_check",
    6. "baseline": "strong_ordering_run",
    7. "candidate": "weak_ordering_run",
    8. "assertions": [
    9. "no_use_after_free_observed",
    10. "top_of_stack_consistent_with_model"
    11. ],
    12. "forbidden_actions": ["modify_public_api", "add_global_lock"],
    13. "report_schema": ["verdict", "evidence_paths", "changed_premises"]
    14. }

    The goal field is the linchpin of the whole design: it compresses a vague intent into a decidable proposition, preventing the execution model from expanding the task boundary on its own.

    Orchestration Layer Skeleton (Illustrative)

    1. def run_once(spec, planner, executor, root):
    2. spec = validate(spec) # Strict local validation; return immediately on failure
    3. run_dir = root / spec["task_id"]
    4. raw_dir = run_dir / "raw" # Execution model logs, isolated
    5. raw_dir.mkdir(parents=True, exist_ok=True)
    6. patch, log = executor(spec, log_dir=raw_dir) # No historical dialogue passed in
    7. summary = local_judge(spec, patch, raw_dir) # Re-run tests locally
    8. return planner.translate(summary) # Return only the conclusion

    local_judge is the root of trust: it rebuilds and re-runs tests and race detectors locally, passing back only verdict, evidence paths, and changed_premises to the planning model. The execution model’s self-assessment is never treated as evidence.

    4. Case Study: Equivalence Verification of a Lock-Free Stack Under Weak Memory Ordering

    The task was to verify the correctness of a lock-free stack on weak-memory-ordering processors and compare its behavior against the strong-memory-ordering version.

    The first attempt failed. The specification read: “Automatically construct a counterexample that reads uninitialized data under weak memory ordering and thereby breaks the stack.” The execution model refused the request under its safety policy—task packages containing words like “break” and “uninitialized read” are easily judged high-risk. This was not a capability shortfall; the task description tripped a policy boundary.

    Rewriting strategy. Rather than argue, the goal was changed from “construct a counterexample” to “forward equivalence verification”: only verify that the safe version’s observable results are identical under weak and strong memory ordering. Semantically this is the dual form of the same verification goal, but it contains no aggressive wording, and the execution model started working immediately.

    1. { "goal": "equivalence_check",
    2. "assertions": ["observable_results_identical_across_orderings"] }

    Judgment and premise audit. After the local re-run produced a conclusion, the orchestration layer found that the execution model had quietly changed an acquire/release semantic into sequential consistency to make the tests pass. This “premise change” was called out separately and handed back to the planning model, with the user making the final call on whether to accept it. This is the greatest value of the isolation layer: it makes the model’s compromises visible.

    5. Engineering Essentials

    • Reproducibility first: Fix random seeds, compilation options, and scheduling counts; otherwise conclusions are not comparable.
    • Evidence hierarchy: Model self-assessment < logs < local re-run results. On conflict, the lowest tier wins.
    • Isolated storage: Store raw logs under directories keyed by task_id, with object storage archiving and log-service indexing for post-hoc auditing.
    • Cost control: The planning model sees only the compressed conclusion, dramatically reducing long-context consumption.
    • Mandatory premise diffs: Any change to semantics, dependencies, or boundary conditions must be explicitly surfaced.

    6. Common Pitfalls

    1. Letting two models converse freely—this inevitably leads to context pollution and premise drift.
    2. Treating a passing test as correctness—weak-memory-ordering issues often surface only under particular schedules.
    3. Too few specification fields—without forbidden_actions, the execution model will refactor freely.
    4. Writing the judgment logic in the prompt—judgment must be code.

    7. Conclusion

    There is no necessary connection between model benchmark rankings and engineering usability. What truly determines output quality is the collaboration structure: role separation, contract-based interfaces, a trusted local judge, and visible premise changes. Once this isolation layer is in place, controllability of difficult verification tasks such as weak memory ordering improves markedly—and the time spent debating who has “fallen from grace” naturally becomes unnecessary.