A coding agent on a laptop had already redacted a parser task when the free server probe returned inside the latency budget. The secret scan was clean, the freshness stamp was new, and the offline change count on that card was zero. While the remote generation was still running, a local typo fix landed in the same function the patch was about to touch. The returning patch matched the old snapshot and would have overwritten the newer line if the apply had been automatic.
The scene is a composite illustration for this tutorial, not a ticket pulled from a named company or a personal lab log. It still captures the tradeoff that appears once a remote runner starts to look cheaper than another local generation. Local execution protects secrets, keeps working through a dead link, and sees edits that arrive during the wait. A free server can win the generation itself when the payload is already safe and the measured round trip fits the budget.
The laptop should still win the apply step whenever that remote patch overlaps work written after the stamp. Admission and apply are different decisions, and a clean scan does not authorize a blind write to disk. Treating them as one step is how a fast, inexpensive hop corrupts a file the remote process never reread.
Admission is not the same as apply
The admission gate asks whether any free server may receive a redacted scaffold for this particular task. The apply gate asks whether the returned patch may change the tree that exists at the moment of return. Latency, secret class, and offline residue are admission inputs, while line overlap is strictly an apply input. A result can pass admission and still be rejected at apply time without any contradiction in the rules.
Disclosure: This article was prepared as part of MonkeyCode's product outreach. MonkeyCode appears here only as an operator-described option with free model access and a free server choice. This draft states no model names, token quotas, hardware sizes, or durations, because no primary source was supplied for those figures. The operator describes the project as open source, and the license should be read from the repository rather than inferred from this page.
Readers should confirm the live free model access and free server terms on the project site before planning a real workload. A price of zero does not relax either gate, and it does not make an env file safe to upload. The free server wins admission only when the probe fits the budget, the secret count is zero, and offline residue is absent. It loses admission when the probe fails, a denylist hit appears, or the stamp is older than the agreed window.
What to measure on the laptop
Latency has to come from a fresh probe, not from a diagram that a team remembered from the previous week. The task card stores a budget in milliseconds, and the probe stores a round-trip time that contains no repository text. A failed or missing probe counts as offline, even when a desktop icon still reports that the network is connected. Teams that skip the probe will eventually hand work to a path they have not timed on that day.
Secret class is a count of denylist hits inside the exact payload proposed for the remote call. The scan should cover env files, private keys, raw tokens, and uncommitted diffs marked local-only by the team. A single hit keeps the task on the laptop, because redaction after upload cannot recall a credential. This tutorial ships no universal denylist, so the repository owners need patterns that match their own tree.
Offline residue counts path changes that happened while the link was down, together with the age of the cached stamp. A stamp is a hash of the allowed files, written into a ledger that is required to remain on the laptop. When that hash no longer matches, admission should defer rather than offer a stale scaffold to a remote process. The deferral is intentional, and it costs less than a generation aimed at a tree the agent has already left behind.
How the three tradeoffs interact
A fast probe cannot rescue a payload that still contains a token, so latency never outranks secret class. A clean scan cannot invent connectivity, so good secret hygiene is not the same thing as an offline plan. An online path with a fresh stamp can still lose when the probe time exceeds the budget stored on the card. The laptop should then generate locally or wait, instead of paying for a round trip it has already judged too slow.
The free server wins only the narrow case in which admission is clean and the later overlap check stays silent. That narrow case is still useful, because a long completion can stall a laptop that is already busy with tests. The remote side returns text in that case, while the laptop remains the only place allowed to write the tree. If admission or overlap fails, the zero price of the server is irrelevant and the local outcome is the correct one.
Numbered workflow
The following sequence keeps measurement, admission, and apply in an order that a runner can audit later. Each step uses values the laptop can recompute, and none of the steps assumes a named model or a fixed quota. Operators can insert their own probe command at step four without changing the overlap rule at the end.
- Write a task card with a goal, allowed paths, a latency budget in milliseconds, and a freshness window in seconds.
- Hash the allowed paths, store the stamp in a local ledger, and refuse to copy that ledger to the free server.
- Build the outbound payload, run the secret scan, and keep the task local if the hit count is not zero.
- Probe the free server with a health request that carries no repository text, and record the round-trip time.
- Admit the redacted scaffold to the free server only when the probe fits the budget and the residue count is zero.
- On return, compute line ranges from the patch and from edits made after the stamp, then apply only if the ranges are disjoint.
- If the ranges overlap, leave the tree untouched and ask for a new stamp rather than forcing a merge in the agent loop.
Reference checker
The module below is an unexecuted reference for review, not a benchmark and not a log from a hosted run. It accepts measurements from the caller, and it neither opens a socket nor reads a real environment file. The numeric sample later in this section is illustrative input, not an observed latency from any product. Annotations use Python 3.10 union syntax, so an older interpreter should rewrite those hints before import.
from dataclasses import dataclass
from enum import Enum
class Decision(Enum):
LOCAL = "local"
FREE_SERVER = "free_server"
DEFER = "defer"
REJECT_APPLY = "reject_apply"
ALLOW_APPLY = "allow_apply"
@dataclass(frozen=True)
class Admission:
latency_budget_ms: int
probe_rtt_ms: int | None
secret_hits: int
stamp_age_s: int
freshness_window_s: int
offline_changes: int
payload_redacted: bool
@dataclass(frozen=True)
class Span:
path: str
start: int
end: int
def admit(card: Admission) -> Decision:
if card.secret_hits or not card.payload_redacted:
return Decision.LOCAL
if card.stamp_age_s > card.freshness_window_s or card.offline_changes:
return Decision.DEFER
if card.probe_rtt_ms is None or card.probe_rtt_ms > card.latency_budget_ms:
return Decision.LOCAL
return Decision.FREE_SERVER
def overlaps(left: Span, right: Span) -> bool:
if left.path != right.path:
return False
return left.start <= right.end and right.start <= left.end
def apply_decision(remote: list[Span], local_edits: list[Span]) -> Decision:
for patch_span in remote:
for edit in local_edits:
if overlaps(patch_span, edit):
return Decision.REJECT_APPLY
return Decision.ALLOW_APPLY
Save the module as overlap_gate.py in a scratch directory before the sample command is expected to import it. The sample command builds one admitted card and one overlapping span pair, then prints both decision values. The first line should print free_server for that clean card, and the second line should print reject_apply. The sample spans share parser.py across lines 60 through 68, so the inclusive overlap test is expected to fire.
python - <<'PY'
from overlap_gate import Admission, Span, admit, apply_decision
card = Admission(800, 140, 0, 12, 60, 0, True)
print(admit(card).value)
remote = [Span("parser.py", 40, 68)]
local_edits = [Span("parser.py", 60, 72)]
print(apply_decision(remote, local_edits).value)
PY
Move the local span to lines 80 through 90 and the apply check should print allow_apply for that pair. Set secret_hits to 1 and admission should return local, even though the probe time remains comfortably fast. Clear the probe value and admission should also return local, because a missing measurement is not a successful path.
Reading hunks into spans
Line ranges should come from the diff the agent would apply, not from a guess about the whole file. The helper below is also unexecuted reference code, and it reads unified hunk headers for a single path. It ignores renamed files, mode changes, and binary hunks, which need a richer parser than this tutorial provides. Feed it only the diff for one path, and keep real tokens out of the fixture text used in tests.
import re
HUNK = re.compile(r"^@@ -\d+(?:,\d+)? \+(\d+)(?:,(\d+))? @@")
def spans_from_unified(path: str, diff_text: str) -> list[Span]:
found = []
for line in diff_text.splitlines():
match = HUNK.match(line)
if not match:
continue
start = int(match.group(1))
count = int(match.group(2) or "1")
if count == 0:
continue
found.append(Span(path, start, start + count - 1))
return found
Append the hunk helper to the same overlap_gate.py file so tests can import spans and decisions together. A local git invocation can supply that diff without sending the patch to the free server at all. The command below prints a unified diff with zero context lines, which makes hunk headers easier to parse. Pipe that output into a local script that calls spans_from_unified, and compare those spans with edits made after the stamp.
git diff -U0 -- parser.py
That comparison stays on the laptop, even when the patch text was produced by a free server a moment earlier. A zero-context diff is a parsing aid, not a requirement that the agent generate patches with no surrounding lines. If a runner emits standard three-line context, the same hunk header still carries the starting line and the count. The ledger hash should be recomputed after any accepted apply, so the next card cannot reuse a stamp from the pre-patch tree.
Decision table
The table compresses the same rules the functions implement, so a reviewer can audit them without reading Python first. Rows are conditions the laptop can observe, and the result column is the only placement this workflow allows. A free server does not appear as a winner merely because it is offered at no charge.
| Condition | Result | Why it matters |
|---|---|---|
| Secret hit or payload not redacted | Stay local | Credentials and raw diffs never enter the free server |
| Probe missing, failed, or slower than the budget | Stay local | Offline or slow paths should not pretend to be remote wins |
| Stamp expired or offline file changes exist | Defer | The scaffold would describe a tree the laptop has already left |
| Clean admission, then overlapping local edits | Reject apply | A fast remote patch must not erase work done during the wait |
| Clean admission and disjoint ranges | Allow apply | Generation left the laptop, but the write still happens locally |
Contract checks to add
A team should encode the table as local tests before any runner is allowed to call a network. One test supplies a secret hit plus a tiny probe time and expects the local decision. Another test omits the probe and expects local, while a third sets an expired stamp and expects defer. A fourth test feeds overlapping spans and expects reject_apply, and a fifth uses disjoint spans after clean admission.
python -m pytest tests/test_overlap_gate.py -q
The pytest line is a suggested entry point, not evidence that a suite passed while this article was being written. Fixtures should use stand-in paths and fake token strings, or the test itself becomes a secret-handling failure. A green local run says nothing about queue delay, model quality, or how long a free server option will remain. Those unknowns are why the workflow rechecks terms outside the code instead of baking a quota into the card.
Limitations and who should skip it
The overlap helper treats ranges as closed and inclusive, which simplifies real diff hunks more than a merge tool would. Callers that need renames or binary files should extend the reference and label that extension as their own work. The function trusts caller-supplied spans, so a careless extractor can hide an overlap that should have blocked apply. Shared free servers remain a poor fit for regulated data, production secrets, and source that belongs to a customer.
Those workloads should stay local even when a toy card would have returned a free-server admission. This method assumes the laptop stays the source of truth and that someone can accept a deferral without a broken release. People who need an always-on remote workspace, or who cannot pause an agent on overlap, should not adopt the gate. Operators should reread the current free model access and free server terms, since this article is neither a quota nor a permanence promise.
Place the checker beside the runner that already builds patches, and point the probe at a health endpoint the operator trusts. Keep the freshness ledger on the laptop, and confirm the live terms on the MonkeyCode project page before a real handoff. Only after those checks should a redacted scaffold leave, and only a non-overlapping patch should be allowed to land.
Top comments (0)