Inspiration: There's a function in a codebase I work on called normalize_legacy_payload. I wrote it, and I've wanted to delete it for months, but every time I search the name I get a handful of hits and can't tell, in thirty seconds, whether any are real. Some are comments. One is a different function with the same name. So it stays, year after year, just in case. That's how code rots: not from bad decisions, but from being unsure. I wanted a tool that could prove a deletion was safe.
What it does: GraphSurgeon deletes dead code and proves it was safe. It's a GitLab Duo agent skill, a publishable Duo flow, and a deterministic CLI that all use the GitLab Orbit knowledge graph as a write-safety oracle. It finds exported definitions with zero inbound cross-file references, double-checks the symbol isn't used inside its own file, runs your test suite as a second gate, and opens a merge request whose description embeds the literal query it ran and the per-symbol evidence. The reviewer approves on proof, not faith; it never auto-merges.
The part I'm most proud of is the refusal. In the demo it keeps apply_discount (exported, imported by nobody, but still called inside its own file) and compute_total (referenced only through an aliased import that grep can't see). A tool that knows when to stop is one you can trust.
How it uses the GitLab Knowledge Graph: Orbit resolves real symbol references across files the way a compiler does, not the way a text search does. GraphSurgeon inverts the usual read-the-graph pattern: it uses the absence of a resolution edge as the precondition for a destructive edit. For each candidate it runs one Orbit traversal, counting distinct imported symbols in other files that resolve to the definition, and a count of zero means nothing else references it. It reads Orbit Local's graph.duckdb directly and introspects the undocumented gl_edge columns at runtime, so the same code works on the real graph or a fixture.
How I built it: A pure, unit-tested decision core in Python (the deletion math is auditable and LLM-free), a schema-adaptive DuckDB reader, an exact line-range editor with orphan-import cleanup and graph-drift detection, a test gate, and an evidence renderer. The Duo skill ships the same logic as paste-ready Orbit SQL recipes; the flow calls Orbit's get_graph_schema and query_graph MCP tools so it runs inside the Duo Agent Platform.
Challenges: Orbit's indexer is Linux/macOS-only and the gl_edge schema is undocumented, so I made the reader introspect the edge columns at runtime and shipped a fixture graph so the core reproduces with zero Orbit install. Getting the refusal cases right, specifically same-file-only usage and aliased imports, was the hard, important part.
What I learned: That the most valuable thing a graph can tell you is sometimes what isn't there. An absent edge, hardened with a couple of cheap guards and a test gate, turns the scariest edit in software into a reviewable, provable one.
What's next: Cross-repo checking via Orbit Remote, more languages, and a "dead code budget" CI check.
Log in or sign up for Devpost to join the conversation.