Using AI Agents for Codebase Refactoring and Monolith Decomposition
1password · Tech · 2026 · source Agentic: yes · promotional bias: low · source-backed · extracted with prompt 0.5.6 (schema v2)
Generated from extraction.json — do not edit by hand. Every claim cites verbatim source evidence; stated means the quote directly asserts the claim, implied means it supports it indirectly.
Problem
Domain: Production engineering and monolith decomposition
1Password needed to decompose and refactor a multi-million-line Go monolith while learning where AI agents could safely accelerate high-stakes engineering work without violating sequencing, schema, deployment, or data-boundary constraints.
Constraints:
- The B5 monolith served mission-critical Unified Access workflows at high request rates and low latency.
- Service extraction required coordinated schema evolution, read/write path changes, deployment sequencing, and shared data contracts.
- Agent-generated changes could introduce subtle production failures despite locally clean code.
- Parallel agent execution only helped when work was structurally independent.
- Human engineers remained responsible for boundaries, invariants, and sequencing.
Architecture
1Password built an agentic refactoring toolchain around deterministic artifacts. Go SSA analysis, SQL parsing, and DataDog MCP runtime data produced domain ownership maps, coupling graphs, and extraction order. Agents helped build analyzers and execute well-specified migrations from manifests and playbooks, while humans constrained scope, reviewed sequencing, and stopped complex service extraction where schema and deployment invariants were too interdependent for safe autonomous execution.
Diagram confidence: explicit (topology described by the source).
flowchart LR b5-go-monolith["B5 Go monolith"] --> go-ssa-analyzer["Go SSA analyzer"] b5-go-monolith --> sql-dependency-parser["SQL dependency parser"] go-ssa-analyzer --> deterministic-artifacts["Deterministic artifacts"] sql-dependency-parser --> deterministic-artifacts datadog-mcp-integration["DataDog MCP integration"] --> deterministic-artifacts deterministic-artifacts --> human-engineering-reviewers["Human engineering reviewers"] deterministic-artifacts --> agent-execution-worktrees["Agent execution worktrees"] human-engineering-reviewers --> agent-execution-worktrees agent-execution-worktrees --> b5-go-monolith
Components
| Component | Role | Interacts with |
|---|---|---|
B5 Go monolith |
The multi-million-line production codebase being analyzed and refactored. | Go SSA analyzer, SQL dependency parser, Agent execution worktrees |
Go SSA analyzer |
Provides static code-structure and call-site analysis. | B5 Go monolith, Deterministic artifacts |
SQL dependency parser |
Identifies database schema and access-pattern coupling. | B5 Go monolith, Deterministic artifacts |
DataDog MCP integration |
Supplies runtime coupling and transaction visibility. | Deterministic artifacts |
Deterministic artifacts |
Represent domain ownership maps, coupling graphs, call-site manifests, and extraction-order plans. | Go SSA analyzer, SQL dependency parser, DataDog MCP integration, Human engineering reviewers, Agent execution worktrees |
Human engineering reviewers |
Define boundaries, invariants, sequencing, and escalation decisions. | Deterministic artifacts, Agent execution worktrees |
Agent execution worktrees |
Isolated workspaces where agents execute independent, specified changes in parallel. | B5 Go monolith, Deterministic artifacts, Human engineering reviewers |
Data flow
Static code, SQL schemas, and DataDog runtime traces feed analyzers that generate deterministic ownership maps, coupling graphs, manifests, and extraction-order recommendations. Engineers turn those artifacts into playbooks with invariants and escalation rules. Multiple isolated agents operate in git worktrees on independent tasks, apply templates or draft changes, and hand ambiguous or sequencing-sensitive work back to humans for review.
3 supporting quotes
Why this architecture
1Password constrained agents with deterministic artifacts because unconstrained model judgment was too risky for irreversible production migrations. Agents were valuable at reading, classifying, and applying repetitive patterns, but engineers kept authority over system boundaries, deployment order, and data invariants.
3 supporting quotes
Models used: AI coding agents · Cursor planning/execution model mix
Scale
- The target was a multi-million-line Go monolith.“their large-scale Go monolith serving as the foundation for their Unified Access product.”summary, stated
- The successful transaction migration updated over 3,000 call sites.“a database transaction handling migration that required updating over 3,000 call sites.”summary, stated
- The 3,000-call-site migration executed in hours.“The actual execution took only hours, with the majority of time invested in building the tooling and writing the specification.”summary, stated
- Complex coordinated tasks saw 20-30% productivity gains.“For this class of complex, coordinated work, the productivity gains were real but modest – approximately 20-30% improvement.”summary, stated
Alternatives considered (roads not taken)
Let agents interpret the codebase continuously
Rejected because: 1Password preferred deterministic analyzers and manifests that engineers could reason about reproducibly.
Parallelize all agent refactoring work
Rejected because: Parallelism only worked when changes were independent and structurally isolated.
Ask agents to handle complex service extraction autonomously
Rejected because: Service extraction involved ordering and invariants across schema evolution, deployment sequencing, and shared data contracts.
Automate comprehensively
Rejected because: 1Password found it safer to define explicit automation boundaries and escalation paths.
Patterns
multi-agent-orchestration (agent execution)
1Password used multiple isolated agents in git worktrees for parallel codebase changes where independence was guaranteed.
tool-use-orchestration (agent tooling)
Agents and engineers combined SSA, SQL parsing, DataDog runtime data, manifests, and playbooks to guide refactoring.
observability-tracing (runtime context)
DataDog runtime coupling data informed extraction sequencing and improved transaction visibility.
structured-output-contract (agent safety)
Agents worked from deterministic manifests, explicit templates, playbooks, invariants, and escalation rules rather than open-ended judgment.
human-in-the-loop-gate (safety)
Humans retained responsibility for sequencing, boundaries, and ambiguous service-extraction decisions.
Tradeoffs
Agents build deterministic tools
Chose Use agents to create analyzers and manifests, then constrain execution to those artifacts over Use agents as ongoing interpreters of system boundaries.
Rationale: Deterministic outputs gave engineers stable artifacts to review and reason about.
Heavy specification before rapid execution
Chose Build tooling, classify patterns, and write a playbook before running agents over Send agents directly through thousands of call sites.
Rationale: Upfront deterministic preparation made the repetitive migration safe enough to execute quickly.
Human-controlled service extraction
Chose Keep humans in charge of schema/deployment sequencing over Let agents autonomously extract services.
Rationale: Current agents could not reliably manage dependency chains and invariants.
Intentional coverage boundaries
Chose Define where automation stops and escalation begins over Chase complete automation with more prompting.
Rationale: Graceful escalation was safer than letting agents improvise on ambiguous edge cases.
Gotchas (what bit them)
Agents mishandled migration sequencing despite explicit instructions.
Root cause: Complex service extraction requires interdependent schema, write-path, read-path, deployment, and data-contract decisions.
Resolution: 1Password restricted agents to well-specified patterns and kept humans responsible for sequencing-sensitive work.
An agent attempted an unsafe UUID-column backfill order.
Root cause: The agent optimized local code changes without preserving insertion-path invariants.
Resolution: Humans needed to enforce correct migration sequencing and stop unsafe plans.
Agents speculated when context was incomplete.
Root cause: Language models fill gaps with plausible but unverified assumptions.
Resolution: Specifications must name invariants, boundaries, ordering constraints, and escalation conditions.
Parallel agents can amplify inconsistency without structural isolation.
Root cause: Concurrent edits collide unless work units are independent.
Resolution: Use worktrees and only parallelize when independence has been guaranteed.
Generated code was not the hard part.
Root cause: Correctness depended on sequences of irreversible or hard-to-reverse engineering decisions.
Resolution: Invest in deterministic analysis, explicit specs, and human coordination before automated execution.
Evaluation
1Password evaluated agents pragmatically through migration outcomes, alignment with experienced engineers' extraction order, productivity gains, and observed failure modes in real refactoring work.
Metrics: 3,000+ call-site migration in hours · 20-30% productivity improvement on complex coordinated tasks · Extraction order aligned with experienced engineers · Observed sequencing and speculation failure cases
3 supporting quotes
Outcomes
- Agents completed a 3,000+ call-site transaction migration in hours after deterministic preparation.
- The analysis produced useful ownership maps, coupling graphs, and extraction sequencing.
- Agents delivered 20-30% productivity gains on complex tasks but did not remove human coordination.
- The team identified deterministic artifacts and explicit escalation as the safe pattern for agentic refactoring.
The work targeted a multi-million-line Go monolith and a 3,000+ call-site migration, with complex service extraction still requiring human-led sequencing.