Hi, jumping in on your post. Like you, I’ve experienced serious drift with coding agents, not simply because the models were too small or had limited context windows, but because they began concealing whether they actually succeeded or failed, quietly introducing fallbacks, and discarding the guidelines established at the start of the project.
To solve this, I’ve been using a deterministic approach: Invariants + SHA-256 + External Probes.
The core idea is simple: at the start of a task, define architectural invariants inside a structured JSON file. Once written and verified, seal it with a SHA-256 hash. This completely prevents the LLM from silently editing its own constraints to hide its drift. During long sessions, an automated hook re-injects a lightweight checkpoint every 5 turns to re-anchor its attention without blowing the context window.
I typically back this up with a very strict, robust system prompt. For a 27B model, a heavy 3-page prompt would drown its reasoning buffer. Here is a stripped-down, lightweight version you can test locally:
- In the IDE / External Script (The Stick)
-
Keep invariants.json and its invariants.sha256 in your workspace.
-
Use a pre-commit hook or an execution runner that runs real ground-truth probes (cargo check, unit tests, negative grep checks for unauthorized process/socket patterns).
-
If the hash check fails or a probe exits with an error, the external runner injects the raw stderr directly into the model’s next turn: the model is hard-blocked by the OS, not by its own goodwill.
2. In the Model Prompt (The Carrot)
Example: invariants.json
{
"version": "1.0",
"project": "engine-core",
"invariants": [
{
"id": "INV-001",
"target": "runtime::inference",
"statement": "Inference runs strictly native; no spawned subprocesses or local HTTP/network calls.",
"type": "negative",
"probe": "! grep -rE '(Command::new|std::process|reqwest|http://|localhost)' src/core/",
"expected_exit_code": 0
},
{
"id": "INV-002",
"target": "engine::pipeline",
"statement": "Compiler and unit test harness validate the nominal path with zero regression.",
"type": "positive",
"probe": "cargo check --quiet && cargo test --test unit_pipeline -- --quiet",
"expected_exit_code": 0
},
{
"id": "INV-003",
"target": "error_handling",
"statement": "No silent error swallowing or default fallbacks in decoding routines.",
"type": "negative",
"probe": "! grep -rE '(unwrap_or|catch_unwind|\\?\\?)' src/decode/",
"expected_exit_code": 0
},
{
"id": "INV-004",
"target": "api::contract",
"statement": "Public execute() signature strictly matches the frozen interface definition.",
"type": "positive",
"probe": "grep -q 'pub fn execute(&mut self, ctx: &Context) -> Result<Tensor, EngineError>' src/core/mod.rs",
"expected_exit_code": 0
}
]
}