
Fine-Tuning a Pi Harness Adapter for porc
In How We Evaluate and Improve porc (Pi + ORC) with Harbor, prompt tuning and harness fixes took a frontier model from 6/24 to 24/24 on cross-session ORC tasks. That left the harder question for smaller open models: can a 27B model learn to check shared memories, follow stored procedures, and write back workspace state reliably without a long prompt doing all the work?
Hugging Face's Harness Adapters at Scale gave a clean starting point. Their team trained a specialist LoRA for Pi (harness-hub/Qwen3.8-27B-pi-adapted) directly inside the Pi harness, lifting Qwen/Qwen3.8-27B on SWE-bench Pro and Terminal-Bench 2.1 while cutting tool calls in half. I stacked two-stage GSPO reinforcement learning on top of that Pi adapter inside containerized porc environments and published the resulting adapter as niradler/Qwen3.8-27B-pi-porc.
On a 56-task benchmark across 15 task families (5 attempts per task, 280 trials per arm, thinking off), the adapter lifted porc pass rate from 67.1% to 80.7% (+13.6 points, paired bootstrap 95% CI [+7.5, +20.0]). Consistency moved even faster than the average: tasks solved on all 5 attempts rose from 24 to 37, while inconsistent mixed-outcome tasks dropped from 23 to 15.
Why stack RL on top of the Pi harness adapter
Starting from harness-hub/Qwen3.8-27B-pi-adapted (LoRA r=32 / alpha=64) instead of base Qwen/Qwen3.8-27B saved me from re-teaching basic coding-agent habits. That adapter already knows Pi's read, write, edit, and bash tools, runs cleanly with thinking off, and solves coding tasks without meandering.
When I added porc (@orc/pi) on top of the Pi adapter, the extension alone delivered a huge jump: across 56 tasks, pass rate rose from 11.4% without porc to 67.1% with porc. Even with that jump, the baseline model missed a third of all attempts and only passed all 5 attempts on 24 of 56 tasks.
The gaps clustered around multi-step shared state. Reading a short team convention from memory already sat at 97%, and creating jobs, skills, or pads was already at 100%. Following a multi-step procedure stored in an ORC task sat at 13%, following a procedure in a knowledge base sat at 60%, following one in a pad sat at 0%, and writing a guardrail rule sat at 60%. That is the exact gap an extension-specific harness adapter should close.
How RL works end to end on a porc task
If you have never trained an agent with reinforcement learning, the mechanism is simpler than the jargon makes it sound. There is no labeled demonstration telling the model which tool to call next. Instead, the model tries the same task multiple times inside a real container, an automated grader scores only the final state, and the trainer reinforces the attempts that passed while discouraging the ones that failed.
Every rollout runs the real harness inside an isolated Docker container: pi 1.7.0, the built porc extension connected to a live ORC v0.1.75 daemon over HTTP MCP, and a non-root agent user. Before Pi starts, the container seeds the workspace files and ORC state, deletes the temporary seed folder, and locks /tests away from the agent.
Trace one real 6-rollout training group from Stage 2. The prompt asks Pi to write pwpolicy.py implementing our password policy (>= 12 characters, uppercase, digit, and rejecting the word "kestrel"). /app is empty, and the rules live in ORC's knowledge base (policies/passwords.md). Notice what feedback the model actually receives: no text critique or failing test output is ever fed back during training. The grader runs python3 assertions against pwpolicy.py, emits a single scalar (PORC_REWARD 0 or 1), and the trainer turns that scalar plus output tokens into per-rollout feedback:
- Failing rollout (1 of 6,
1,679tokens): callsmemory_list,skill_list, andbash("ls -la /app && grep -rin password /app"), never checks the KB, and guesses wrong rules. Grader returnsPORC_REWARD 0, sor = 0.000. - Passing rollouts (5 of 6,
307to1,064tokens): callorc(invoke, "kb_search"), readpolicies/passwords.md, and pass all 6 assertions. Grader returnsPORC_REWARD 1, and the token bonus0.1 * max(0, 1 - out_tokens / 6000)producesr = 1.095for the 307-token pass down tor = 1.082for the 1,064-token pass. - Scalar advantage and token masking (GSPO): the group mean across all 6 rollouts is
0.907. Subtracting the mean (A = r - mean) gives-0.907to the failing guess,+0.188to the shortest pass, and+0.175to the longest pass. Prompts and<tool_response>tokens are masked out (loss = 0), soAlands strictly on the model's own generated tokens (its tool calls and code). GSPO updates only ther=96LoRA matrices (alpha=192onq,k,v,o,gate,up, anddownprojections, zero KL penalty) while keeping baseQwen/Qwen3.8-27Bfrozen.
You can see that exact behavior shift on kb-sla-hours, an unseen evaluation task that asks Pi to write sla.py with first-response SLA hours (P1..P4) per the support SLA policy stored in policies/sla.md (1h, 4h, 24h, 72h). On the baseline Pi adapter, 3 of 5 attempts failed: one ran ls -la /app && grep -ri sla /app, concluded no policy doc existed, and guessed P1: 1, P2: 4, P3: 8, P4: 24. After RL, 5 of 5 attempts called orc(invoke, kb_search), read policies/sla.md, and wrote the exact table.
Evaluation bench and disjoint training tasks
To test real procedure following alongside ORC primitives, I built porc-bench (56 tasks across 15 families, stratified into a 32-task dev split for Stage 2 checkpoint selection and a 24-task held-out test split). Hand-templated tasks cover memories, reference docs, jobs, rules, past sessions, and plain coding controls. Multi-step procedure tasks adapt offline business-app reconciliation workflows from harness-hub/automation-adapter-envs (simulated CRM, payroll, order, dispatch, and invoicing apps), stripping the rules out of the prompt and placing them inside an ORC skill, KB doc, task, or pad.
| Family group | Eval tasks | What the agent has to do |
|---|---|---|
procedure-skill, procedure-kb, procedure-task, procedure-pad | 20 | Find a multi-step reconciliation procedure in ORC and execute it against simulated business apps |
memory, reference-kb | 10 | Recall a team convention or internal catalog from ORC and apply it in code |
write-task, write-memory, write-rule, write-job, write-skill, write-pad | 15 | Persist a rule, task with priority, memory, cron job, skill, or rollout pad into ORC |
jobs | 2 | Trigger an existing ORC job and record its output |
past-session | 4 | Reuse a decision recorded in an earlier Pi session transcript |
control | 5 | Plain self-contained coding tasks where ORC is not needed |
Training ran on disjoint tasks across the same families (excluding past-session, because ORC v0.1.75 inside the container never indexed the seeded Pi session transcripts), with five automation domains kept strictly eval-only.
Headline results: 67.1% to 80.7% pass rate and 37/56 solved every time
Training ran in two stages under GSPO with thinking off, temperature 0.8, top-p 1.0, 65,536-token context, and an 8,192-token per-turn cap:
- Stage 1 (pass-only RL): 21 steps from the Pi adapter on 207 training tasks, group size
n=3, learning rate5e-6, binary pass/fail reward only. This checkpoint was re-evaluated on the final container image rather than retrained. - Stage 2 (mean-centred RL + token tie-break): resumed from Stage 1 step 21 for 3 steps on the expanded 227-task training set, group size
n=6, 12 prompts per step, learning rate5e-6, group standard-deviation normalization disabled, with a0.1 * max(0, 1 - output_tokens / 6000)bonus on passing episodes and-0.1on failed episodes with any turn at or above8,000tokens.
All evaluations below use the same fixed container image, 5 attempts per task (280 trials per arm), de-duplicated per (arm, task, attempt):
Metric (porc enabled, 56 tasks x 5) | Pi adapter (baseline) | Stage 1 (step 21) | Final (Qwen3.8-27B-pi-porc) |
|---|---|---|---|
| Pass rate | 67.1% | 76.8% | 80.7% |
| Tasks solved on all 5 attempts | 24 | 27 | 37 |
| Tasks with mixed outcomes (1-4 of 5) | 23 | 26 | 15 |
| Tasks failed on all 5 attempts | 9 | 3 | 4 |
| Median generated tokens / attempt | 776 | 1,324 | 1,063 |
| Generated tokens / solved task | 2,603 | 3,908 | 3,505 |
| Median tool calls / attempt | 5 | 8 | 7 |
| Attempts with a turn >= 8,000 tokens | 1 | 3 | 2 |
| Share of tool calls going to ORC | 58% | 65% | 65% |
Paired by task with a bootstrap 95% confidence interval:
| Comparison | Tasks | Pi adapter | Stage 1 (step 21) | Final adapter | Final vs baseline (95% CI) |
|---|---|---|---|---|---|
With porc, all tasks | 56 | 67.1% | 76.8% | 80.7% | +13.6 pts [+7.5, +20.0] |
With porc, dev split | 32 | 65.6% | 78.1% | 84.4% | +18.8 pts (checkpoint chosen here) |
With porc, held-out test split | 24 | 69.2% | 75.0% | 75.8% | +6.7 pts [-0.8, +15.8] |
Without porc, all tasks | 56 | 11.4% | 17.1% | 21.1% | +9.6 pts [+5.0, +14.6] |
Without porc, held-out test split | 24 | 7.5% | 13.3% | 20.0% | +12.5 pts [+6.7, +18.3] |
The biggest per-family gains landed directly on procedure following and knowledge lookups: procedure-task climbed from 13% to 67%, procedure-kb from 60% to 94%, reference-kb from 67% to 93%, procedure-skill from 77% to 91%, and write-rule recovered from a Stage 1 dip (60% -> 40%) to reach 80%.
Shaping the training data and reward to make RL work
Getting the training set and reward signal right mattered far more than sweeping hyperparameters. Four changes turned noisy runs into a steady climb.
Keep the full task mix and grow data around real failure modes
My first instinct was to train only on families with headroom, dropping saturated families (memory, jobs, write-job, write-skill, write-pad, and control) to save rollout budget. That backfired fast. The narrow 137-task mix at lr=2e-5 collapsed in 10 steps (64.3% -> 45.8%) into zero-tool-call repetition hitting the 8,192-token cap. Without saturated tasks in the batch, nothing pushed back when the policy drifted on them. Putting all families back at lr=5e-6 kept saturated capabilities at 100% while hard families climbed.
After Stage 1 reached 76.8%, inspecting per-task trajectories pointed straight to the next data addition. On write-rule, the policy dropped from 60% to 40% while spending up to 130 tool calls retrying policy JSON syntax. On control, one task (ctl-slugify) started failing because the model wrote code once and stopped without running tests. For Stage 2, I expanded the training set from 207 to 227 tasks by adding 10 new write-rule specs and 10 edge-case control coding tasks where one-shot writing fails.
Before training on any new task, the data pipeline enforces three invariants: the reference solution scores 1, a no-op scores 0, and a seed audit queries ORC from the agent's side to confirm every seeded skill, memory, KB doc, task, pad, and job actually exists (295/295 task seeds in the container image, including the 12 excluded past-session training seeds, after catching a silent orc skill create rejection tracked in niradler/orc#637 and removing /tmp/seed before Pi starts). That audit is what made procedure-skill jump from flat 77% in Stage 1 to 91% in Stage 2 once the training skills were present and readable through ORC.
Turn off group std normalization so a token bonus stays a tie-break
Stage 1's pass-only reward taught persistence at a real token cost. Median generated tokens per attempt rose from 776 to 1,324, and generated tokens per solved task jumped 50% (2,603 -> 3,908). On write-rule, median tokens jumped from 886 to 9,435.
Adding a small 0.1 token-efficiency bonus on passing episodes looked like the obvious fix. Instead, three intermediate efficiency runs cut tokens and dragged dev pass rate down right alongside them. Even on the fixed data with n=6, dev pass fell from 83.3% to 78.1% by step 3 while dev median tokens fell from 1,262 to 980.
The culprit was group standard-deviation normalization. When every rollout in a group passes, their rewards differ only by the token bonus (for example 1.095, 1.090, and 1.085). Dividing by that tiny 0.0041 group standard deviation blows a 0.005 token gap up into ±1.22 policy advantages, matching the magnitude of a pass/fail group. The 0.1 weight never mattered.
Disabling group standard-deviation normalization (--disable-grpo-std-normalization, using plain mean-centred advantages) fixed it immediately. The length term stayed a ~0.01 tie-break against ~0.50 for pass/fail. Resuming from Stage 1 step 21 at lr=5e-6 and n=6, Stage 2 climbed on dev from 82.3% to 85.4% at step 3 while cutting dev median tokens 14% (1,127 -> 974), then plateaued between 82% and 84%. Step 3 became the released checkpoint.
What changed in the trajectories beyond pass rate
Looking past the headline average surfaced three operational shifts:
- Plain coding controls stayed clean: on the 5
controltasks (25 attempts), pass rate stayed at80%, totalorccalls across all 25 attempts stayed at5(identical to baseline), and median generated tokens edged down from239to219. RL did not make the model spam ORC on ordinary code. - The adapter learned ORC beyond the
porctool wrapper: whenporcwas disabled (porcoff,orcCLI still onPATH), pass rate still climbed from11.4%(32/280) to21.1%(59/280). Passing attempts mentioningorcrose from8to31, whilecontrolstayed flat at21/25. The model learned to call theorcCLI viabasheven when the extension was turned off. - De-duplicating eval rows prevented false alarms: raw sample dumps occasionally repeated attempt indices. At step 27 of Stage 1, the raw metric read as a collapse to
0.646when the de-duplicated score was0.750. Every table in this post counts each(arm, task, attempt)exactly once.
Try Qwen3.8-27B-pi-porc with Pi
The released adapter at niradler/Qwen3.8-27B-pi-porc is standalone on top of Qwen/Qwen3.8-27B. It already includes the Pi adapter, so do not load both. The stage1-step21 revision is also tagged on Hugging Face if you want to compare stages.
- Serve the adapter locally with vLLM (thinking off matches training and evaluation):
vllm serve Qwen/Qwen3.8-27B \
--enable-lora --max-lora-rank 128 \
--lora-modules qwen3.8-pi-porc=niradler/Qwen3.8-27B-pi-porc \
--language-model-only --enable-prefix-caching --mamba-cache-mode align \
--enable-auto-tool-choice --tool-call-parser qwen3_xml --reasoning-parser qwen3 \
--default-chat-template-kwargs '{"enable_thinking": false}' \
--max-model-len 131072- Install Pi and
porc, and install ORC (desktop app or CLI) and keep the daemon running:
npm install -g --ignore-scripts @earendil-works/pi-coding-agent@1.7.0
pi install npm:@orc/pi- Point
~/.pi/agent/models.jsonat the local server using"api": "openai-completions"(the adapter was trained on Chat Completions, not the Responses API):
{
"providers": {
"local": {
"baseUrl": "http://localhost:8000/v1",
"api": "openai-completions",
"apiKey": "dummy",
"models": [{ "id": "qwen3.8-pi-porc" }]
}
}
}Then start Pi against the local model and bind a repository to an ORC project with /orc:
pi --provider local --model qwen3.8-pi-porcSummary
A few high-level caveats stay open. The held-out test split is small (24 tasks, 69.2% -> 75.8%, 95% CI [-0.8, +15.8], with Stage 2 vs Stage 1 nearly flat on test pass rate at 75.0% -> 75.8% while winning on 5/5 consistency and lower token cost, and Stage 1 step 21 chosen before the dev/test split). General coding benchmarks (SWE-bench Pro, Terminal-Bench 2.1) were not re-run beyond the 5-task control family, procedure-pad (20%) and write-rule token retries (13,080 median tokens) still have headroom, past-session stayed unindexed in ORC v0.1.75 containers (20%), and everything ran with thinking off on a single 27B base model.
The main lesson from both this run and my earlier notes in Post-Training: When a Specialist Beats a Bigger Model is how much of post-training is environment and measurement hygiene. Auditing seeded state from the agent's side and turning off group std normalization moved the score more than any sweep over reward weights. Next, I want to fix container session indexing so past-session can enter training, tighten write-rule policy validation in ORC so the agent stops burning retries on schema errors, and measure retention on Terminal-Bench 2.1.

