AI 资讯
Atomic writes — how tempfile + os.replace prevent corrupted JSON
What happens if the power cuts out while a process is writing to a config file? Or if antivirus software on Windows briefly locks a file mid-write? If you naively overwrite a file with open(path, 'w') , whatever partial content existed at the moment of interruption is what remains on disk. For JSON, that usually means broken syntax — json.load() throws on the next startup, and the entire configuration is effectively lost. This article walks through a standard technique for preventing that: writing to a temporary file first, then swapping it in atomically. Note: "Atomic" here means an operation either completes entirely or doesn't happen at all — there's no partial, observable in-between state. It's the same sense of the word used for database transactions. Why direct overwrites are dangerous open(path, 'w') effectively truncates the file first and then writes the new content. If the process is interrupted during that window, the file is left empty or holding incomplete content. # Dangerous: a crash mid-write leaves a corrupted file behind with open ( ' config.json ' , ' w ' ) as f : json . dump ( data , f ) # what if this gets interrupted? The causes vary: a kill -9 , a power outage, antivirus software briefly blocking file access on Windows, or a backup tool grabbing the file mid-write. This rarely reproduces during local development, but in a long-running production environment, it will eventually happen with near certainty. The fix: write to a temp file, then swap it in The core idea is simple. Never touch the target file directly. Write the complete new content to a temporary file first, confirm that write fully succeeded, and only then replace the target file with that temp file. import json import os import tempfile def atomic_write_json ( filepath , data ): dirpath = os . path . dirname ( os . path . abspath ( filepath )) or ' . ' fd , tmp_path = tempfile . mkstemp ( dir = dirpath , suffix = ' .json.tmp ' ) try : with os . fdopen ( fd , ' w ' , encoding = ' u
AI 资讯
x402 Explained: HTTP-Native Micropayments for AI Agents (With Real Code)
x402 Explained: HTTP‑Native Micropayments for AI Agents (With Real Code) Target audience: developers who are building autonomous AI agents and need a lightweight way to charge for individual API calls without introducing a separate billing system. Why look at x402? Autonomous agents often expose fine‑grained services—think “summarize this paragraph”, “classify this image”, or “fetch the latest price for a token”. Traditional approaches (API keys + monthly invoices, subscription tiers, or ad‑hoc invoicing) add operational overhead that doesn’t scale when an agent might make thousands of micro‑calls per day. The x402 specification repurposes the HTTP 402 Payment Required status code to turn every request into a self‑contained payment negotiation. If the client hasn’t paid, the server replies with 402 and includes the exact payment details the client must satisfy. Once the payment is verified, the server processes the request and returns the normal 200 response. Because the payment is expressed as a plain HTTP header, the mechanism works over any transport that supports headers—REST, GraphQL, gRPC‑HTTP/2 bridge, or even WebSockets. No new protocol layers, no side‑channel escrow services, and no need to maintain a separate billing database. Core components of an x402 flow Piece What it does Where it lives Payment Request Server‑generated data describing the required amount, token, chain, and payee address. Sent in the Pay response header on a 402. Server Payment Proof Client‑generated data proving that a transaction meeting the request was included on‑chain. Sent in the X-Payment request header. Client Verifier Server‑side code that checks the proof: validates the transaction hash, confirms the correct token amount was transferred to the payee, and ensures the chain ID matches. Server Wallet/Signer Client‑side library (e.g., ethers.js) that builds, signs, and broadcasts the payment transaction. Client The spec deliberately stays agnostic about the underlying blockchain;
AI 资讯
Your team's coding rules aren't in the prompt, they're in the ingest
Every AI code reviewer claims it respects your team's standards. Very few can tell you what those standards actually are. The test is mechanical. Ask the tool, or the vendor, one question: where do my rules live? If the honest answer is "we loaded a generic style guide plus whatever your PR description happened to say", then your standards aren't in the model at all. The reviewer is running on vibes and hoping your repo looks conventional enough to pass. The tools that genuinely track your rules share a shape: the standards are an input, not a hope. They read your rule files, your linter config, your past review comments, sometimes your docs. The review is judged against that artifact, which means when a comment fires you can ask "which rule?" and get a config line back, not a paragraph of model reasoning. That last part is the thing worth testing for. If a reviewer can't point to the specific rule it applied, it is not following your standards. It is approximating what it assumes standards look like. Those two feel identical for the first six months, then diverge exactly when you've stopped proofreading its output. A short checklist when you trial one: Does it ingest a rules file, or only the PR context? Can it point to the exact rule that triggered a comment? Does it adapt to your historical review style, or reset every run? Is a "rule" something you can open, read, and edit in the UI? If the answer to all four is no, you bought a very chatty spellchecker that happens to be trained on GitHub. The eval that actually decides it: can your own reviewer reproduce one of your team's real past review decisions, given only your real rules file? Run that before you hand it a production PR.
AI 资讯
The GNU strip backdoor is the case AI code review can't see
This paper (arxiv 2607.24888) is worth a stop if you evaluate AI code review. It shows Ken Thompson's trusting-trust attack is not compiler-specific: the authors pull it off with GNU strip, a build utility that neither reads nor generates source, using only tampered finished ELF binaries. In the NixOS bootstrap, one malicious strip in the binary seed implants a payload that propagates to the next strip generation and survives into the final standard environment after the seed is gone. The uncomfortable part for anyone building or buying AI review: these tools read the patch text and the source, and none of them reads the build path or the binary seed. And that is not a limitation a bigger model fixes. Put the strongest reasoning model in the world on that source diff and it sees a clean PR, because the malicious code is not in the source at all. It arrived as a finished strip binary in the dependency closure. I keep bumping into the same split and this paper is the cleanest example yet. Two jobs get lumped together. One is "did this source diff introduce a bug or flaw", and AI is genuinely, surprisingly good at that. The other is "does the artifact your users run match the source you reviewed", and no diff-based review, human or model, can answer yes to that. That is an artifact provenance and build reproducibility job, not a code review job. So the rule for teams adopting AI review: use it for the first job, and do not let its approval make you feel covered on the second. If your acceptance criterion becomes "the model said the diff is fine", you have traded the compiler-trust problem for a strip-trust problem and called it a win.
AI 资讯
I Want More Coding Agents to Work Like This
💻 One thing I dislike about coding-agent setups is how quickly they become part of one specific machine. Provider config goes in one place, session state somewhere else, local models live in another directory, and suddenly moving to a second machine means rebuilding the environment. OpenClaude-Portable takes a much cleaner approach. It packages the coding agent, runtime and persistent data into a self-contained folder. It supports cloud and local models in the same setup The project currently supports 9 provider options: Anthropic Claude OpenAI Google Gemini DeepSeek OpenRouter NVIDIA NIM Ollama LM Studio custom OpenAI-compatible APIs I like this because the portable part is not tied to one model vendor. I can use a cloud model when I want the strongest hosted option, then switch to Ollama or LM Studio when I want a local workflow. The important caveat is simple: cloud providers still need internet. Ollama can run offline after the initial setup. The "zero footprint" idea is more useful than it sounds The project redirects its persistent data into a local data folder. That includes provider settings, API keys, logs, session history, agent memory and local Ollama files. According to the repository, it does not write configuration into the host system. For me, this is the real feature. I do not care that the agent happens to be on a USB drive. I care that I can move the folder and keep my environment with it. 💾 There are two very different ways to run the agent The launcher offers a normal mode that asks before file writes or shell commands. There is also an optional Limitless mode that can run without approval prompts. I like that these are explicit choices rather than one hidden permission switch. For normal development I would keep approval mode on. For a disposable test project or a controlled autonomous task, the second mode could be useful. Sessions can survive the move Another practical detail is session resume. The project stores session history inside the por
开发者
Europe's largest carbon capture facility opens in the Netherlands
AI 资讯
Secure temporary file sharing for AI agents and humans
开发者
Saturday Evening Post Will Stop Printing After 205 Years
开发者
Premium Shop Helpfull
AI 资讯
Stratagems #29: Leo Counted 164 Nodes. The AI's Blossoms Had One Root.
Dress a tree in borrowed blossoms, and it looks alive. The roots still tell the truth. — The 36...
开发者
Open-source 3D anatomy explorer: 2,234 selectable BodyParts3D meshes
开发者
TALA Is Open-Source
产品设计
CERN's migration path from CentOS Linux to Debian
开发者
1% increase in immigration leads to a 1.78%-2.97% increase in Far-Right voting (2024)
AI 资讯
GM's breakup with CarPlay and Android Auto has one exception
GM's lineup is dropping Apple CarPlay and Android Auto in favor of its own infotainment systems. But one model is keeping the phone-mirroring capabilities.
AI 资讯
Le Creuset x Star Trek Collection: Prices, availability, release date
Vulcan oven mitts, spaceship baking dishes, and an out-of-this-world communicator grater—you'll need warp speed to Klingon to this limited edition kitchen kit, ideal for perfecting the broth of Khan.
开发者
[ Removed by Reddit ]
[ Removed by Reddit on account of violating the content policy . ] submitted by /u/Kel_Thuzad11 [link] [留言]
产品设计
Show HN: Stuxnet – A reconstructed source code of the infamous cyber-weapon
Stuxnet! Here reproduced by me. Only researchs educations purposes.
AI 资讯
Faker Doesn't Know Your Entities Are Related, So I Built Something That Does
Faker Doesn't Know Your Entities Are Related, So I Built Something That Does You've added a second entity to the schema, wired up a @ManyToOne , and gone back to your seed script to generate fifty more rows. Ninety seconds later, the app refuses to start: unique constraint violation, somewhere inside a loop you wrote three weeks ago at 11pm. You fix it. You restart. A different field breaks a different constraint. This is the exact moment every Spring Boot developer eventually meets the real limit of tools like Faker. They're brilliant at generating a name, an email, an address. They have no idea the Payment sitting in front of them needs a Counterparty to already exist. So you do what everyone does: hand-write the wiring. Create parents first. Hold onto their generated IDs. Wire them into children. Hope you didn't just violate a @NotNull somewhere in the process. It works, for a while. Then the schema changes, and the script quietly stops matching reality until the next 3am debugging session finds out the hard way. I hit this enough times that I stopped patching the script and looked at the actual problem: the information needed to seed this correctly already exists. It's sitting right there in the entity, in the annotations you already wrote. @ManyToOne , @NotNull , @Column(unique = true) , JPA already knows the shape of your data. Nothing should need to be told that twice. That became SynthForge . The core idea Instead of writing a script that generates data, you annotate the entity: @Entity @Seed ( count = 50 ) public class Counterparty { /* fields only */ } @Entity @Seed ( count = 200 ) public class Payment { @ManyToOne ( optional = false ) private Counterparty counterparty ; } Start the app in a dev profile. Both tables populate, correctly ordered, on every restart. No seed method. No calling code, anywhere. The entity is the seed script. What's actually happening underneath Entity scanning. SynthForge reads JPA-managed attributes through the jakarta.persisten
AI 资讯
Security Foundations Behind Reliable AI Systems
Originally published on WordPress on September 27, 2025. When AI systems fail in production, the failure is often blamed on data quality, model drift, or algorithmic limitations. In practice, many of the most damaging failures originate much earlier and much lower in the stack. They come from weak security foundations that allow systems to behave in unintended ways. Reliable AI is not just about accuracy or performance. It is about whether the surrounding infrastructure enforces discipline around access, data handling, and execution paths. Infrastructure as the First Line of AI Security Every AI system depends on infrastructure that controls how compute, storage, and networking are consumed. If that infrastructure is loosely governed, the AI system inherits that weakness. A common example is a shared compute environment where multiple teams run experiments. If isolation is poorly enforced, one workload can access artifacts, logs, or intermediate data from another. The model may be mathematically sound, but the environment allows behavior that violates assumptions about separation and control. From a reliability standpoint, this creates hidden coupling. An AI job might fail or behave inconsistently because another process consumed shared resources or modified shared state. From a security standpoint, the same weakness allows unauthorized access to sensitive datasets or trained models. Strong infrastructure boundaries do not just protect against attackers. They protect teams from each other and from accidental misuse. Access Control Across the AI Lifecycle AI systems have long lifecycles that include data ingestion, preprocessing, training, evaluation, deployment, and monitoring. Each stage introduces different access needs. Problems arise when a single identity or role is allowed to operate across too many of these stages. For example, an engineer might have permission to both modify training data and deploy models. That convenience can quietly undermine trust in the