Skip to content

feat: derive classification signals from docs for external analyzers - #291

Merged
jflowers merged 2 commits into
unbound-force:mainfrom
jflowers:opsx/docscan-signal-classification
Oct 1, 2026
Merged

jflowers merged 2 commits into
unbound-force:mainfrom
jflowers:opsx/docscan-signal-classification

Conversation

@jflowers

@jflowers jflowers commented Sep 29, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

External-analyzer projects (e.g., Python via snake-eyes) report a large
share of detected side effects as ambiguous (56.7% for snake-eyes)
despite their spec/design docs already documenting which effects are
contractual vs. incidental. gaze docscan already discovers those docs,
but that output never reaches classification.

This change adds a doc → signal derivation step so documented contracts
and documented internal bookkeeping drive classification:

  • A deterministic Markdown annotation grammar
    (<!-- gaze:contractual TypeName --> and > [!gaze-contract] fenced
    blocks) to declare effects contractual/incidental, keyed by the
    analyzer's effect-type name.
  • A machine-readable sidecar (.uf/gaze/contracts.yaml/.json) for
    explicit (package, function, side_effect_type) → label overrides.
  • A new internal/adapter/docsignal/ package producing
    []docsignal.DerivedSignal (a keyed carrier; taxonomy.Signal
    unchanged), fanning type-level annotations out to per-function tuples
    via the effect list.
  • Wiring into adapter.mergeClassifications so doc signals flow through
    classify.ComputeScore with no protocol changes.

Strictly scoped to external analyzers; the Go-native godoc path is
unchanged.

closes #285

How to Test

go build ./...
go test -race -count=1 -short ./...
go test -race -count=1 -short ./internal/adapter/docsignal/
go test -race -count=1 -run TestExternalSideEffectAnalyzer_DocSignalClassification ./internal/adapter/
golangci-lint run ./internal/adapter/... ./internal/protocol/...

How to Demo

In an external-analyzer project, add
<!-- gaze:contractual ContainerMutation --> to a .md doc (or a
.uf/gaze/contracts.yaml entry), then run gaze quality --analyzer <name>.
Effects documented as contractual/incidental resolve from ambiguous
instead of remaining ambiguous.

Key Files Changed

  • internal/adapter/docsignal/ (new) — grammar, parser, sidecar loader,
    derivation, plus 19 unit tests and a 12-scenario coverage ratchet.
  • internal/adapter/classify.go / sideeffect.go — merge doc signals into
    classification; unconditional derivation.
  • internal/protocol/testdata/fake_analyzer/main.go — --no-classify-signals
    and --unclassified-effect flags for independent doc-signal testing.
  • docs/ — new guides/doc-annotations.md plus updates to
    concepts/classification, reference/configuration, guides/improving-scores,
    and index.

This PR was generated by /uf.finale (AI-assisted).

@fullsend-ai-review

fullsend-ai-review Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

🤖 Finished Review · ✅ Success · Started 3:16 PM UTC · Completed 3:35 PM UTC

Commit: 01b454d · View workflow run →

Runtime: claude · Model: opus → claude-opus-4-6 · Effort: high · Cost: $14.27

@fullsend-ai-review fullsend-ai-review Bot added the risk/elevated PR risk: elevated label Sep 29, 2026
@fullsend-ai-review

Copy link
Copy Markdown

Risk Assessment: elevated (3/5)

Details

Elevated risk driven primarily by large change size (2762 lines across 28 files) and moderate test ratio (0.21). Risk is mitigated by well-scoped issue with clear design rationale, strong spec artifacts, explicit scope boundary keeping Go-native path untouched, and self-contained new package with comprehensive test suite.

@fullsend-ai-review

Copy link
Copy Markdown

Review

Findings

Medium

Low

  • [error-handling] internal/adapter/docsignal/derive.go:40 — DeriveSignals silently discards the error from LoadSidecar via a blank identifier (sidecarSignals, _ := LoadSidecar(moduleRoot, stderr)). While this is an intentional design decision per D5 (graceful degradation) and LoadSidecar already writes warnings to stderr, an inline comment explaining the intentional discard would improve readability for future maintainers.

  • [stale-doc] docs/protocol.md — The classify_signals degradation description states that when the method errors or is absent, Gaze uses pre-classified effects from analyze. With this PR, doc-derived signals from Markdown annotations and the sidecar file also contribute during degradation. The protocol-level statement is technically correct (protocol behavior is unchanged), and the new behavior is documented in docs/concepts/classification.md and docs/guides/doc-annotations.md, but a cross-reference from the protocol doc would be helpful.

  • [incomplete-doc] docs/porting/taxonomy-reference.md — The Signal Weights table lists only Go-native signal sources. The three doc-derived source tokens introduced by this PR (architecture_doc ±25, readme ±15, sidecar ±30) are already documented in docs/concepts/classification.md and docs/guides/doc-annotations.md, but adding them to the taxonomy reference table as external-analyzer-only entries would provide a complete cross-reference for porter implementors.

@fullsend-ai-review fullsend-ai-review Bot added the requires-manual-review Review requires human judgment label Sep 29, 2026
@jflowers
jflowers force-pushed the opsx/docscan-signal-classification branch from 01b454d to 9d8af6e Compare September 29, 2026 17:19
jflowers added a commit to jflowers/gaze that referenced this pull request Sep 29, 2026
Addresses PR unbound-force#291 review feedback from @fullsend-ai-review[bot].

Signed-off-by: Jay Flowers <[email protected]>
Assisted-by: deepseek-v4-pro
@jflowers

Copy link
Copy Markdown
Collaborator Author

Thanks for the review. Resolution of the four findings:

Medium [protected-path] AGENTS.md — Rejected. The change adds one "Recent Changes" entry documenting the new internal/adapter/docsignal/ package, consistent with the existing convention. No governance gate, threshold, or MUST rule was modified.

Low [error-handling] derive.go blank identifier — Rejected. The intentional discard is already explained inline at internal/adapter/docsignal/derive.go: "Load the sidecar file (warnings go to stderr; errors degrade gracefully to grammar-only signals)." This is deliberate per design D5 (graceful degradation).

Low [stale-doc] docs/protocol.md — Addressed in 2b62525: the classify_signals degradation bullet now notes doc-derived signals supplement pre-classified analyze effects, with a cross-reference to the classification concepts doc.

Low [incomplete-doc] docs/porting/taxonomy-reference.md — Addressed in 2b62525: the Signal Weights table now lists architecture_doc ±25, readme ±15, and sidecar ±30, marked external-analyzer-only.

@jflowers jflowers self-assigned this Oct 1, 2026
jflowers added a commit to jflowers/gaze that referenced this pull request Oct 1, 2026
Addresses PR unbound-force#291 review feedback from @fullsend-ai-review[bot].

Signed-off-by: Jay Flowers <[email protected]>
Assisted-by: deepseek-v4-pro
@jflowers
jflowers force-pushed the opsx/docscan-signal-classification branch from 2b62525 to c5b5eac Compare October 1, 2026 19:24
- Add internal/adapter/docsignal package: annotation grammar,
  sidecar overrides, and doc-signal derivation
- Wire doc signals into adapter.mergeClassifications
- Add --no-classify-signals and --unclassified-effect flags to the
  fake analyzer for independent doc-signal path testing
- Document the grammar, sidecar, and weights in docs/

Closes unbound-force#285

Assisted-by: deepseek-v4-pro
Generated with AI assistance (deepseek-v4-pro)
Addresses PR unbound-force#291 review feedback from @fullsend-ai-review[bot].

Signed-off-by: Jay Flowers <[email protected]>
Assisted-by: deepseek-v4-pro
@jflowers
jflowers force-pushed the opsx/docscan-signal-classification branch from c5b5eac to deb2c5b Compare October 1, 2026 21:48

@jflowers jflowers left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: Could not post as APPROVE due to insufficient permissions (self-review prohibition). Posted as COMMENT instead. Original verdict: APPROVE.

LGTM. Clean, well-scoped implementation of doc → classification signal derivation for external analyzers.

Verified locally:

  • go build ./... — PASS
  • go test -race -count=1 -short ./... — PASS (20/20 packages)
  • golangci-lint run ./internal/adapter/... ./internal/protocol/... — PASS (0 issues)

Notes:

  • Strictly scoped to external analyzers; Go-native godoc path unchanged.
  • 12-scenario ratchet test plus E2E doc-signal-only integration test.
  • Sidecar (YAML/JSON) parsing uses standard unmarshalers with semantic validation and graceful degradation.
  • No security or alignment findings.

This review was generated by /uf.review-pr (AI-assisted).

@jflowers
jflowers merged commit 471c677 into unbound-force:main Oct 1, 2026
5 checks passed
@jflowers
jflowers deleted the opsx/docscan-signal-classification branch November 15, 2026 21:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

requires-manual-review Review requires human judgment risk/elevated PR risk: elevated

Projects

None yet

Development

Successfully merging this pull request may close these issues.

derive doc/design-doc signals from docscan output to resolve ambiguous classification (external analyzers)

1 participant