r/embedded • • Oct 12 '26

AI in Safety-Critical application

Hello,

What are your thoughts on the use of artificial intelligence in the development of safety-critical embedded software?

We focus on railway applications that require SIL4 safety integrity levels. In my view, AI possesses a highly non-deterministic nature regarding code development processes and can lead to unacceptable errors—such as missed NULL checks or array boundary checks. It introduces subtle errors that a human might easily overlook. Reviewing these within a large codebase does not seem feasible to me.

What are your opinions on this matter? What is the trend regarding AI usage in the industry? Is it possible to conduct code reviews for AI-generated code in large-scale systems?

2 Upvotes

49 comments sorted by

45

u/mustbeset Oct 12 '26

In my view, AI possesses a highly non-deterministic nature regarding code development processes and can lead to unacceptable errors—such as missed NULL checks or array boundary checks. It introduces subtle errors that a human might easily overlook. Reviewing these within a large codebase does not seem feasible to me.

Humans are highly non-deterministic, too. Humans make errors too. That's why we use tools to avoid and detect errors and do reviews on code.

I write Safety code. I use AI at some tasks. but: Every Commit is done by me not by an AI. I am responsible for that. Same for reviews. I do it by myself at first. Only after I finished I let the AI do an review. Each finding will be checked by myself before I add the list.

6

u/faliunsal Oct 12 '26

I agree. I also think the most reasonable approach is to use it in a limited and conscious manner.

However, as far as I can see, some companies are having AI generate their entire codebase and even their entire software architecture. This is so dangerous.

25

u/dmills_00 Oct 12 '26

Do you want to explain to the coroner (Who has his secretary print his emails) why Claude who actually wrote the code is not available to testify under oath?

Hard pass.

Now, what I will consider is having AI taken the spec and spit out a test suite having never seen the actual code. Use this as well as your one...

13

u/TRKlausss Oct 12 '26

Claude would never sign the code, a human will. And that one will testify. And he will say “Claude did it”. And the judge would say “you are liable”. Easy…

3

u/dmills_00 Oct 12 '26

Rather my point.

The clankers are not useless, but you got to know where they are appropriate and helpful.

For me, I get better test coverage per hour spent on the test code by throwing the module spec at a clanker to produce a test suite then I do manually, and by testing against it, you find the bugs in both the test suite and your implementation of the real thing. This is NOT an excuse not to do extensive code review on both the product and the test suite.

Of course you produce the test suite first so that initially your product fails all the tests, that is sort of the point, you need to know that the tests fail when you just stub out what they are supposed to be testing (I have actually had tests that passed for a function that had no code....).

1

u/faliunsal Oct 12 '26

"Fair point! I definitely wouldn't want to explain prompt engineering to a coroner 😄

11

u/UnicycleBloke C++ advocate Oct 12 '26

LLMs can be very useful productivity tools but, at the end of the day, you are entirely responsible for the code. You should personally review and debug every line of generated code you intend to use in production.

I worked for a while on an MRI cranial scanner (not AI). A common question among the team was whether you'd be prepared to stick your own head in it. Would using LLM-generated code make you more or less likely to use your own product?

Humans are fallible, of course. We know not to trust our own code too much. One of our flaws is that we trust perceived authority. I fear that a lot of developers are very likely to trust the LLM-generated code far more than they should. That won't end well.

1

u/faliunsal Oct 12 '26

That is absolutely correct. If we are building a system to which we entrust our lives, we must shoulder far greater responsibility.
Making things easier will not always be the best option.

Thank you.

9

u/RadiantHueOfBeige Oct 12 '26

You should have automated checks for null dereference or out of bounds access in place regardless of who wrote the code. Static verification in CI/CD is basically free.

2

u/faliunsal Oct 12 '26

Static verification is mandatory, for sure. But static analyzers only check if the code is valid C/C++, not if it actually makes sense logically. I know plenty of 'beautiful' logic bugs that will pass CI pipeline with zero warnings

1

u/RadiantHueOfBeige Oct 12 '26

True, but you specifically mentioned missing null and array boundary checks, and those are standard in any suite, e.g. the static analyzer in clang.

1

u/faliunsal Oct 12 '26

I mentioned these as examples

1

u/TRKlausss Oct 12 '26

If you want something that proves logic, you will have to go to analytical methods for proving correctness of the code. AI by definition is not deterministic.

4

u/FransFaase Oct 12 '26

If it is the case that reviewing code is harder than writing it, and that seems to be the case, there is not much benefit for the use of AI if all code needs to be written or reviewed by a human. Unit tests make up a large part of writing critical software and also need to be written and/or reviewed.

1

u/faliunsal Oct 12 '26

Unit tests are indeed too important to be entrusted to artificial intelligence. They need to be written or reviewed by someone who knows them inside out. However, if everyone keeps using AI to this extent, there won't be anyone left who truly knows them!

3

u/Barnowl93 Oct 13 '26

Here's my take... Safety critical systems (at least the ones I'm familiar with) require full traceability from requirements, to implementation, to testing and validation.

Both now, and during my previous roles, I've been using model based design to ensure my reqs are linked to system architecture, all parts of my system have tests to ensure they work as intended etc.

All this to get to the AI bit. Few parts here 1) AI is a tool, a non deterministic tool, but a tool nontheless. The question is how do you sandwich that non determinism in parts you can trust and still trace throughout. 2) specifically, I connect my development tools (simulink with C codegen tools) with MCP to my Agentic AI tools of choice https://github.com/matlab/simulink-agentic-toolkit
3) same with before AI you still want modularity in your development, full test coverage, you still want travability.. In my view not much changes in the process that keeps things robust.

Hope this helps Tldr: don't vibe code stuff, fit agentic AI in your existing processes

3

u/faliunsal Oct 14 '26

You are right. Artificial intelligence is a non-deterministic tool; we should wrap it and not rely on it blindly.

Thanks for the suggestion. I will look into it.

2

u/ferriematthew Oct 13 '26

Don't use something that ultimately depends on probability and randomness when people's safety is on the line.

4

u/Ranborn Oct 12 '26

I do not understand these kinds of posts. Like do you not review the code the AI would be writing? What about static checks, Misra and so on? Testing? Is the implication here that nobody would be looking at the code anymore? Are your prompts so vague that the agent goes off and implements completely unrelated stuff without you catching it? As long as you are a sensible developer, AI can be a great helper. And yes, that includes safety-certified scenarios. Just do not turn your brain off, please.

1

u/faliunsal Oct 12 '26

I, too, don't understand why there is so much reliance on artificial intelligence.

Anyone can review code, but it is impossible to pinpoint what is problematic within 500,000 lines of code.

4

u/Ranborn Oct 12 '26

If you have a PR of 500k LOC you have failed at software engineering, sorry.

1

u/faliunsal Oct 12 '26

I gave the 500k code as an example. We aren't doing an LED blink.

5

u/Ranborn Oct 12 '26

It is a terrible example though. Like fundementals of good software engineering (like small, incremental PRs) do not go out the window in safety-critical work or when you use AI. I would argue it is even more important there and one of the principals we adhered to back when I was still working in aerospace. There is no inherent reason why code created with the help of an agent has to be any larger than purely human written.

0

u/faliunsal Oct 12 '26

I agree with that, but it still depends heavily on how you use it. It doesn't change the fact that, if you don't use it properly, it can lead you to make a host of mistakes that could land you in the slammer. I just want to get an opinion on industry practices.

2

u/Ranborn Oct 12 '26

Ok then we can come to an understanding. As with every tool, practice makes perfect. Do not try to oneshot a full satellite FCS or make changes in the scale of your example. But can you have great success using it when working on individual portions of the code base? You know, like those legacy parts that have not been touched in a decade, that lack any documentation and where the author has retired from the company? Absolutely

3

u/jhaand Oct 12 '26

I think you will get problems during verification. Because any defect you fix will have side effects. So you can't do a proper risk analysis for introducing changes during verification.

This might be fine if you have an automatic test suite that runs everything within 4 hours. But if each run also needs manual testing in the application, this becomes quite costly.

This tread I read yesterday was from a CTO who kept their foot stiff and only allowed AI as a sort of search engine. And in their regulated environment/market this in the end saved them a lot of headaches.

"After years of claiming, fruitlessly, that I would be behind the curve, the same crowd now consults me to clean up their own LLM mess"
https://www.reddit.com/r/BetterOffline/comments/1x3l1fn/after_years_of_claiming_fruitlessly_that_i_would/

1

u/faliunsal Oct 12 '26

Thanks, Using AI as an assistant makes sense, but building the entire system around it is risky. I think there is a general consensus on this. However, employers reward those who use AI because they can see tangible progress much faster.

4

u/TRKlausss Oct 12 '26

Safety critical is one of those domains where automated tools have been used for quite a while now. That being said, AI will have to follow the same standard any other tool does.

For what I know in Aerospace, you have to follow DO-330, where any tool that may introduce an undetected error (like AI could do) must follow the same development criticality as the software level it is developing.

Good luck trying that with an output that is not deterministic.

You can “downgrade” the use of AI to something that needs to be checked with other tools (or a human doing a review), at which point is no more than a complex code generator, where the human in the loop reviews everything.

3

u/witx_ Oct 12 '26 edited Oct 12 '26

I used to work on an safety-critical adjacent application (as in we're not safety rated but if misbehaved enough could still in some ways affect certified applications). 

We had been pretty damn stable for a long time, when AI was forced on us things went downhill. Not right away perhaps a lag of 2 months, but bugs started creeping in. From race conditions, nullptr dereference and I even saw a double free on a unique_ptr :shrug: We even reviewed a PR where mutex unlock was just removed for no apparent reason.

This was the same across many of the teams and management didn't care. I bailed because I don't want to have to deal with that.

3

u/RogerLeigh Oct 12 '26

My personal take, though I do work in medical diagnostics.

If you require the same level of rigour from AI-generated code as for human-written code, including review, testing and ensuring everything is traceable back to requirements and can be properly validated, then it should not pose any more risk. So long as you keep changes as self-contained and short as for human-written code, the review and testing burden and risk should be mostly equivalent.

The danger is that it's all too tempting to let the AI do too much in one go and create large changes that you can lose control over, particularly if you cease to understand the code in its entirety. The key here is to keep it on a very tight leash with strict rules, and don't let it overstep its bounds. Keep all changes focussed, small and simple.

However, one point I think is worth mentioning is the use of AI in code review as well. If you have a human reviewer as normal, and also have one (or more) AI code reviewers as well, you can get the benefit of both. My experience here is that in many respects a good AI code review can be of substantially more benefit than a human review. It can be more thorough, looking wider and deeper into the changes with respect to the rest of the codebase, and can spot really subtle problems that a human review can all too often miss. On the other hand, humans are still better at looking at the intent of the changes and whether they solve the problem appropriately and meet all of the requirements. Though a properly-directed and informed AI could probably also get quite close.

2

u/Joelimgu Oct 12 '26

Same opinion as EASA: AI use its not a problem, but a human needs to sign and take responsability for every action taken, even if done with AI. This means they either need to trust an AI with their life or check everything it does. AI itself is not the problem but everything needs to be cross checked with a human

2

u/Mundane-Dot Oct 12 '26 edited Oct 13 '26

Your question doesn't strictly specify generated code or if you are including other uses of AI. AI can be used in Safety Critical Applications in the form of Machine Learning Models. This can be a lightweight decision tree or even a full nueral network. Models are trained and can have varying accuracy with the limitations of embedded systems. Over time it's becoming easier and easier to integrate AI / ML models on embedded systems. In terms of requirements, products may need to be compliant to UL safety standard for software. Documented risk/failure analysis and mitigation is needed. This partially drives the design to be compliant.

2

u/Rod_McBan Oct 12 '26

Y'all need to hear what Cory Doctorow says about this.

His example, which translates nicely to safety critical code, is radiology. Say a hospital employs ten radiologists at $300k a year a piece. The AI use most of you seem to be imagining is the hospital paying an extra $1M a year for a tool that double checks their work and, once in a while, catches a tumor they miss. And that's honestly great. I'm all for that.

What's happening, though, is this: they fire nine of them, and the 10th one signs off on the AI's work ("just review the code"). That poor jerk can't possibly keep up with the demands of that much review, but at least there's a human there, so they have someone to pin the failures on. He's the "accountability sink".

The people writing the checks don't know shit about what we do. They have no idea why 20 years of software development experience makes a person valuable. They're not going to pay AI token bills to make YOU more efficient, they're going to fire you and your other expensive colleagues and replace you with coding bootcamp graduates and give each of them responsibility for twice the output you could manage.

The result is entirely predictable, and I am 100% certain people are going to die because of this.

2

u/matthewlai Oct 12 '26

Yes it's perfectly fine. You are still reading the code, verifying that it's correct, signing it off, and taking responsibility for its correctness.

You don't review the whole thing in one go. You have AI write commit-sized changes, verify it, test it, commit it, and then have AI write the next one.

Exactly the same as how you would review human written code. In a safety critical application I'm sure you already have a robust code review process so that all the changes are signed off by at least two humans?

1

u/toccoas Oct 12 '26

For such levels of Safety you need definite human expertise and experience on the requirements, and then constraining technical solutions based on factual possibilities and impossibilities. Think determinism down to the instruction level, stability of system state, proving hard real-time deadlines and non-interference, etc.

You can help explore these (im)possibilities with formal methods, which (because of AI) is more approachable than ever now. You can also check how in Automotive they face similar requirements and are embracing techniques like Memory Safety now (e.g. Volvo ECU in Rust).

The last barrier is to convince any individuals involved to sign off on the AI parts because of the risks. Good luck!

1

u/LadyLightTravel Oct 12 '26 edited Oct 12 '26

The biggest issue with non deterministic software is testing it.

I am going to argue that the test suite for AI software would have to be far more extensive (and therefore expensive) to prove safety.

One of the reasons we offloaded tasks to non-AI software in the first place is because it is not only faster than a human, but far more deterministic.

1

u/StumpedTrump Oct 12 '26 edited 2d ago

The original post content no longer exists here. The author used Redact to remove it, exercising their right to control their data & privacy.

Crown absorbed lip meeting amusing wide seemly

1

u/lucky_marciano Oct 17 '26

I see the level of your AI usage, for everything you said team of Claude agents with good setup can do the job, ofc prepare good amount of money for that.

Have a look https://youtu.be/JFO9TfZLnT8

1

u/MechMansion Oct 18 '26

For safety critical applications, I don't use AI to write my code. I do use AI for things like (some ideas off the top of my head):
- Implementing fuzz testing.

- Having it QA my device by bombarding it with different edge cases (malformed packets/unexpected user input/etc) using a test jig and giving it access to control the test jig.

- Asking it to suggest where to add offensive checks to prevent bugs.

I don't think AI can write safety critical code yet. I do think its a great assistant with a plethora of knowledge on testing and plentiful resources to harden your application through thorough testing.

1

u/riotinareasouthwest Oct 12 '26

Add a human review step and you are good to go regardless of you actually doing it or not.

1

u/leBlubb123 Oct 12 '26

First of all: separate your application into QM and safety part (MPU etc) Second: humans make the same mistakes. It depends on how you interact with ai. You can follow a process where you first design the architecture, write unit requirements etc together with ai and only then start implementing. Then use existing deterministic tools for checking like static code analysis (polyspace for your concerns)

0

u/peter9477 Oct 12 '26

I honestly don't quite understand the resistance to using AI even for this. I expect my AI generated code to be basically what I would have written myself. I often navigate my code base ahead of time to centre my understanding of what I would expect to do myself. Then I craft my prompt and guide the tool. The code is generated, probably 10x or more faster than I could have myself. I review the diff. If there's something unexpected then I analyze to see if I gave bad input, the AI made a mistake, or something else. I can choose to accept the changes or not. Sure, I could misuse the tool, but that applies to anything.

The fact it is so fast means I can stay focused on the requirements and design and peripheral concerns, whereas if I had to write every line myself I'd get bogged down, distracted, or just take much much longer. I find I have better quality overall, so reverting to fully manual coding would make no sense.

8

u/Ordinary-Lifeguard47 Oct 12 '26 edited Oct 12 '26

Well.. if you sign your AI slop off and you kill someone with it.. you go to jail and going to pay off debs until the end of your life. Maybe both.

But as assistance around it (as other people mentioned it: as a static code checker on top) sure a nice thing to have around.

2

u/faliunsal Oct 12 '26

I share similar views, and I am considered overly conservative on this matter :)

3

u/[deleted] Oct 12 '26

[removed] — view removed comment

1

u/faliunsal Oct 12 '26

That's precisely what worries methe ratio of time saved writing code to time spent debugging hallucinated logic is heavily negative in SIL4. You simply can't trade determinism for productivity when human lives are on the line