PolyGlot Refactor AI — Autonomous C → Rust Migration Agent
Inspiration
Software engineering's most expensive refactors are not greenfield features—they are large-scale dependency upgrades, legacy language migrations, and framework overhauls. Existing coding assistants excel at single-file completions, but they fail at repository-scale migration: they ignore dependency trees, break AST consistency across thousands of lines, and leave broken test suites in their wake.
I wanted to build an agent that treats migration as a systems problem, not a chat completion problem: plan the transformation DAG, execute in dependency order, verify with real tests, self-correct on failure, and revert unsafe steps—then deliver a reviewable pull request.
What I Learned
Building PolyGlot Refactor AI taught me three lessons that generalize beyond this project:
1. Planning must precede execution.
LLMs are strong at generating code but weak at repository-scale topology. By forcing Nemotron 3 Ultra to emit a validated DAG (using graphlib.TopologicalSorter) before any file is rewritten, I reduced cascading breakage. The planner drops hallucinated paths, enforces unique file ownership, and repairs cyclic dependencies automatically.
2. Verification is the real product.
A migration that doesn't pass cargo test is a liability, not a feature. The agent records a C baseline first, so pre-existing failures are not blamed on the port. After translation, it runs cargo test, intercepts stack traces, feeds them back to Nemotron Super with the instruction "Fix this compiler error while preserving the AST signature," and iterates up to max_repair_iters times. Steps that cannot verify are reverted with their dependents—"revert, don't force."
3. Token Factory enables agentic workflows at hackathon scale.
Routing three model tiers through https://api.tokenfactory.nebius.com/v1 made the pipeline economically viable:
- Nemotron 3 Ultra (
nvidia/Nemotron-3-Ultra-550b-a55b): DAG planning and hard repairs - Nemotron 3 Super (
nvidia/nemotron-3-super-120b-a12b): File translation and Tavily mapping extraction - Nemotron 3 Nano (
nvidia/NVIDIA-Nemotron-3-Nano-30B-A3B): Low-risk mechanical edits
The expected token cost for a repository with (n) translation units and average depth (d) in the include DAG scales approximately as
[ O(n \cdot \bar{L} + d \cdot T_{\text{repair}}) ]
where (\bar{L}) is average file length and (T_{\text{repair}}) is the number of self-correction rounds. Tiered routing keeps the fast path cheap and reserves Ultra for the hard path.
How I Built It
The system has four pipeline phases, mirroring the hackathon's "Best Apps and Agents" track:
Phase 1 — Ingestion & Dependency Analysis
- Repository cloning: Git shallow-clone into a sandboxed workdir
- Static analysis: C adapter parses includes, function/struct signatures, and builds a call graph
- Planning: Nemotron 3 Ultra produces a step-by-step DAG;
validate_and_repair()enforces real file existence, unique ownership, and include order
Phase 2 — Asynchronous Multi-File Refactoring
- Parallel waves: Steps in the same topological wave run concurrently via
asyncio.Semaphore - Translation: Nemotron Super/Nano rewrite C translation units into single Rust modules in
rust-port/ - AST consistency: Generated modules are checked against already-translated dependency contracts
Phase 3 — Verification & Self-Correction Loop
- Test execution:
cargo test --manifest-path rust-port/Cargo.tomlinside the sandbox - Error interception: Compiler errors and test failures are captured with file snippets and stack traces
- Iterative convergence: Failures are fed back to Nemotron Super/Ultra for repair until the suite passes cleanly
Phase 4 — Artifact Generation & PR Delivery
- Git commits: Per-step commits for atomic revert capability
- Pull request:
hub-style PR via GitHub REST API with a rich body containing signature maps, telemetry, and step status - Frontend: Next.js UI with live SSE event stream, C vs Rust side-by-side diffs, git diff, signature table, migration telemetry, and persistent run history sidebar
Challenges Faced
| Challenge | Resolution |
|---|---|
| No Rust toolchain locally | Validated pipeline logic locally with scripted sandbox fakes; cargo test runs inside the Render backend container |
| C parsing without libclang | Built a structured regex/AST-lite adapter for includes, functions, structs, and enums; noted as an honest gap for production |
| Frontend–backend CORS | Configured CORS_ORIGINS on Render to allow the Vercel origin |
| Model hallucinated file paths | validate_and_repair() drops nonexistent paths and repairs include-order edges from the real graph |
| Unverified migration steps | Revert policy: failing steps and their dependents are rolled back rather than shipped red |
Tools & Services Used
| Category | Tool | Role |
|---|---|---|
| Inference | Nebius Token Factory | Runtime LLM API for Nemotron 3 Ultra / Super / Nano |
| Models | NVIDIA Nemotron 3 Ultra / Super / Nano | Planning, translation, repair, and mapping extraction |
| Research | Tavily Search API | Grounds C→Rust mappings in real documentation (qualifies for Best Use of Tavily) |
| Backend | FastAPI + Uvicorn + Python | Pipeline orchestration, SSE event stream, Git/PR integration |
| Frontend | Next.js 14 + React + TypeScript | Review UI with live timeline, side-by-side diffs, telemetry |
| Hosting | [Render] | Backend web service |
| Hosting | [Vercel] | Frontend deployment |
| Version Control | Git + GitHub | Per-step commits and pull request creation |
| Container | Docker | Backend image definition (portable to Nebius Serverless Jobs) |
Submission Notes
- Track: Best Apps and Agents
- Runtime model calls: Yes—every Nemotron call hits
https://api.tokenfactory.nebius.com/v1at runtime - Frontend URL:
https://polyglot-seven-sepia.vercel.app - Repository: Public GitHub repo with MIT
LICENSE - Demo video: ≤3 minutes on YouTube showing Token Factory calls and green `cargo test
Built With
- css
- docker
- fastapi
- github
- javascript
- makefile
- next.js
- node.js
- python
- react
- render
- shell
- tavily
- typescript
- uvicorn
- vercel
Log in or sign up for Devpost to join the conversation.