Compare two contexts¶
ithrl compare tests whether a declared context change improves or degrades a fixed behavior.
Both contexts come from one immutable case. Install ithrl[compare] for statistical inference.
Both contexts keep the same triggering input, target, grader, model, reconstruction, policy and attempt limits. A second historical capture can suggest an intervention, but both arms execute from the selected case. See bundle comparisons and tool output investigations for qualified profiles and costs.
Try without a provider¶
Create the bundled deterministic case:
mkdir -m 700 ithrl-compare-demo
ithrl extract --example --output ithrl-compare-demo/case
The fake runner matches only when earlier user inputs A and C remain; restoring either alone
leaves the target unmatched. Their source-bound IDs are ctx-4c4e9663bfd5daae and
ctx-8a6964db1606f4e7.
Save this configuration as ithrl-compare-demo/comparison.toml with mode 0600:
schema_version = 1
kind = "comparison"
objective = "repair"
minimum_effect = 0.1
seed = 1
eligibility_policy = "independent-safe-preaccept-only"
freshness_seconds = 86400
[reference]
removed_context_ids = ["ctx-4c4e9663bfd5daae", "ctx-8a6964db1606f4e7"]
[candidate]
removed_context_ids = []
[calibration]
positive_minimum_matches = 2
negative_maximum_matches = 0
[calibration.reference]
required_valid = 2
max_attempts = 2
[calibration.candidate]
required_valid = 2
max_attempts = 2
[confirmation]
alpha = 0.05
[confirmation.reference]
required_valid = 20
max_attempts = 20
[confirmation.candidate]
required_valid = 20
max_attempts = 20
[limits]
max_provider_calls = 0
max_wall_time_seconds = 10000
attempt_timeout_seconds = 1
Inspect the pair and resource limits:
ithrl compare ithrl-compare-demo/case --config ithrl-compare-demo/comparison.toml \
--observation-store ithrl-compare-demo/observations.sqlite --dry-run
The report describes both contexts and the complete calibration and confirmation budget without collecting observations. Then run with the same configuration and store:
ithrl compare ithrl-compare-demo/case --config ithrl-compare-demo/comparison.toml \
--observation-store ithrl-compare-demo/observations.sqlite
Expect confirmed-improvement: restoring A and C raises the match rate from
zero to one, with a directional lower bound greater than 0.1. It collects four calibration and
40 fresh confirmation observations, makes zero provider requests and executes no returned action.
These sample counts demonstrate a large deterministic effect; they are not a general sample-size
recommendation.
Both contexts may be reduced. To try this, remove the irrelevant B input
(ctx-c30510481bc8c960) from both selections and start a new run. For your own investigation, use
IDs from its case.
Prepare a declared removal¶
ithrl prepare compare constructs a new ablation pair without hand-authoring its source bindings.
It compares an explicit baseline with that same context after a declared removal. Use the full
original to ask about the captured context, or a retained selection to ask about its smaller
context and existing edits. The resulting experiment uses the existing compare collector.
It does not search for a removal or extend an old run.
Preparation defaults to degradation when settings omit the direction; --objective repair asks
whether the declared removal improves the target's match probability and overrides the settings
file's direction.
Prefer an existing private comparison profile through --profile: it contains the exact resolved
experiment and plan and imports no observations. If a native profile is unavailable, follow
Detect, inspect and execute to acquire one within your authorization.
Detection may inspect authentication and start bounded local harness probes; it makes no provider
requests. Preparation itself does neither and refuses grading before any runtime probe.
Acquire the source profile in the environment intended for subsequent native detection. Proxy and certificate environment settings, native tools and Copilot SDK installation paths can change the capability identity. An otherwise identical package installation need not match an older profile. If the intended environment has changed, follow Specify the investigation and Detect, inspect and execute to acquire a fresh source profile using the original unpinned input experiment, or the case default only when it preserves the intended target, oracle and native choices. Reusing the old bundle's pinned experiment repeats the mismatch. Then prepare a new bundle with the fresh source profile. Keep the old profile, experiment and bundle unchanged; do not edit their pinned digests to make detection pass. Offline authoring can run elsewhere, but its recorded execution facts must match later detection.
Use --preflight RECEIPT --experiment EXPERIMENT only when the exact resolved experiment was
already saved and matches the receipt's plan. shrink --dry-run --save-preflight exports a receipt,
not that experiment file. Native selection can fill runner fields such as the capability digest,
so the original input or case-default experiment may differ from the resolved one. If the exact
experiment is missing, use a comparison profile; do not reconstruct a missing predicate or relax
identity checks. Omit --experiment with --profile.
For the provider-free case above, create an empty protected workspace and save a fake profile:
mkdir -m 700 ithrl-compare-demo/original
ithrl compare ithrl-compare-demo/case --config ithrl-compare-demo/comparison.toml \
--original-workspace ithrl-compare-demo/original --detect-capabilities \
--profile ithrl-compare-demo/source-profile.json
Then prepare removal of A from the full original:
ithrl prepare compare ithrl-compare-demo/case --baseline original \
--profile ithrl-compare-demo/source-profile.json \
--original-workspace ithrl-compare-demo/original --remove ctx-4c4e9663bfd5daae \
--output ithrl-compare-demo/ablation --calibration-samples 2 \
--positive-minimum-matches 2 --negative-maximum-matches 0 \
--confirmation-samples 20 --alpha 0.05 --minimum-effect 0.1 \
--seed 1 --freshness 86400 --max-provider-calls 0 --max-wall-time 10000
This creates a new mode-0700 directory with mode-0600 files:
comparison.toml: the exact baseline, candidate and prospective comparison settings.experiment.toml: the recorded input experiment, with its target, oracle and runner choices.ablation.json: private provenance, requested and effective removals, historical status, identities, budgets and unresolved native-readiness gates.
The normal summary identifies the baseline as original context, recorded preservation or an unconfirmed proposal. It separates requested whole-record removals from the effective additional removals after dependency closure, common baseline omissions and requested text edits. The private report retains the exact selections; the summary does not print their source text.
The prospective budget reports total attempts, provider calls and time using the recorded
per-attempt bounds. The JSON budget also includes the confirmation reserve. Time includes
configured pacing; local overhead is additional.
These totals describe planned collection. Actual provider calls and executed actions remain zero,
historical sample credit is zero, execution is not authorized and current native admission is
unchecked.
Preparation publication supports Linux only and requires renameat2(RENAME_NOREPLACE) in libc,
the kernel and destination filesystem. Other platforms refuse before writing; unsupported Linux
filesystems also refuse publication.
If the final directory sync fails after atomic publication, the command reports
preparation-published-durability-unconfirmed. The complete bundle exists, but crash durability
is unconfirmed. Inspect and preserve that output privately; retrying at the same path is refused.
The status is structurally-prepared; native-admission-unchecked. Inspect the private bundle, then
run the command printed by preparation (next_command in its JSON summary) for its dry run.
When a path contains terminal control characters, the text summary prints the command as a JSON
string labeled for decoding before use. Decode that string, or use the decoded next_command
from --format json; the terminal-safe escapes are not literal path characters.
For this fake-runner example, removing A makes
the target unmatched; execution with these settings can confirm degradation with zero provider
calls. The two calibration and twenty confirmation samples per arm demonstrate that deterministic
effect, not a general sample-size recommendation. Preparation itself collects no observations.
For your own case, replace every selector and statistical limit. Independently verify the
canonical --original-workspace root and that the new output is outside it, the case and all
inputs. A recorded workspace path does not establish that boundary. Preparation checks controlling
directories and metadata without reading workspace contents. Symlinks and Windows junctions in
output ancestors are refused. Preparation does not look up authentication, detect capabilities,
start a harness or open an observation database. Existing outputs are refused.
Choose the baseline and removal¶
Use one of these baseline argument sets with the other preparation inputs and limits:
| Baseline arguments | Meaning |
|---|---|
--baseline original |
Full immutable original; no retained result is needed. |
--baseline retained --result RESULT |
Validated published reduction with complete eligible recorded preservation and a compatible behavior profile. Incomplete search alone does not invalidate complete confirmation. |
--baseline retained --result RESULT --proposal |
Explicitly accept a reconstructable saved proposal while retaining its recorded loss, incomplete evidence or profile mismatch. |
--baseline retained --selection SELECTION |
Private ContextSelection JSON supplied directly; always a proposal, with no historical preservation claim or required paid reduction. |
RESULT must be a complete published current-format reduction snapshot, including one that records
partial evidence. A live .runs directory, raw retained JSONL, calibration-only snapshot, fuzz or
comparison result is not a saved reduction input. Malformed, foreign, unsafe or source-inconsistent
evidence refuses in every mode. A deterministic fake-runner result cannot establish native
preservation. Historical observations provide no new calibration or confirmation credit.
SELECTION contains removed_context_ids and, when present, its complete source-bound mutation.
For example, the synthetic demo's explicit baseline can omit only B:
{"removed_context_ids": ["ctx-c30510481bc8c960"]}
Save it with mode 0600, use a new output directory, and select A as the additional removal.
For a saved reduction, prefer --result so preparation validates the complete recorded selection,
including previous paragraph edits; copying retained IDs alone can silently restore removed text.
Repeat --remove ID for whole-record removals. Preparation expands atomic and dependency groups
and reports the complete effective change. A prior paragraph edit survives an additional record
removal only when its edited node remains retained. To remove paragraphs, use
--section CONTEXT:INDEX:SECTION_ID, with selectors from ithrl inspect sections; repeat within
the same original field. Further paragraph removal unions original section IDs, preserving the
old edit. To remove one tool output text span, use --span FIELD_ID:START:END, with the
original codepoint positions. Both record partitions must stay identical
and the reference must have no mutation. Preparation refuses existing append/span baselines,
multiple edited fields, removal of an edited node, protected changes, absent units and no-ops.
Statistical settings may instead come from optional --settings FILE; explicit statistical options
override that file. The file must contain complete valid settings before overrides apply; options do
not fill missing TOML fields. It uses kind = "comparison-preparation", the comparison's
statistical fields and [limits], without [reference], [candidate], model, provider or
reasoning overrides. The attempt timeout must match the recorded execution facts. Direct
sample-count options allocate no replacement slots. Choose all counts, gates, direction, error
allocation, effect threshold, eligibility, seed, freshness and budgets before collecting
observations. Shared preparation settings are independent of the source harness; native
qualification profiles do not supply defaults.
Verify the native handoff¶
For native inputs, preparation's printed command performs separate current detection
with the generated configuration and recorded per-attempt request cap. Keep its
--preparation BUNDLE/ablation.json argument during detection, dry run and initial execution.
ithrl checks the detected profile's exact experiment, plan, selections, workspace, policy and limits
against the draft. Changed inputs require a new bundle; a runnable profile alone does not establish
that it matches the prepared intervention. Recorded non-null input-token limits refuse because the
comparison CLI cannot preserve them.
After detection, use the saved profile for the
normal dry-run and execution procedure, keeping the preparation
argument and omitting --experiment. The preparation report grants no execution authority and
establishes no new native qualification. Check the supported-inputs table and authorize the exact
current profile separately. A native readiness or reconstruction refusal is not a behavioral
nonmatch.
A confirmed degradation concerns the complete tested removal under its declared baseline. It supports neither individual necessity nor a unique historical cause. Failed calibration and inconclusive confirmation establish neither no effect nor redundancy. An effect confirmed only against retained context does not establish that the full-original effect differs. See the ablation design for the estimands and validation proposal.
Specify the investigation¶
Choose the target and intervention before collecting observations. Use --experiment FILE to
supply the target, oracle and optional cooperative grader, or omit it to use the case default.
A saved profile contains the frozen experiment and cannot be combined with --experiment.
For a native case, the predicate must keep the captured target category (final-response or
shell-action), but need not match the historical response. It defines the prospective behavior
tested in both arms; the captured decision remains unchanged and supplies no sample credit.
The comparison configuration sets sample counts, direction, freshness and resource limits.
Each selection lists removed_context_ids and an optional source-bound mutation. Removing a
record also removes records that depend on it. An empty selection means the full original.
Prior-user edits use the same
text contracts as reduction and fuzzing; comparison
also implements the tool output text span contract.
Unsupported edits and removal of the triggering input are refused before sampling.
Use a different predicate¶
Copy the case's default experiment before changing the predicate. In the command below, CASE is
the extracted case and PRIVATE is an existing directory with mode 0700, outside the case and
original workspace:
install -m 600 CASE/experiments/default.toml PRIVATE/experiment.toml
For a literal final-response check without task grading, replace the copy's entire [target]
table with:
[target]
type = "final-response"
text_contains = "EXPECTED_PHRASE"
Replace EXPECTED_PHRASE with the nonempty, case-sensitive text that defines the behavior you want
to measure. Use only one of text_equals, text_contains or text_contains_any; the last accepts
an array of literal alternatives. For shell targets, keep the copied tool identity and action count
and use either command_equals or command_contains. Keep the target category and all other
tables unchanged, including oracle protections, runner settings and any sampling or grading
configuration. A task grader requires its unconstrained final-response target.
Pass the copy with --experiment PRIVATE/experiment.toml during
capability detection. Once the profile is saved, omit --experiment:
the profile contains the frozen experiment. Keep the source case unchanged; a different predicate
requires a new profile and run.
Select records and text¶
Use the id values in the case's private context.jsonl edit graph for whole-record removals.
It records dependencies and protected units; native session IDs are not context selectors.
For a previous reduction, retained-context.jsonl identifies its surviving units, and
ithrl inspect retained CASE --result RESULT --format json relates the retained partition to the
original graph. For a further removal, prefer preparation to preserve
the complete saved selection. When manually authoring a pair, copy the chosen removals and any
existing mutation into [reference] and [candidate]; restoring a record means omitting its ID
from that selection's removals. Keep the source case unchanged.
List eligible text fields and their source-bound selectors without a model call:
ithrl inspect sections CASE --format json
For paragraph removal, copy context_id, content_index, original_text_digest and
policy_digest from one fields entry, then choose its sections[].id values in source order.
Replace the uppercase placeholders below with those values:
[[candidate.mutation.edits]]
operation = "remove-text-sections"
context_id = "CONTEXT_ID"
content_index = 0
original_text_digest = "ORIGINAL_TEXT_DIGEST"
policy_digest = "POLICY_DIGEST"
section_ids = ["SECTION_ID"]
To append literal text instead, use this edit shape with an eligible prior-user field's selectors:
[[candidate.mutation.edits]]
operation = "append-text"
context_id = "CONTEXT_ID"
content_index = 0
original_text_digest = "ORIGINAL_TEXT_DIGEST"
text = "Additional context."
Use the field's reported content_index, which need not be zero. Each context permits at most one
text-field edit. Appends require an otherwise unchanged context; section removals may accompany
record removals when the edited field survives. Native admission checks support for the selected
target and edit before sampling.
Select tool output text¶
Tool output text discovery and edit authoring are provider-free. Check supported inputs and the tool output investigations for qualified final-response profiles.
List eligible prior tool output fields:
ithrl inspect tool CASE --format json
Select a reported field_id. Use the bounded
tool output text display to examine it privately.
Ranges are nonempty and half-open, in original Unicode codepoints. For example, a string containing
é, one LF and X has three codepoints and four UTF-8 bytes. The range [0, 1) removes é;
[1, 2) removes the LF. An escaped display such as é\nX has different positions from the source.
Select text from the original field, not its escaped display or UTF-8 byte positions.
Save the exact substring in a private UTF-8 file without changing escapes, line endings or trailing
characters. The helper below locates a unique occurrence and reports original codepoint offsets.
Run it in the Python environment containing the same ithrl installation or build as your CLI.
Replace CASE, FIELD_ID and SNIPPET with the case path, discovered field ID and private snippet
file:
python - CASE FIELD_ID SNIPPET <<'PY'
import sys
from pathlib import Path
from ithrl.case import CaseWorkspace
evidence = CaseWorkspace.open(Path(sys.argv[1])).load()
_, site = evidence.tool_output_text_field(sys.argv[2])
snippet = Path(sys.argv[3]).read_bytes().decode("utf-8")
start = site.original_text.find(snippet)
if not snippet or start < 0 or site.original_text.find(snippet, start + 1) >= 0:
raise SystemExit("The snippet must occur exactly once in the original field.")
print(f"START={start}\nEND={start + len(snippet)}")
PY
The helper prints only offsets. Reading bytes preserves line endings; an added newline or different
escaping will not match. For manual inspection, use context_id to find the node in
context.jsonl, then source, selector.line and field_path to locate its native snapshot,
JSONL line and JSON pointer.
Use the reported integer START and END values:
ithrl inspect tool CASE --field FIELD_ID --start START --end END --format json
Copy mutation.edits[0] from the report into the candidate configuration below. Replace every
uppercase placeholder and both offsets with the reported values, including the full field ID and
digests. The example offsets delete the field's first codepoint:
[reference]
removed_context_ids = []
[candidate]
removed_context_ids = []
[[candidate.mutation.edits]]
operation = "remove-tool-output-text-span"
context_id = "CONTEXT_ID"
field_id = "FIELD_ID"
original_text_digest = "ORIGINAL_TEXT_DIGEST"
start = 0
end = 1
removed_text_digest = "REMOVED_TEXT_DIGEST"
Only the candidate may contain a span deletion; keep the reference unmutated. Both contexts must retain the same records after dependency closure, including the edited field and its dependencies. The edit preserves the result envelope, triggering input and other fields. Removing the complete field produces an empty string; native reconstruction may omit an empty content block. Common record omissions condition the comparison on the retained context. Shrink and fuzz do not accept this operation.
Choose direction and samples¶
Set objective according to the question:
| Objective | Positive calibration arm | Negative calibration arm | Directional effect |
|---|---|---|---|
repair |
Candidate | Reference | p(candidate match) − p(reference match) |
degradation |
Reference | Candidate | p(reference match) − p(candidate match) |
The positive arm must reach positive_minimum_matches; the negative arm must have no more than
negative_maximum_matches. prepare compare exposes those same gates as
--positive-minimum-matches and --negative-maximum-matches. For example,
--objective repair --positive-minimum-matches 2 --negative-maximum-matches 0 requires at least two
candidate matches and no reference matches. Both arms require complete eligible calibration
samples. Failure ends the run with calibration-failed; successful calibration permits fresh
confirmation. Calibration observations receive no confirmation credit.
To permit replacement attempts, set eligibility_policy = "safe-provider-transport" before any TOML
tables. Keep required_valid fixed and set a larger max_attempts for each arm before collection.
The policy permits a fresh scheduled attempt after a verified typed transport failure, preventive
timeout or structured overload with no behavioral output. It requires no requested actions, enforced
action denial, unchanged protected state and verified cleanup. Unknown provider acceptance and the
full conservative call charge remain recorded; errors never count as behavioral losses. Captured
behavioral output, unsafe attempts and unresolved dispatches remain ineligible. For the strict
independent-safe-preaccept-only and narrower safe-provider-overload policies, see
sampling eligibility.
Replacement uses only frozen spare slots and resource allowance; it never extends a terminal plan.
After calibration, the command durably selects the pair and collects one fresh, randomized
confirmation block. A confirmed effect requires its one-sided lower bound to exceed minimum_effect
at the declared alpha. See comparison results for
outcomes, statistical assumptions and accounting.
Prepare native execution¶
Check the native prerequisites and supported inputs. Keep the observation store and profile outside the case and original workspace. Native execution protects the source case and original workspace and denies returned actions. Structural detection alone does not establish experimental support.
Before detection, replace the demonstration's synthetic selectors and [limits] settings. Choose
an attempt_timeout_seconds suitable for the native continuation, a nonzero max_provider_calls
and a max_wall_time_seconds that can admit both calibration and confirmation. Each arm's
max_attempts includes any permitted replacement attempts. The dry-run report calculates the
complete request and wall-time ceilings from these counts and the detected per-attempt cap,
cancellation grace and pacing; do not size a full comparison from calibration alone.
Choose execution settings¶
Before detecting capabilities, place any execution overrides before the first TOML table in
comparison.toml. The same settings apply to both harnesses; replace the placeholders with
supported values and omit settings you do not need:
model = "MODEL_ID"
reasoning_effort = "EFFORT_LEVEL"
Omitted settings use the values saved in the experiment supplied with --experiment. Explicit
values that conflict with saved values are refused. Without a saved value, provider and model use
the captured values when available, and the runner selects reasoning effort.
Codex can select a locally configured provider with provider = "PROVIDER_ID". Copilot uses
github-copilot and rejects other providers.
Both arms use the same resolved settings. Detection records the execution and history policy in the profile; native execution verifies the requested settings before forwarding inference. Source evidence remains unchanged. Inspect the resolved policy and report any history projection separately from the context edit. Changing execution settings requires a new profile and fresh observations; observations from different settings cannot be pooled.
Detect, inspect and execute¶
In the commands below, CASE is the case directory, ORIGINAL the original workspace, STORE
the private observation database and PROFILE the saved profile file. Omit
--experiment PRIVATE/experiment.toml to use the case's default experiment; otherwise use the
private copy prepared above.
-
Detect and save a profile, with zero provider requests:
bash ithrl compare CASE --config comparison.toml --experiment PRIVATE/experiment.toml \ --original-workspace ORIGINAL --detect-capabilities --profile PROFILE -
Inspect the plan without starting a harness:
bash ithrl compare CASE --config comparison.toml --profile PROFILE \ --original-workspace ORIGINAL --observation-store STORE --dry-runCheck both contexts, objective, provider, model, action denial and request/time limits. If the report refuses the budget or freshness window, revise the configuration and repeat detection with a new profile before execution. Configuration changes invalidate the saved profile.
-
Execute the reviewed plan within your authorization:
bash ithrl compare CASE --config comparison.toml --profile PROFILE \ --original-workspace ORIGINAL --observation-store STORE --acknowledge-model-executionExecution rechecks the saved profile and makes provider requests within its frozen limits.
--max-provider-calls-per-attempt can set a lower native request cap during detection. It becomes
part of the saved execution identity. The command admits whole blocks and reserves confirmation
capacity. Its displayed ceilings are conservative bounds, not token or monetary budgets.
The four arms may schedule at most 1,000 attempts in total. Large context bindings can require a
smaller plan to fit the private result snapshot; preparation reports comparison-evidence-capacity
before collecting observations.
Stop after calibration¶
Add --calibration-only to a new run or an unselected resume to stop before selection and
confirmation:
ithrl compare CASE --config comparison.toml --profile PROFILE \
--original-workspace ORIGINAL --observation-store STORE \
--acknowledge-model-execution --calibration-only
The configuration must still reserve the complete comparison budget. With three required valid
observations and three maximum attempts per calibration arm, the pilot permits six attempts;
provider requests are bounded by the profile's per-attempt cap. A one-request cap permits six
requests. Successful calibration reports calibrated and saves an inspectable nonterminal snapshot.
It does not establish a confirmed effect. Repeating --resume --calibration-only reuses the
completed pilot without dispatching more observations.
Review calibration before continuing. If confirmation is authorized, resume without
--calibration-only to collect fresh observations within the original allowance and deadline.
Calibration observations supply no confirmation credit, and calibration-only mode is refused
after confirmation has been selected.
Results and resume¶
Normal output contains identities, edit metadata, counts, bounds and accounting, without source
text or model responses. --format json writes one JSON report to stdout; plan and progress go to
stderr. Save the reported result_path and run_state_path.
Use comparison inspection to read a private snapshot, interpret its outcome or validate its source selections without a native runtime.
Resume only the canonical run directory:
ithrl compare RUN_DIRECTORY --resume --acknowledge-model-execution
Resume preserves the pair, target, policy and allowance. It never repeats completed confirmation or redispatches an unresolved attempt. Inspecting an already completed run requires no execution acknowledgment or native detection. Resume requires the implementation that created the run; use offline inspection for results from a different implementation. An expired freshness window or wall-time allowance ends the comparison; inspect its saved evidence before preparing a new run.
If publication fails, follow the reported recovery action. Restore write access for an output failure, or preserve a conflicting destination file elsewhere. Then resume to publish the saved terminal evidence without collecting again; ithrl never overwrites the conflicting file.