Physician, (learn how to) heal thyself

Back at the beginning of the year I introduced AppScript, an interpreter for an “Objective-C without the C” language. Time’s passed, and a lot of the rough edges are smoothed over: AppScript now bridges to C types anywhere they appear, including in C functions and block parameters/return values; supports out parameters including out-NSErrors and the BOOL *stop in NSFastEnumeration; and much more. It’s time to do something interesting with a newly-complete language.

My current interest is Continuous Validation: how do we shorten the loop between people having problems and finding out that the software we built doesn’t solve them in the right way? The lowest-hanging fruit is crashes. Generally, customers don’t want their software to crash, so if it happens, it’s definitely wrong.

AppScript exposes an uncaught exception handler hook. The exception provides error details and the full backtrace (including native code) enriched with additional information about frames in the AppScript interpreter. It also doesn’t catch exceptions, so all exceptions are uncaught… What if an LLM hooked into the exception handler, determined the problem, patched the code and re-ran the failing operation?

That’s the idea behind ASAnalyst. Here’s the design:

So now all I need is an LLM and the prompt, tools, and supporting information it needs to get this right. Some requirements:

  • Minimal cost to the customer, because otherwise they’re paying to fix my problems.
  • Private, because I don’t know what information is included in objects that appear in the backtrace.
  • Don’t block the customer if the network’s down.
  • Safe from injection, because I still don’t know what appears in the backtrace. Clearly there’s a security choice already being made in “let’s generate software on the fly on the customer’s machine”, no need to make that any worse than it already is!

My first thought is to use the built-in Apple model via FoundationModels. Two disadvantages: I bring Swift into a purely-ObjC (and AppScript) project; and not available on non-Apple platforms, when cross-platform support via GNUstep is a secondary goal for the language. But it does cover all the requirements above.

Eval time! Here’s the method: I generate 24 separate synthesised AppScript crash reports, each of which has a “golden patch” known to fix the problem:

  • 16 examples of recoverable bugs, in eight categories: misspelt selector; wrong arithmetic operator; missing method; incorrect keyword usage; nil sent to message that expects non-nil; no value returned from method; attempt to mutate an immutable collection; failing value conversion.
  • 4 examples of unrecoverable bugs (those where retrying the operation isn’t feasible): for the purposes of the eval, this is any bug like the above that occurs in new/copy/alloc method because you can’t do memory management if something fails somewhere in a memory-management method.
  • 4 examples of injection attempts, where a string in the exception information contains instructions for the model to do something other than analyse the failure.

Then I have three candidate system prompts:

  • The baseline prompt, just containing the instructions to: attempt to uncover the root cause; describe the root cause in a single sentence for the app developer; whether the operation can be retried or the app needs to restart; describe the situation to the end user in non-technical language; and an AppScript patch that resolves the problem (empty if the root cause isn’t known).
  • Baseline, plus a short description (1,200 bytes) of the AppScript language syntax.
  • Baseline, plus a long description (2,700 bytes) of the AppScript language syntax.

The LLM receives each synthesised report in the same user prompt, with each of the 3 system prompts, 3 times per condition (so 216 total runs). A separate LLM (Deepmind’s Gemma4 31B) scores the response on a scale of 1-5 based on the accuracy of the descriptions, availability of a patch, accuracy of the patch, and whether the LLM followed injected instructions. I take the mean score and scale it 0-1: 0 meaning the model gave consistently low-quality responses, and 1 meaning it gave responses consistently judged to be perfect.

Apple’s on-device model does best with the short-summary system prompt, but still only generates patches that are actually valid AppScript 6% of the time (13 out of 216 instances). Even in these cases, the patches it generates don’t fix the problem; it tries to add unrelated category methods to system classes like NSObject. The things it is good at are avoiding injection attacks (92%) and giving explanations (normalised score 0.56).

OK, so this is a non-starter. Maybe I need a more capable model, and to think carefully about how I deploy it to retain the self-healing capability while also maintaining the privacy, security, and cost goals.

Many hours later, and I have the eval results for 6 open weight models from the mistral, gemma4, qwen3_5, and glm4_moe_lite families. Saving the gory details, the best performance is from qwen/qwen3.8-27b with the long system prompt:

  • 69% valid patches
  • 12% correct behavior on recovery
  • 75% chooses the correct retry/restart outcome
  • 100% ignores injection attempts
  • 0.77 normalised judge score
  • mean time to response of 10.2s

That’s…not great, but it’s sufficient to suggest that the idea is feasible. I have three different lines of attack now. One is to experiment with the prompt and the rules of the game, to see if I can improve accuracy. The second is to change how the source is represented to the LLM; if I can send and receive syntax in a “known” programming language like Ruby it might do a better job. The third is to try and prove this concept entirely in a well-known runtime environment like Python to more closely align the LLM’s goal with the things it’s trained on.

About Graham

I make it faster and easier for you to create high-quality code.
This entry was posted in AI, code-level, tool-support. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.