Ask Agda rather than re-derive: the audit¶
File: agda-native-air/docs/agda-mcp/agda-mcp-ask-agda-audit.md
Purpose: the audit record for issue #106 — every answer agda-mcp computes from source text, with a verdict on each, and the two measurements the issue asked for: what --interaction-json actually carries for the § 5 error corpus (Measurement 1), and what --trace-imports=0 does to the checkedFromSource signal (Measurement 2). Every probe below was run on 2026-08-20 against the pinned Agda 2.8.0 inside nix develop .#backend, and every quoted transcript was captured live from a real process; scratch directory prefixes are abbreviated to … in the quotes. This is a standalone document rather than a section of docs/agda-mcp/agda-mcp-interaction-lane.md because that file is #75's design record while this audit is a cross-tool inventory with its own acceptance list; the two cite each other.
1. The rule¶
answer = whatAgdaSaid <|> whatWeDerived: when Agda can answer a question, ask Agda; a local derivation from source text is a pre-flight approximation and a fallback, never the authority, and a change in Agda's output degrades a field to the derived value and never to a wrong value. That is issue #72's rule for Agda's prose ("the diagnostics text never gets a vote") applied to informational fields, with #100 as the worked example: get_goal scanned the file for its module field and reported a literate file under a name found in its prose, while Agda had already printed the true answer in output the same call had captured. The normative, author-facing statement of the rule — the one a new tool's author is expected to read before writing a scanner — lives in agda-mcp/README.md under Architecture Notes ("Ask Agda rather than re-derive"); this document is the audit that applied it to the existing surface.
2. The inventory¶
Every derived answer in the server, its verdict, and the issue that delegated it or would. The issue predates #75 and #108 landing, so several rows are resolved by delivery; for those the audit's job is to record the resolution accurately, not to propose it.
| derived answer | where | verdict | issue |
|---|---|---|---|
| hole positions and spans | AgdaMCP.Holes |
delegated for goal-scoped queries; parity-subordinated in the batch listings | #75 (PR 107), #108 (PR 110) |
| goal type and context | macro injection (ensureDebugImport + reportGoalCtx) |
delegated | #108 (PR 110) |
| module name | moduleNameOf scan |
delegated | #100 (PR 105), #108 (PR 110) |
| structured diagnostics | AgdaMCP.Diagnostics (#74) |
stays, measured | Measurement 1 below; enrichment filed as #115 |
| project libraries and include paths | AgdaMCP.Project |
stays, no interface exists | — |
checkedFromSource |
AgdaMCP.Agda.checkedFromSourceOf (#77) |
derived; the muted-channel hole now detected | Measurement 2 below; #114 (PR 117) |
| the acceptance gate command | AgdaMCP.Gate |
out of scope | #78 |
- The hole model — delegated where a lane answers at runtime, parity-subordinated everywhere else; both halves recorded.
AgdaMCP.Holesports Agda 2.8.0's literate preprocessor and a model of its lexer to answer "where are the holes?". What #75 (PR 107) and #108 (PR 110) delegated at runtime is the goal-scoped surface:get_goal's lane path asksCmd_goal_type_contextat the lane's interaction point, and a warm lane's stored goals fill the batch listings' goal strings. The batch listings' hole positions, spans, counts, and handles are still computed fromfindHoleson every call (handleCheckFileandhandleGetDiagnosticsbuild them from the scan unconditionally, warm lane or not), and evenget_goal's lane path addresses the hole lexically first, then validates the lane's point against the scan's span coordinates and declines to the fallback on any mismatch. For those answers the design doc's § 1 demotion is subordination rather than substitution: the scan remains the runtime source — a pre-Agda source edit structurally needs a source view, sincefill_holeand the injection path rewrite bytes, and the scan is also the code-only view and the fallback for files Agda refuses to load — while Agda remains the authority it is held to, tier 2d pinning the scan to batch Agda and the tier-3 lane tests pinning it to the lane'sInteractionPointsacross the fixture matrix. A batch listing's positions are derived values whose warrant is the parity suite rather than a per-call Agda answer, and the audit records that as the accurate residue: delegation by substitution where a lane query runs, delegation by subordination where the scan still computes. - The reporting-macro injection — delegated, fallback recorded. Since #108 (PR 110),
get_goalasks the lane'sCmd_goal_type_contextfirst: Agda's own goal display arrives as data, with no file mutation, and the response sayssource: "interaction-lane". The inject-patch-restore dance survives only as the stated fallback (source: "injected-macro") for a lane that crashed, could not start, a file that does not load there, or a shutting-down registry — and as the one path that reports binder visibility, which Agda's goal display does not carry. - The module name — delegated twice over. #100 (PR 105) re-sourced the batch path to
agdaModuleNameOf, reading the name Agda resolved from its ownChecking M (path).line; #108 (PR 110) strengthened the lane path withliModule, the name stored at load time so even a warm reuse knows it. The code is literally the rule:giModule = liModule li <|> moduleNameOf (flavourOf absPath) src. The scan persists in exactly two places, both correct: before the injection edit, where no Agda has spoken yet, and as the<|>fallback that keeps a successful answer complete when Agda named no module. - Structured diagnostics — stays; the conjecture measured false in the strong form. Issue #106 conjectured that
--interaction-json"emits structured information for the same errors" and asked how much of #74's parser it would retire. Measurement 1 (§ 3) answers: the protocol's error payloads carry the same prose batch prints, wrapped in a JSON envelope; the envelope retires the parser's segmentation layer (block splitting, banner dedup, severity classification) and none of its content extraction (codes, line/col ranges, theinvolvedpayloads). The one class where the protocol carries more than the prose — unsolved metas, whose names and types arrive as data — is filed as enrichment #115 rather than migration, because on that class the lane does not fail at all, and tolerance is exactly what the two-lane policy bars from verdict-adjacent surfaces. - Project resolution — stays, and it is not an oversight.
AgdaMCP.Projectfinds the nearest*.agda-lib, parses the libraries registry, and computes include paths. No Agda query answers "what libraries and include paths apply to this file":agda --helpoffers none, and the interaction protocol is a consumer of the answer rather than a source — § 2.4 of the lane doc probed thatCmd_loadwith an empty argv does not even inherit a useful context, so the lane needs the resolved flags handed to it on every load. Until Agda grows such a query, this derivation is the server's to own; it is kept honest by the response echo (#76), which shows the client the exact resolution every call used. checkedFromSource— derived honestly on three of four branches, and the fourth is now detected. The signal reads Agda's progress lines, which is asking Agda — but its warm branch is an inference from silence, and--trace-imports=0manufactures silence. Measurement 2 (§ 4) reproduces the misreading end to end, closes every alternative arrival path for the flag, and records the decision: detectable wins over acceptable-and-documented, filed as #114 and delivered by PR 117. The delivered shape is the degradation this section recommended: both lanes read the effective trace level out of the argv they assembled (AgdaMCP.Agda.progressChannelMuted) and withhold every answer that would have rested on a silence the server caused — the boolean in each lane, andcheck_project'smodulesChecked, which counts the same lines. The restore variant stays declined for the reason recorded below.- The project gate — out of scope.
AgdaMCP.Gatedecides which command is a project's acceptance gate by readingMakefiles and scripts. That is not Agda's question; no delegation could exist. Listed so the inventory is complete.
3. Measurement 1: the error corpus over --interaction-json¶
Method: each fixture of the § 5 error corpus (docs/feedback/flrp-agda-mcp-improvements.md, fixtures under agda-mcp/test/resources/diagnostics/) was copied to a scratch directory and driven three ways: batch agda (prose + exit code), the real server's get_diagnostics over the MCP transport (what #74 extracts today), and a fresh agda --interaction-json child per fixture speaking the wire protocol of the lane doc's § 2 — flush the startup noise with a sentinel, Cmd_load with the resolved argv, sentinel again. One fixture was added beyond § 5: WarnOnly.agda (an EmptyPrivate warning and nothing else), because warning-only runs are the case that motivated the parser's dedup heuristic.
The per-class result:
| error class | the protocol adds beyond batch prose | still prose-only in the protocol |
|---|---|---|
UnequalTerms |
the message isolated in one JSON field; JumpToError start offset; an atoms:["error"] span with start and end character offsets |
code, line/col range, expected/actual |
NotInScope |
same envelope | code, range, the did-you-mean candidates |
AmbiguousName |
same envelope | code, range, the qualified candidates and their provenance |
ClashingDefinition |
same envelope | code, range, the previous definition's origin |
ModuleDoesntExport + NotInScope |
the severity split is structural: the warning rides a warnings array beside the error object |
each warning's code, range, and missing names, inside its message string |
UnsolvedConstraints + UnsolvedMetaVariables |
the load does not fail: metas arrive as structured invisibleGoals (name, type, line/col range each), the constraint error as prose in AllGoalsWarnings.errors |
the constraint text; and the [UnsolvedMetaVariables] diagnostic is never emitted at all |
EmptyPrivate (warning-only) |
the warning appears once, structurally — no "All done" banner duplication — and Status.checked is true |
the warning's content |
The representative transcripts, trimmed to the load-bearing lines. A failed load (here UnequalTerms.agda) answers with the batch prose inside JSON, a start offset, and an error span whose note duplicates the same prose:
{"info":{"error":{"message":"…/diag-corpus/UnequalTerms.agda:17.5-9: error: [UnequalTerms]\nBool !=< Nat\nwhen checking that the expression true has type Nat"},"kind":"Error","warnings":[]},"kind":"DisplayInfo"}
{"filepath":"…/diag-corpus/UnequalTerms.agda","kind":"JumpToError","position":584}
{"direct":true,"info":{"payload":[{"atoms":["error"],"definitionSite":null,"note":"…same message…","range":[584,588],"tokenBased":"NotOnlyTokenBased"}],"remove":false},"kind":"HighlightingInfo"}
The scope-warning pair separates severities structurally but each payload stays prose:
{"info":{"error":{"message":"…/ModuleDoesntExport.agda:23.5-15: error: [NotInScope]\nNot in scope:\n absentName\n …"},"kind":"Error","warnings":[{"message":"…/ModuleDoesntExport.agda:20.24-50: warning: -W[no]ModuleDoesntExport\nThe module DiagBarrel doesn't export the following:\n absentName\n…"}]},"kind":"DisplayInfo"}
The unsolved-meta fixture, which batch fails with two diagnostics (exit 42), does not fail on the lane at all — Status.checked stays false, but the load ends in AllGoalsWarnings plus InteractionPoints, and the § 5 ask ("each meta with its type") that the prose cannot carry arrives as data:
{"info":{"errors":[{"message":"error: [UnsolvedConstraints]\nFailed to solve the following constraints:\n _n_4 + _m_5 = 3 : Nat (blocked on _n_4)"}],"invisibleGoals":[{"constraintObj":{"name":"_n_4","range":[{"end":{"col":16,"line":28,"pos":1153},"start":{"col":9,"line":28,"pos":1146}}]},"kind":"OfType","type":"Nat"},{"constraintObj":{"name":"_m_5","range":[…]},"kind":"OfType","type":"Nat"}],"kind":"AllGoalsWarnings","visibleGoals":[],"warnings":[]},"kind":"DisplayInfo"}
{"interactionPoints":[],"kind":"InteractionPoints"}
And the warning-only fixture, which batch prints twice (once raised, once under the "All done; warnings encountered" banner), arrives once, with Status.checked: true:
{"info":{"errors":[],"invisibleGoals":[],"kind":"AllGoalsWarnings","visibleGoals":[],"warnings":[{"message":"…/WarnOnly.agda:2.1-8: warning: -W[no]EmptyPrivate\nEmpty private block."}]},"kind":"DisplayInfo"}
The verdict, per the issue's question "how much of #74's parser would the JSON protocol retire":
- Retired in principle: the segmentation layer. One message per JSON object retires block splitting; the absence of the banner duplication retires the dedup heuristic; the
error/warnings/AllGoalsWarnings.errorsenvelope retires severity classification;JumpToErrorand the error atom add a character-offset position the prose states in line/col form. - Not retired: all four of the content defects the module header of
AgdaMCP.Diagnosticsrecords fixing. The code ([Code]and-W[no]Code), theLINE.COL-COLranges, the position-less headers (error: [UnsolvedConstraints]opens at column 0 on the wire too), and theinvolvedpayloads (expected/actual, candidates, origins, metas) are all insidemessagestrings byte-identical to batch prose. A lane-sourced diagnostics tool would run the same parser on the same prose, fished out of JSON fields; the parser is transport-independent content extraction, and nothing about the transport retires it. - Changed semantics, which is the real boundary: on the unsolved-meta class the lane does not fail, so lane-sourced "diagnostics" would disagree with the batch verdict on exactly the tolerance cases issue #69 was about — which is the two-lane policy's § 1 argument, met again from the other side.
get_diagnosticsis a verdict-adjacent tool (it reportssuccessfrom the batch exit code); it cannot re-source its evidence to a lane that refuses to fail. - Exceeded, once: the metas' names and types are data the prose never carries, one peek away in a warm lane's
AllGoalsWarnings— filed as #115, mirroring #108's peek shape (enrichment, never a verdict input, cold lane changes nothing). - Two smaller observations, recorded but deliberately not filed: the character offsets (
position,range:[584,588]) would need the file's text to become line/col, so "using the protocol's positions" would reintroduce a source-text derivation the prose already answers in line/col; and the lane's failed-load prose (errorMessageOf) could be fed throughparseDiagnosticsto give live-query failures structured payloads, a composition that works precisely because the parser is transport-independent — worth an issue the day a live-query client asks for it, not before.
So the conjecture's strong form is false for five of six classes, true in a useful sense for one, and the practical consequence is the opposite of a migration: #74's parser stays, unshared work stays zero (the parser already serves any prose, whichever pipe carried it), and the one structural surplus becomes #115.
4. Measurement 2: checkedFromSource under --trace-imports=0¶
checkedFromSourceOf reads a completed run with no Checking line as interface reuse, because a warm agda exits 0 printing nothing. The issue reported that --trace-imports=0 silences the line outright, making a clean cold check read as warm. Reproduced, extended to the lane, and every escape hatch probed:
- Level semantics, cold (a two-module scratch project, caches scrubbed before each run): no flag and
--trace-imports=1print theCheckinglines (1 is the default level);--trace-imports=0prints nothing — the hole;--trace-imports=2and the bare--trace-importsaddFinishedlines;--trace-imports=3addsLoadingfor every interface read. Warm: every level below 3 is silent; level 3 printsLoadinglines, the only positive warm evidence the flag family offers. - The misreading, through the real server: a cold
check_fileon a clean module answerscheckedFromSource: truewith default flags andcheckedFromSource: falsewith--trace-imports=0appended — the same source re-check, reported as warm. The failing branch stays honest: a broken module under the flag answerssuccess: falsewith the field absent (exit non-zero, no evidence either way), and the module name degrades to the declared-name fallback by the<|>rule. - The lane has the same hole: a cold
Cmd_loadwhose per-load argv carries--trace-imports=0emits noRunningInfoat all — probed, the load went straight toAllGoalsWarnings— solrCheckedFromSource(which feedsget_goal's lane-pathcheckedFromSource) reads a genuine re-check asfalse, and the storedliModulestays empty (that one is covered by the fallback; the boolean is covered by nothing). - Every other arrival path is closed:
{-# OPTIONS --trace-imports=0 #-}is rejected with[OptionError] Unrecognized option, and an.agda-libflags:field carrying it is rejected identically — so the flag exists only on the command line the server itself assembles from its--agda-flags,projectExtraFlags, andfileDirIncludeFlags, in both lanes. The grammar is closed too:=Nis the only level-carrying spelling, bare--trace-importsmeans 2, a space-separated level does not parse (the0becomes a second input file, exit 71), and the last occurrence wins (--trace-imports=0 --trace-imports=1printsChecking; the reverse prints nothing).
The recorded decision: detectable, filed as #114. The reasoning: the misreading sits on the field's most common branch (a clean check), and the field exists to explain latency, so a wrong "warm" defeats its purpose in a way an absent field does not — the #106 degradation ordering is absent over wrong. Detection is complete because the arrival path is single and the grammar closed (both probed above), and it is cheap because the server already owns the argv it would scan. The last-wins ordering even offers a repair — append --trace-imports=1 when and only when the effective level is 0 — though that variant needs a version gate for foreign --agda-bin toolchains; both options and all the probe evidence are on #114, so nothing is re-derived there. This section was the documentation of record for the behavior until #114 landed (PR 117), which is also when the checkedFromSourceOf doc-comment gained its caveat — deferred to the fix rather than taken as a drive-by edit here, alongside the agdaModuleNameOf comment that already carried the flag's effect on the module name.
5. The issue's third acceptance item, overtaken by events¶
The acceptance list asked for #75's description to be updated to say it retires the hole scanner and the macro injection, not just that it adds live queries. That item is overtaken: #75 closed with PR 107, #108 (PR 110) subsequently moved get_goal itself onto the lane, and the design record both issues share already carries the claims in their accurate final form — § 1's lexical-layer bullet states the scanner is "demoted, not deleted … never again the authority for anything Agda can answer; the parity tests keep it honest against the lane's InteractionPoints", and § 4's AgdaMCP.Tools.ProofState entry states "the injection path remains as the fallback (source: "injected-macro") … and it is the one path that reports binder visibility". Both sections were re-read against merged main during this audit and carry the claims verbatim; "retire" would in fact overstate them, since the scanner splices and the injection reports visibility on purpose. This resolution is recorded here and on issue #106 rather than by reopening a closed issue's text.