Inspiration

Large language models are already remarkably capable at understanding and debugging code. But most coding workflows still use them in a relatively static way: provide a large amount of repository context, ask for a patch, and hope that the patch works.

We wanted to explore a different question:

What if, instead of putting the repository into K2, we gave K2 the ability to explore the repository itself?

A software engineer does not normally begin debugging by reading every file in a codebase. They start from an issue, search for relevant code, inspect a few files, run a test, observe what happened, update their hypothesis, and decide what to do next.

That workflow maps naturally to what we found most compelling about K2 Horizon: tool use, persistent context, and long-horizon decision making.

So we built HorizonFix around one principle:

Give K2 access, not a dump.

Instead of treating K2 as a passive patch generator, HorizonFix makes K2 the controller of the debugging process.

K2 decides what to search, what to read, what to test, what to change, and what to do next based on the evidence it has observed.

Our goal became:

From bug report to verified repair — autonomously.


What it does

HorizonFix is an autonomous debugging agent powered by K2 Horizon.

Given a repository and a reported software issue, HorizonFix lets K2 interact with the codebase through a controlled set of tools:

  • list_files
  • read_file
  • search_code
  • run_tests
  • apply_patch
  • get_git_diff

There is intentionally no hard-coded debugging trajectory.

HorizonFix does not decide in advance which files should be inspected, where the bug is located, which tests should be executed, or what sequence of actions should be followed.

K2 decides what to do next.

The resulting workflow is:

Issue → Explore → Observe → Act → Test → Revise → Verify

If a test fails, that failure becomes new evidence. If a tool call is unsuccessful, K2 can change its approach. If a patch introduces another problem, K2 can continue investigating.

The goal is not simply to generate code that looks correct.

The goal is to leave behind a repository that has actually been tested and verified.

Not just a proposed patch. A verified working repository.


How we built it

The central design decision behind HorizonFix is that K2 Horizon controls the debugging trajectory.

Our Python system provides tools, but it does not prescribe how K2 should use them.

At each step, K2 looks at the evidence accumulated so far and selects its next action.

A debugging trajectory might look like:

search → read → test → inspect → patch → test → revise → verify

But this sequence is not scripted.

It emerges from K2's decisions.

Why K2 Horizon?

We designed HorizonFix specifically to maximize the capabilities that make K2 Horizon interesting as an agentic model.

K2 is responsible for:

  • navigating unfamiliar repository structures
  • deciding what information it needs
  • selecting relevant code
  • interpreting tool observations
  • maintaining a debugging hypothesis across many steps
  • recovering from unsuccessful actions
  • deciding when to modify code
  • using test results as new evidence
  • determining whether further investigation is necessary
  • deciding when the repair is sufficiently verified

In other words:

K2 doesn't sit inside our workflow. K2 drives the workflow.

Instead of asking K2 to solve one predefined step of a larger program, we let K2 decide what the program should do next.

Tool use as context management

Tool use also solves another important problem: repository context.

A simple approach to repository-level debugging is to place as much source code as possible into the model's prompt.

That becomes increasingly impractical as repositories grow.

HorizonFix takes the opposite approach.

The repository remains an external environment. K2 can search it, inspect specific files, and retrieve relevant code only when it determines that information is necessary.

The loop becomes:

Decide what information is needed → retrieve it → observe it → decide again

This is a form of just-in-time context acquisition.

It does not require every file in the repository to occupy the context window upfront, and irrelevant parts of the codebase do not have to be loaded simply because they exist.

This design should become increasingly useful as repositories grow: instead of trying to fit a large codebase into a prompt, K2 can navigate it incrementally.

Controlled execution

We deliberately expose a small set of explicit tools rather than arbitrary shell access.

Repository exploration, code search, test execution, patching, and Git diff inspection are separate observable operations.

This gives K2 enough capability to perform real debugging while keeping the execution process constrained and understandable.

Tool results are fed back into K2 as observations, allowing later actions to depend on what actually happened in the repository.

That feedback loop is the core of HorizonFix.


Challenges we ran into

Long-horizon debugging

Real debugging rarely follows a perfect sequence of actions.

The agent may inspect files that turn out to be irrelevant, run a test that reveals a different problem, or need to revise an earlier hypothesis.

One of our biggest challenges was therefore supporting a sufficiently long interaction between K2 and the repository without turning the workflow into a predefined script.

This made execution budgets, context management, and tool efficiency important parts of the system.

Recovering from tool failures

K2 does not always make a perfect tool call.

During development, it sometimes attempted invalid test targets or requested operations that our tools rejected.

We decided not to hide these failures.

Instead, HorizonFix returns them to K2 as observations.

K2 can then adapt.

This became one of our favorite behaviors in the project because it demonstrates the difference between a static generation pipeline and an agent interacting with an environment:

Failure itself can become useful information.

Building safe and useful tools

Giving an autonomous model arbitrary execution access would have made the prototype simpler, but much harder to control.

We instead built explicit operations for repository inspection, pytest execution, code modification, and Git diff inspection.

Finding the right balance between giving K2 enough freedom to debug autonomously and keeping repository interactions constrained was an important engineering challenge.

Knowing when to stop

Generating a plausible patch is easy to define as an endpoint.

Autonomous debugging is harder.

The agent has to decide whether the evidence it has collected is sufficient, whether another test is necessary, and whether the repository is actually in a state worth calling repaired.

That made verification, rather than code generation, a central concept in HorizonFix.


Accomplishments that we're proud of

We are proud that HorizonFix became more than a wrapper around an LLM call.

K2 can autonomously navigate a repository, search for relevant implementation details, inspect source files, execute tests, modify production code, observe the consequences of those changes, and continue debugging based on new evidence.

We also built the system so that the debugging trajectory is observable.

Tool calls, test executions, repository modifications, Git diffs, failures, and verification status can all be inspected rather than hidden behind a single generated answer.

Most importantly, HorizonFix demonstrates a different way of using K2 Horizon.

We are not simply asking K2 to produce a better patch.

We are giving K2 an environment in which its decisions can affect the next state of the problem.

K2 reasons about the repository, acts on it, observes what changed, and reasons again.

That is the behavior we most wanted to explore during this hackathon.


What we learned

The biggest lesson was that the model is only one part of an agent.

Tool design, context management, execution budgets, failure handling, repository isolation, and verification all strongly affect what the model can accomplish.

We also learned that tool use is about more than executing actions.

It changes the relationship between the model and its context.

Instead of giving K2 everything we think might be relevant, we can give K2 the ability to decide what becomes relevant.

This distinction becomes particularly interesting for large codebases.

A repository can be much larger than what we would want to place into a single prompt, while the actual bug may depend on only a small subset of its files.

An agent that can search and retrieve information on demand can treat that large repository as an external information space rather than a block of text that must be loaded upfront.

Finally, we learned that autonomous debugging is fundamentally a feedback problem:

Decide → Act → Observe → Revise

The same model can behave very differently when it is able to observe the consequences of its own actions.


What's next for HorizonFix

The next step is scaling HorizonFix from our controlled debugging environments to large, real-world repositories.

This is where we believe the architecture becomes especially interesting.

As repository size grows, loading the entire codebase into model context becomes increasingly expensive or impractical. HorizonFix instead allows K2 to navigate the repository selectively, retrieving only the information needed as the investigation develops.

We want to evaluate this on real software-engineering tasks such as SWE-bench Verified, where K2 would need to navigate unfamiliar open-source repositories and repair real reported issues.

We also want to improve the efficiency of long-horizon debugging through:

  • smarter repository search
  • context pruning
  • observation compression
  • selective test execution
  • adaptive tool-use budgets
  • better stopping criteria

Ultimately, HorizonFix is an experiment in fully using what makes K2 Horizon compelling:

tool use, persistent context, adaptive decision making, and long-horizon interaction with a real environment.

Instead of asking:

"K2, what is the answer?"

HorizonFix asks:

"K2, what should we do next?"

And it keeps asking until there is evidence that the repository works.

Built With

Share this project:

Updates

Submission history