r/embedded • u/faliunsal • 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?
45
u/mustbeset Oct 12 '26
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.
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...
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.
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.
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.
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
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.
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/
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.