Skip to content

Commit 2f064dd

Browse files
committed
fix(audit,cli): Codex review — unbiased sampling, classified group signature, truncation root kind, core-crash report
Four verified findings from the #309 review, all real: 1. Sampling bias (P1): taking the first `sample` instances in heap-enumeration order could catch only old garbage and miss a later durably-held instance — a false OBSERVED_ONLY. ALL matching instances are targeted now: the verdict is exact over the whole population, and only PATH RESOLUTION is sampled (bounded at `sample` paths). 2. Group signature (P1): grouping by hop type names merged stack-rooted and durably-rooted instances sharing a type sequence, classifying the whole group by whichever path came first. The signature now carries the classification and the per-hop fields. 3. Truncation (P1): stopping the unwind at maxHops yielded ClrRootKind.None -> 'unsupported-root:None', which the verdict counts as durable — a long stack-only path read as RETAINED. The parent chain is now walked to the true root for the verdict; only the RENDERED path stays bounded. 4. Core-crash report (P2): the rc-70 branch returned exit 5 without writing ~/.owen/diag/last-failure.json, contradicting the published contract on the most important internal-error path. It now goes through CrashReport.Child (null capture — the core's own polite line is already on stderr), and the gate-A crash smoke asserts the report is mentioned. The fifth finding (AGENTS.md: audit development lives in OwnAudit) is a placement decision answered on the thread: the decoupling half of the rule is honored (no ownlang coupling, public CLI/JSON only), the witness core originates from PR #280 which placed it in this repo's audit/, and the extraction here followed an explicit owner-side direction; whether to relocate to OwnAudit stays an owner decision, not a drive-by move. Verified locally: builds clean, selftest 11/11, flagship-demo bad 'leak DEMONSTRATED' / ok 'fix VERIFIED (OBSERVED_ONLY)'. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015de4MezSeUnZBoWq1fFU5M
1 parent 3774e5f commit 2f064dd

4 files changed

Lines changed: 36 additions & 10 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2414,6 +2414,7 @@ jobs:
24142414
[ "$rc" -eq 5 ] || { echo "FAIL: expected exit 5 for a core crash, got $rc"; exit 1; }
24152415
echo "$out" | grep -q "ownlang: internal error" || { echo "FAIL: expected the core's polite one-liner"; exit 1; }
24162416
echo "$out" | grep -q "This is a bug in owen" || { echo "FAIL: expected owen's polite framing"; exit 1; }
2417+
echo "$out" | grep -q "Diagnostic report" || { echo "FAIL: the core-crash path must write the diagnostic report (Codex P2)"; exit 1; }
24172418
echo "$out" | grep -q "Traceback (most recent call last)" && { echo "FAIL: raw traceback leaked without --debug"; exit 1; }
24182419
echo "$out" | grep -qE "^0 findings\.$" && { echo "FAIL: a core crash must never read as a clean scan"; exit 1; }
24192420
true

‎audit/runtime/RetentionPath/Heap.cs‎

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,20 @@ public RetentionReport FindRetainers(string typeName, int sample, int maxHops)
120120
// `GTDGoody` — a cached lambda whose *generic argument* happens to mention it — and then
121121
// confidently reports a path to the wrong object. A tool that points at the wrong culprit
122122
// is worse than no tool.
123+
// ALL matching instances are targeted (Codex P1: taking the first
124+
// `sample` in heap-enumeration order could catch only old garbage
125+
// and miss a later durably-held instance — a false OBSERVED_ONLY).
126+
// The verdict is exact over the whole population; only PATH
127+
// RESOLUTION below is sampled (`sample` paths), keeping the
128+
// expensive part bounded.
123129
var targets = new Dictionary<ulong, string>();
124130
long totalOfType = 0;
125131
foreach (var o in Heap.EnumerateObjects())
126132
{
127133
if (!o.IsValid || o.Type?.Name == null) continue;
128134
if (!IsType(o.Type.Name, typeName)) continue;
129135
totalOfType++;
130-
if (targets.Count < sample) targets[o.Address] = o.Type.Name;
136+
targets[o.Address] = o.Type.Name;
131137
}
132138
if (targets.Count == 0)
133139
return new RetentionReport(typeName, 0, 0, new List<Retainer>());
@@ -209,13 +215,22 @@ void Bfs()
209215
// ---- 3. unwind each sampled target, and group the paths by shape --------------
210216
var groups = new Dictionary<string, Retainer>();
211217
long retainedSampled = 0;
218+
long pathsResolved = 0;
212219
foreach (var kv in targets)
213220
{
214221
if (!parent.ContainsKey(kv.Key)) continue; // not reachable — genuinely garbage
215222
retainedSampled++;
223+
if (pathsResolved >= sample) continue; // verdict stays exact; paths stay bounded
224+
pathsResolved++;
216225

217226
var hops = Unwind(kv.Key, parent, rootKind, maxHops, out ClrRootKind kind);
218-
string signature = string.Join(" -> ", hops.Select(h => h.Type));
227+
// The signature must carry the CLASSIFICATION and the fields,
228+
// not only hop type names (Codex P1): a stack-rooted and a
229+
// durably-rooted instance can share a type sequence, and
230+
// merging them would classify the whole group by whichever
231+
// came first — hiding a durable retainer or inventing one.
232+
string signature = Retainer.Classify(kind, hops) + " | "
233+
+ string.Join(" -> ", hops.Select(h => h.ToString()));
219234

220235
if (!groups.TryGetValue(signature, out var retainer))
221236
{
@@ -241,12 +256,23 @@ private List<Hop> Unwind(ulong target, Dictionary<ulong, ulong> parent,
241256
{
242257
var chain = new List<ulong>();
243258
ulong cur = target;
259+
bool truncated = false;
244260
while (true)
245261
{
246262
chain.Add(cur);
247263
if (!parent.TryGetValue(cur, out ulong p) || p == 0) break;
248264
cur = p;
249-
if (chain.Count > maxHops) break;
265+
if (chain.Count > maxHops) { truncated = true; break; }
266+
}
267+
if (truncated)
268+
{
269+
// Keep walking the (acyclic) parent chain WITHOUT recording
270+
// hops: the rendered path stays bounded, but the verdict must
271+
// see the true root — stopping mid-chain yielded
272+
// ClrRootKind.None -> 'unsupported-root:None', which the
273+
// verdict counts as durable, turning a long stack-only path
274+
// into a false RETAINED (Codex P1).
275+
while (parent.TryGetValue(cur, out ulong p2) && p2 != 0) cur = p2;
250276
}
251277
kind = rootKind.TryGetValue(cur, out var k) ? k : ClrRootKind.None;
252278
chain.Reverse();

‎frontend/roslyn/OwnSharp.Cli/CheckCommand.cs‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,12 @@ await RunExtractorAsync(paths, factsPath, legacy, stats, bodyThrowEdges)
139139
// --fail-on-finding, was silently mapped to a CLEAN scan.
140140
if (rc == 70)
141141
{
142+
// The most important internal-error path must honor the whole
143+
// contract, including the diagnostic report (Codex P2) — the
144+
// core's polite one-liner is already on stderr above.
142145
Console.Error.WriteLine(
143-
"owen: the analysis core failed internally — the line above has the " +
144-
"short cause. This is a bug in owen, not in your code.");
145-
Console.Error.WriteLine(
146-
" Re-run with --debug (or OWEN_DEBUG=1) for the full traceback, and " +
147-
"please report it: https://github.com/PhysShell/Own.NET/issues/new/choose");
148-
return CrashReport.ExitCode;
146+
"owen: the analysis core failed internally — the line above has the short cause.");
147+
return CrashReport.Child("analysis core", rc, args, capturedOutput: null);
149148
}
150149

151150
if (failOnFinding)

‎frontend/roslyn/OwnSharp.Cli/CrashReport.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public static int Handle(Exception ex, string[] args)
5454
/// <summary>Frame a child stage's crash (unexpected exit code) without
5555
/// dumping its raw output on the user; the full capture goes into the
5656
/// report instead. In debug mode the caller prints the raw output.</summary>
57-
public static int Child(string stage, int rc, string[] args, string capturedOutput)
57+
public static int Child(string stage, int rc, string[] args, string? capturedOutput)
5858
{
5959
var report = TryWrite(args, stage,
6060
cause: $"{stage} exited with unexpected code {rc}",

0 commit comments

Comments
 (0)