# 878 Files, Two Lines of Risk: How My Agent Vets a Fast-Moving Upstream

Author: Maksym Tytarenko | Date: 2026-12-01 | Category: AI & ML | Tags: agent-corp, vibe-trading, supply chain, code review, AI agents, dependency pinning
Canonical: https://www.tytarenkoagency.com/blog/878-files-two-lines-of-risk-how-my-agent-vets-a-fast-moving-upstream

> Upstream moved past my vetted pin 40 times in 51 days. An AI agent vetted every delta; 16 stopped at HIGH. The latest, 878 files, stopped in ten minutes on two carried findings.

My agent fleet runs a paper-trading experiment on top of an open-source trading agent, [Vibe-Trading](https://github.com/HKUDS/Vibe-Trading). Upstream moves fast. In the 51 days from October 11 to December 1, 2026, my watcher noticed upstream moving past my vetted pin 40 times. Each time it opened a task, and each time an AI agent vetted the new code before anything could reach the box that trades.

Sixteen of those forty vets ended with a HIGH verdict and no pull request. The latest one is the subject of this article. It was a delta of 333 commits and 878 changed files, and the agent stopped it in about ten minutes. It stopped it for the same two findings as the vet before it, in code nobody on my side had touched.

This is the story of how that gate works, why a big diff is the wrong thing to be afraid of, and what I learned about letting an agent say no.

## What Vibe-Trading is in my setup

Vibe-Trading is an upstream project from HKUDS: an AI agent that does market research, backtests and, through broker adapters, live orders. I run it as a component of my autonomous agent fleet, agent-corp. The deployment is deliberately small: one Alpaca **paper** account, a frozen mandate, a fail-closed order gate and a hash-chained audit ledger. Claude Code on the fleet's subscription decides what to trade; Vibe-Trading enforces the mandate.

I do not run upstream as is. I keep a fork with 25 numbered patches of my own, each with its own test. Three files pin the whole arrangement in my repo:

- `UPSTREAM_SHA`: the upstream commit I vetted.
- `FORK_SHA`: the fork head I actually deploy, which is upstream plus my patches.
- `patch_carriers.json`: the list of upstream files my patches touch, the "carriers".

Nothing reaches the trading box without passing through those pins, and the rollout service installs a new pin only after I approve it in Telegram.

## The gate, step by step

When upstream moves, the fleet's daemon opens a task with a fixed script. The executor is a headless Claude Code session in a container. It has three gates to clear, and it is told to stop at the first one that fails.

Gate 1: vet the delta. Clone upstream at the new head, run a static prescan over the whole tree, and deep-read the diff for every gate-relevant file. On a HIGH verdict the instruction is blunt: push nothing, open no PR, label the issue, comment the findings and close it.

Gate 2: rebase my patches. Only after a verdict below HIGH. Move the fork's `upstream` branch forward with a fast-forward push, create a new branch from the deployed fork head and rebase it onto the new upstream. Never force-push. Stop if a rebase conflict cannot be resolved without changing what one of my patches does.

Gate 3: open the bump PR. Move both pins, regenerate the carrier list in the same PR, and put the vet report in the PR body together with the exact command I run to record the verdict. The agent prints that command; it never runs it.

After merge, container tests and a smoke run under a HALT switch happen in the rollout service on the box. Then I approve the install.

## What "gate-relevant" meant this time

Three terms carry the rest of this article, so here they are in one place:

- **Gate-relevant file:** an upstream file that can change what the agent is allowed to do, as opposed to what it computes.
- **Carrier:** an upstream file one of my fork patches modifies. If upstream rewrites a carrier, my fix may silently stop working.
- **Carried finding:** a HIGH or MEDIUM finding from an earlier vet that is still present at the new head.

The task for the latest delta named the scale up front: upstream at `0b039db0`, my pin at `cee72998`, 333 commits apart. It listed 103 gate-relevant files. These are files that can change what the agent may do, not just what it computes:

- the CI workflow,
- the backtest engines and data loaders,
- the agent loop and its tool lifecycle,
- the config schema and limits,
- the live-trading mandate store and the order gate,
- the LLM provider adapters.

It also listed 13 files that my own patches depend on. An upstream change there can quietly undo one of my fixes, so the agent had to state, per file, whether my patch still does what it did.

Two details in that task are what made the run trustworthy.

First, the task told the agent that GitHub's compare API stops listing files at 300. The list in the issue was therefore incomplete by construction, and the agent had to run `git diff --stat` in its own clone and read what that showed. It did: the real delta was 878 files, 68,475 lines added and 31,636 removed.

Second, the task warned that the carrier list itself was stale. It had been derived from older pins than the ones deployed. A gate that trusts its own inventory without checking it is the quiet failure mode here. Writing the staleness into the task turned it into something the agent had to account for.

## The verdict is on upstream plus my patches

The rule that does the real work came out of an earlier round: the verdict is on upstream plus mine, not on upstream alone. The thing I would deploy is upstream's tree with my patches applied. So a finding carried over from an earlier vet counts as closed only when two things hold:

1. my fork carries a patch at that exact carrier, the file and construct the finding names;
2. that patch's own test passes on the new head.

A finding that is unreachable only because a tool allow-list withholds the tool does not count as closed. That is configuration, not a code boundary.

This rule matters because the alternative is drift in the other direction. Without it, every vet would re-report the same upstream issues forever, even after I had patched them. With it, a patch plus a passing test retires a finding. The absence of either keeps it at its original severity.

The rule has a weak point, and I know where it is: it trusts the patch's own test. A test that passes while missing the actual attack path would close a finding that is still open. That is why the rule names the exact file and construct, and why the vet re-runs the patch's test on every new head instead of relying on an earlier verdict.

## Why this delta stopped

The agent's report on the 878-file delta found no new HIGH. It stopped on two old ones, both carried from the previous vet and both still present verbatim at the new head. It verified that by reading the files at the new commit, not by inferring it from ancestry. It also showed that the previously vetted head was an ancestor of the new one, so the old code was carried forward. The check is one command, and the report quotes its output:

```
git merge-base --is-ancestor 84109fbb 0b039db0; echo $?
0
```

Both files are public. The snippets below are quoted from them at that exact commit, so anyone can check them.

H1: a model-authored file can grant a read root anywhere on disk. In [`agent/src/tools/path_utils.py`](https://github.com/HKUDS/Vibe-Trading/blob/0b039db0a7fe94b053358996674e3640c35d890f/agent/src/tools/path_utils.py), `session_workspace_for_run` reads the run's `req.json` and does this:

```python
declared = context.get("session_workspace") if isinstance(context, dict) else None
if isinstance(declared, str) and declared:
    workspace = Path(declared).expanduser().resolve()
    if workspace.name == "workspace" and workspace.is_dir():
        return workspace
sessions_root = (roots.runtime_root / "sessions").resolve()
workspace = (sessions_root / session_id / "workspace").resolve()
if not workspace.is_relative_to(sessions_root):
    return None
```

The containment check `is_relative_to(sessions_root)` only guards the fallback path. The declared path returns before it. The file-reading tool adds the result to its allowed read roots, so a prompt-injected model that writes this gets an arbitrary directory added as readable:

```json
{"context": {"session_id": "x", "session_workspace": "/any/dir/named/workspace"}}
```

H2: an unconditional shell hook channel with the full environment. In [`agent/src/product/resources/hooks.py`](https://github.com/HKUDS/Vibe-Trading/blob/0b039db0a7fe94b053358996674e3640c35d890f/agent/src/product/resources/hooks.py), commands from the runtime root's `hooks.json` run like this:

```python
proc = subprocess.run(
    command,
    input=json.dumps(context, ensure_ascii=False, default=str),
    text=True,
    capture_output=True,
    cwd=self.runtime_root,
    timeout=self.timeout_seconds,
    shell=True,
    env=dict(os.environ),
)
```

`shell=True` plus `env=dict(os.environ)` means every provider and broker key is visible to the hook. The hook manager is wired in unconditionally, independent of the flag that enables shell tools (default off) and of the sandbox (also default off).

Neither file appears in my carrier list, and none of my 25 patches touches either one. By the rule above, both findings kept their HIGH severity, and the run ended at gate 1: nothing pushed, no PR, issue closed with the report. From claim to close took about ten minutes.

Neither finding has a patch in my fork yet. Writing those two patches is queued work; until they land, the pin stays where it was vetted.

## The part of the report I trust most

A HIGH stop is easy to produce. Any vet can say no. What makes the report useful is the work it shows on everything that was not a stop:

- A per-carrier table for all 13 patch-dependent files. One row says the backtest runner now threads explicit roots through its path helper, which "tightens, does not loosen, path containment". Another says the CI workflow change is timeout and parallelism tuning "with no security content".
- Moved code was tracked, not assumed. Two carrier files were deleted upstream, the agent loop and the provider tool policy. The agent confirmed by grep that their logic moved to new modules rather than taking the deletion at face value.
- A rewrite was checked for silent weakening. A 1,721-line rewrite of the LLM provider was examined for exactly that risk. The redirect guard, header and credential validation moved into a separate module with the same logic.
- Every hit of a dangerous pattern was explained. The agent grepped the whole diff for `eval(`, `exec(`, `pickle.loads`, `os.system`, `shell=True`, `base64.b64decode`, `__import__` and raw network calls. One hit was test fixture code; another was a validated fetch of an official roster.
- One change was even a strengthening. Cancelling a live order now routes through the mandate gate instead of a best-effort audit after the fact.

That is what I mean by a gate-relevant review. The point is not reading 878 files with equal attention. It is naming the few places where the answer to "may this run?" can change, and showing the evidence for each.

## Forty deltas, sixteen stops

Across the 51 days, the pattern is not "upstream is dangerous". Plenty of bumps went through. Over the same period, at least fifteen bump PRs merged, several with a MEDIUM verdict and a clean rebase, and the pins moved forward each time.

The stops cluster. From November 1 to 8, seven heads in a row ended HIGH. A bump on November 9 moved the pin and retired two findings that my patches had closed. Then the stops came back in mid-November and again from November 28. The latest run is the third HIGH in a row, and the last two stopped on the same two findings.

That clustering is the useful signal. A single HIGH tells me about one commit. Repeated HIGHs on the same `file:line` tell me the finding will not go away by waiting for upstream. If I want to move the pin, the remedy is mine: a patch at that carrier with its own test, after which the next vet can close the finding by the rule. Until then, the deployed pin stays where it was vetted, and the trading box keeps running known code.

## What I have not measured

The vet's own error rate. I have no case on record where a HIGH verdict was later shown to be wrong, but I have not looked for one systematically either: a stopped delta produces no PR, so nobody re-examines it. A false positive costs me a pin that stays behind upstream for a few more days. A false negative costs more, which is why the gate leans toward stopping. Auditing a sample of past HIGH stops against the code is the next measurement worth making.

## What I took from it

The size of a diff is not the risk. 878 files sounded alarming. The decision came down to two functions, each a few lines long, in files the delta did not even need to touch.

Write the gate's blind spots into the task. The 300-file API limit and the stale carrier list were both stated in the task text. Both would otherwise have produced a confident review of the wrong inventory.

Define when a finding is closed, not only when it is found. "Patch at the exact carrier plus a passing test on this head" is a rule an agent can apply and I can audit. "Looks fixed" is neither.

Let the agent stop, and make stopping cheap. A HIGH ends the run with no branch, no PR and no merge decision for me to make. I read one comment. The expensive path, a rebase and a PR, only starts when the vet says it may.

Keep the last step human. The agent prints the command that records the verdict and never runs it. New pins reach the trading box only after I approve them in Telegram.

## FAQ

### What does the vet actually check in an upstream update?

It runs a static prescan over the whole upstream tree. Then it deep-reads the diff for every gate-relevant file, meaning anything that can change what the agent may do: loops, tools, config, order gates, provider adapters and CI. It also checks every file my own fork patches depend on.

### Why did a delta with no new HIGH findings still stop?

Two HIGH findings from the previous vet were still present at the new head. My fork carries no patch at either file. Under my rule, a carried finding is closed only by a patch at that exact place plus a passing test, so both kept their severity.

### Does a HIGH verdict block trading?

No. It blocks the pin from moving. The trading box keeps running the last vetted upstream plus my patches, and a new pin is installed only after a PR merges, the box's tests pass and I approve it.

### Why not just review the 300 files GitHub shows?

GitHub's compare API stops listing files at 300. The real delta here was 878 files. The task tells the agent to run the diff in its own clone for that reason.

### How long does a vet take?

The latest one, 333 commits and 878 changed files, went from claim to closed issue in about ten minutes.

## Related reading

- [Four Merge Presses, One Merge: Fixing the Approval Layer of My AI Agent Fleet](https://www.tytarenkoagency.com/blog/four-merge-presses-one-merge-approval-layer)
- [The Founder Decides Twice: A Universal Pipeline for an Agent Fleet](https://www.tytarenkoagency.com/blog/the-founder-decides-twice-a-universal-pipeline-for-an-agent-fleet)
- [When the Tripwire Cries Wolf: Small-Sample Review Metrics in an Agent Fleet](https://www.tytarenkoagency.com/blog/when-the-tripwire-cries-wolf-small-sample-review-metrics-in-an-agent-fleet)


