Documentation

Docs / Reference

ADR 0068 - Go structural claim contract: files, declarations, imports

Status: Accepted (delegated review, 2026-11-16)

Context

T020 (ADR 0066) labels a language's structural scope (files, top-level declarations, imports) precise only through a rule-table row whose evidence includes a claim contract with a 1:1 test, goldens, corpus checks, an oracle where cheap and an independent review. The T020 investigation (the T020 task record (internal)) inventoried every Go form the extractor (internal/lang/golang) emits and compared it with an oracle built on the Go standard library (scripts/oracle/go_structure/main.go).

Declarations agreed on every compared fact (9330 of 9330 on gotify, realworld-gin and the self-index). Imports did not: 4927 of 13136 in-module imports file edges were wrong (gotify 169, realworld-gin 5, self 4753). Link used PackageFiles for import edges, which gives a test importer every _test.go file of the imported directory (class I-1: test files of another directory's package; I-2: an external test package's sibling x_test files and itself) and ignores build constraints, _/. file names and package clauses (I-3). The probe also showed edges into a nested module (I-4), duplicate identities for func _ and redeclarations (D-1, D-3), receivers dropped silently (D-2) and declarations recovered by tree-sitter in files go/parser rejects (D-4). Precision stops PS-S1-1 to PS-S1-6 hold the PL-L1 flip until each is fixed and the oracle reports 0.

Options considered

  1. Narrow the scope: take imports out of the Go scope (O-S1-2 (b)). Keeps the code; loses the most useful structural fact.
  2. Fix the edges in Link with the go command's package rules, using the build constraints captured at extraction time (O-S1-3 (a): in facts.GoFacts) or passing sources to golang.Link (O-S1-3 (b): an index call change).
  3. Use go list at index time. Needs the module cache or the network for third-party imports, runs the go toolchain on user code's metadata and ties the result to the installed toolchain. Rejected (as in the investigation).

For files go/parser rejects (O-S1-1): (a) claim no declaration or import; (b) keep the facts and drop the file label to best_effort (needs the file label decided after parsing: precision.FileLabel, the scanner, the indexer and the server's stored-label check change); (c) keep only declarations without an error node (no oracle can check recovered trees).

Decision

Option 2 with O-S1-3 (a), and every decision of the task file's "Decisions (2026-11-16, before S1B)" (O-S1-1 fallback (a), O-S1-2 (a), O-S1-4 (a), O-S1-6 (a), O-S1-7 (a), O-S1-8 (a)). The contract is docs/lang/go-structure.md, rows GS-M1, GS-F1, GS-F2, GS-D1..GS-D8, GS-I1..GS-I5 and the default branch D, mirrored by structureRows (internal/lang/golang/structure.go).

No rule-table row is added and no label changes here: PL-L1 follows the independent review (added, below).

Review fixes (S1R)

The independent review (the T020 task record (internal)) found four classes of confident wrong facts the oracle could not see because it shared the code's assumptions (A1..A4), packages the go command rejects that still got edges (B2), wrong call edges from the package-name binding (B3), no code_calls label (B4) and an oracle that was not independent (B1). Each is fixed as a class rule, still at extractors-39 (unreleased):

Consequences

Known gaps

Review notes

Corpus and oracle results (the Go implementation, 2026-11-16, extractors-39):

Review fixes (still extractors-39):

Review notes (S1R, pending acceptance)

Independent review (the T020 task record (internal), on 893af975). Verdict, verbatim: "The PL-L1 flip is blocked. Four class A findings: in each, Graphvein states a structural fact with provenance fact, confidence 1, that the Go toolchain contradicts, and TestGoStructureOracle cannot see it because the oracle shares the blind spot. None of them occurs in gotify, realworld-gin or the self-index (checked by grep), so the corpus numbers stay valid; all four are reachable in ordinary repositories and each has a small class-level fix."

Fixes (4f04be01), verbatim from the task file's "S1 review fixes": "Every class A and B finding is fixed as a class rule, still at extractors-39; PL-L1 is not added and no label changes." Per finding: A1 lone CR (row GS-F3), A2 malformed import paths (CheckImportPath), A3 package documentation, A4 cgo, B1 an oracle on go/build ImportDir over raw bytes plus the go list differential, B2 go/build package errors refused, B3 one package reader for imports, calls and GORM, B4 the code_calls label (O-S1-5 (a)); each with a fixture case, and mutation checks in which the oracle or go list caught every reverted fix. No class A finding is open. The class C items and the two open points of the fixes (import cycles, internal/ visibility) are known gaps above, kept by decision.

Flip (extractors-39): row PL-L1 of docs/extract/precision.md labels Go files precise (test files included); calls stay row D (code_calls). A Go file whose structure claims nothing (go/parser rejects it, a lone CR, not parsed, not extracted or dropped by validation) is stored best_effort, served with reason structure_refused. This section stays pending until the developer accepts the review record; Status stays Proposed.

Review notes (acceptance, 2026-11-16)

Accepted after delegated review on 2026-11-16 (T020 structure contract, Go).

Report a problem with this pageSource: docs/adr/0068-go-structure-contract.md