Skip to content

feat: explicit supersession in compile instead of newest-wins - #201

Merged
jflowers merged 14 commits into
unbound-force:mainfrom
jflowers:opsx/explicit-supersession-in-compile
Nov 12, 2026
Merged

jflowers merged 14 commits into
unbound-force:mainfrom
jflowers:opsx/explicit-supersession-in-compile

Conversation

@jflowers

Copy link
Copy Markdown
Contributor

Summary

Closes #150 (part of #153; builds on merged #146 temporal-validity fields and #145 server-side synthesis).

compile no longer resolves contradictions by recency. A learning is treated as replaced only when a declared supersedes/superseded_by link says so; undeclared contradictions surface in an ## Open Conflicts section with both positions cited, never silently resolved.

  • The synthesis prompt no longer tells the model to "favor the newest learning"; compile reads temporal metadata (validity, supersedes, superseded_by) per learning, normalized and shape-validated at the decode boundary so hostile property values are withheld rather than rendered.
  • Every factual claim in a compiled article must cite its learning identity (bracketed citations); a new pure helper (tools/citations.go) computes forward/backward citation coverage — every claim cites a real source, every source learning is accounted for, superseded sources excepted.
  • Synthesis may propose supersessions in a strict ## Supersession Proposals section; compile parses, validates, strips it, and returns proposed_supersessions plus dropped_proposals with graded drop reasons. Recency alone is never grounds.
  • New supersede_learning MCP tool (52nd tool, union count) links two existing learnings through the guarded write paths feat: temporal-validity fields on learnings (as_of, evidence, validity, supersedes) #146/fix: serialize concurrent same-target supersession writes across every write leg #166 built — full validation ladder (pre-lock fast-fail plus in-lock re-validation including the cycle walk), CAS store claim, guarded markdown backup leg, and a bounded cycle walk that collapses a completed pair into one logical edge so chains extend. A pre-existing cyclic chain is reported for human repair and never extended.
  • store_compiled validates declared sources against existing learnings (ES-FR-012, closes enhancement: dewey_store_compiled should validate sources param maps to existing learnings #93) and returns the same proposal/coverage parity fields.
  • lint gains the citation_coverage kind over store-backed compiled articles (never auto-repaired) with checked/skipped/failed outcome reporting.
  • The /dewey-distill review gate asks which proposed supersessions to confirm alongside the promote selection and applies them via supersede_learning before promoting; the curator allowlist is extended to eight tools (the feat: curator agent for /dewey-distill with enforced human gates #152 six-tool baseline plus verify_candidates from feat: /dewey-distill verify step before the review gate #151 and supersede_learning from this change).
  • Docs synced (README, AGENTS.md, manifest, help text — stale recency wording removed; 013 spec contracts annotated); website sync filed as docs website#409 and blog website#410, with scope-extension comments on website#376 and website#393.

Rebase note: upstream/main advanced 29 commits (curator-tool-allowlist, dewey-distill-verify-step, gate-config-path-parity) during this change's pipeline run. The branch was rebased onto upstream/main and the overlapping surfaces composed: the curator allowlist now carries both authorized additions, tool counts pin the composed 52-tool union (44/51/45 exact per configuration), and the /dewey-distill command carries both the verify step and the supersession apply stage.

How to Test

CI parity (derived from .github/workflows/ci.yml, run locally on the rebased branch, all green):

  • go build -v ./... && go vet ./...
  • go test -race -count=1 -coverprofile=coverage.out ./... (17/17 packages, 0 failures)
  • gaze crap --format=json --coverprofile=coverage.out --max-crapload=48 --max-gaze-crapload=45 ./... (CRAPload 47/48, GazeCRAPload 3/45)

Acceptance scenarios (openspec/changes/explicit-supersession-in-compile/specs/explicit-supersession/spec.md, ES-FR-001..013):

  1. Prompt policy — grep -n "favor" tools/compile.go shows no recency-favor wording; buildSynthesisPrompt renders per-learning validity/supersedes/superseded_by and an ## Open Conflicts section for undeclared contradictions (tools/compile_test.go assertions).
  2. Per-claim citations — compile output requires bracketed learning-identity citations; tools/citations.go computes forward/backward coverage, verified by tools/citations_test.go.
  3. Proposals — synthesis may append ## Supersession Proposals; compile parses, validates (drop reasons: missing_successor, missing_target, successor_not_source, target_not_source, successor_equals_target, empty_rationale), strips it, and returns proposed_supersessions + dropped_proposals.
  4. store_compiled (ES-FR-012, closes enhancement: dewey_store_compiled should validate sources param maps to existing learnings #93) — declaring an unknown source is refused with nothing written; same proposal/coverage parity fields as compile.
  5. supersede_learning MCP tool — with a running dewey serve and two stored learnings, call supersede_learning(successor, target): two-way links recorded in store and markdown backups; reverse declarations, cycles, and unknown identities refused; extending a completed chain (supersede(c, b) after supersede(b, a)) succeeds — regression-pinned in tools/supersede_test.go.
  6. lint citation_coverage — run dewey lint: store-backed compiled articles with uncited claims produce citation_coverage findings (never auto-repaired), with checked/skipped/failed outcome reporting.
  7. /dewey-distill gate — run /dewey-distill: the review gate asks which proposed supersessions to confirm alongside the promote selection and applies confirmed pairs via supersede_learning before promoting (curator allowlist carries all eight tools; HUMAN_GATE markers intact).
  8. Tool count — server_test.go TestNewServer_ToolCount pins the exact per-configuration counts (44 / 51 / 45); the documented union count is 52 tools across README/AGENTS/manifest.

How to Demo

Run /dewey-distill on a vault with stored learnings that contradict: compile surfaces an ## Open Conflicts section citing both positions; the review gate lists proposed supersessions; confirm one pair and watch it applied via supersede_learning before promotion; re-run dewey lint and observe citation_coverage findings on any article with uncited claims.

Key Files Changed

37 files, +6388/−154 (14 commits). Highlights:

  • tools/compile.go — temporal entry fields, declared-supersession prompt policy, proposals and coverage
  • tools/citations.go (new, pure) — forward/backward citation coverage helper
  • tools/proposals.go (new) — supersession-proposal parsing and validation
  • tools/supersede.go (new) — supersede_learning MCP tool with full-ladder validation and bounded cycle walk
  • tools/lint.go — citation_coverage kind and declared-supersession remediation text
  • tools/learning.go, store/store.go — guarded write paths backing the supersession links
  • server.go, types/tools.go — tool registration and input types
  • .opencode/agents/curator.md + agents.go — allowlist gains supersede_learning (frontmatter and prompt text, byte-identical pair)
  • .opencode/commands/dewey-distill.md + slash_commands.go — review gate asks for supersession confirmations; section 7 applies them before promote
  • README.md, AGENTS.md, .uf/dewey/manifest.md, cli.go — documentation surfaces (52-tool union count)
  • openspec/changes/explicit-supersession-in-compile/ — spec artifacts (ES-FR-001..013, KD-FR-104)
  • specs/013-knowledge-compile/ — FR-008 supersession annotations

Known Issues

The code review council returned APPROVE WITH ADVISORIES (5/5 reviewers); 10 non-blocking advisories recorded for follow-up (3 MEDIUM: lint.go raw literals vs store constants, research.md FR-008 mid-table annotation, untested multi-hop reaches refusal; 7 LOW). Spec review returned APPROVE WITH ADVISORIES after 3 iterations with all findings resolved or applied per the recorded human decisions.


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

…-in-compile

Renumber all requirements with ES/KD capability prefixes and
allocation headers; move the distill review-gate requirement into a
knowledge-distillation delta (KD-FR-104) that supersedes the
dewey-distill byte-compat clause; record the tier exception; state
the supersession of 013-knowledge-compile FR-008; and apply the
medium/low review findings across spec, design, and tasks.
…supersession-in-compile

All 24 deduplicated findings decided by the human through the
pause-relay; every decision is an apply:

- HIGH-1: identity grammar accepts legacy pre-unbound-force#146 {tag}-{seq}
  identities (ES-FR-003/ES-FR-010, new scenario); design risk names
  legacy learnings as intended first-class signal
- HIGH-2: full validation ladder (fast-fails + cycle walk +
  reverse-pair check) re-runs inside the withLearningPropsLock hold
  (ES-FR-007, design D6); reverse-pair race scenario added to
  ES-FR-008 so task 6.4's no-cycle assertion is implementable
- Pre-existing-cycle policy (human Option A, fail-closed): walk
  terminating on a pre-existing cyclic chain returns an error naming
  the cycle and writes nothing (ES-FR-008 body, scenario, task 6.4)
- ES-FR-006: rationale sanitization (control/invisible Unicode
  stripped, 512-rune bound, gate treats as data) and
  dropped_proposals reporting channel
- ES-FR-010: per-source supersession status in the pure helper's
  input contract; declared-source normalization (learning/<id>);
  concrete in-body-mention predicate; anchored claim-bearing-body
  boundary (last ## History heading)
- ES-FR-011: scope aligned to store-backed articles; closing clause
  restated observably
- LTV-FR-001 pointer corrected (allocated by
  serialize-supersession-writes delta)
- Read-only registration inside if !readOnly (design D6, task 6.3)
- Curator allowlist extension (human-approved protected-surface
  change): curator.md + agents.go embed + cli_test.go assertions
  (new task 8.3)
- KD-FR-104: prompt-mode gate scenario (store_compiled results);
  archive-time byte-compat record + task 9.5
- Phase 9 restructure: stale recency-text surfaces task (cli.go,
  server.go, dewey-compile.md + slash_commands.go, manifest);
  website sync consolidated into one task naming adjacent published
  surfaces; 013 annotation extended to spec.md FR-008/AC4/research/
  tasks restatements; AGENTS.md enumerations added to task 9.2
- Exact file paths on tasks 1.2/2.1/2.2/2.3; proposal.md tier
  exception cross-reference fixed
…-supersession artifacts

Council returned APPROVE WITH ADVISORIES (correlation
f484d47b-b6a7-4b45-a6f6-59ae816867a2, 4 runs, 0 failures). All four
advisories folded in before implementation:

- task 9.6 + proposal Impact: 013 spec.md annotation enumeration
  extended to every restatement layer — user-story prose (~31),
  independent test (~37), acceptance scenario 2 (~42), SC-002
  (~190), SC-007 (~195) alongside FR-008/AC-4
- task 9.1: README temporal-validity section (~813-815,
  insert-time-only "Set by: supersedes input" framing) annotated
  with the supersede_learning path, mirroring 9.2's AGENTS.md clause
- design Risks: withheld-temporal-values trade-off documented
  (withhold-and-continue vs a report channel; lint follow-up
  observation named)
- ES-FR-013 + design D7: topic fixed to the stored page's name on
  the store_compiled path
LearningEntry decodes validity/supersedes/superseded_by from page
properties with shape-validation at the decode boundary (ES-FR-003),
and buildSynthesisPrompt renders the temporal lines only when present
so legacy learnings render byte-identical (ES-FR-004). Tasks 1.1-1.4.
Remove recency instructions, restate declared-supersession authority
in decision/context rules, add Open Conflicts, per-claim citation,
and Supersession Proposals instructions to buildSynthesisPrompt;
consolidate prompt assertions with mutation-checked tests
(ES-FR-001, ES-FR-004, ES-FR-005). Tasks 2.1-2.5.
HIGH (divisor-testing): supersede_learning falsely refused chain
extension — the cycle walk read a completed pair's two stored
representations (successor.supersedes + target.superseded_by) as a
walkable 2-cycle, so supersede(c, b) after a healthy supersede(b, a)
was refused as a pre-existing cycle, breaking the distill review
gate's sequential proposal application. The walk now tracks how each
node was reached and skips only the mutual reverse of the arrival
edge, collapsing a completed pair into one logical edge; the pair's
own forward link is ignored in its supersedes representation only, so
a genuine reverse declaration still refuses. Regression tests pin
chain extension off both members and the mid-chain successor.

MEDIUM: successor-side backup refusal coverage (mirror of the target
side, plus the equal-value idempotent rewrite); TestSupersedeLearning_
UnknownIdentity's mutating page-name case isolated into its own test.

MEDIUM (protect tags): dewey-compile.md Instructions re-wrapped in
<protect>/</protect> (the phase-9 embed regeneration had synced to an
unprotected tracked file), embed regenerated byte-identically, drift
test for the pair, and a structural test asserting every embedded
command with ## Instructions carries the wrapper.

LOW: checkCitationCoverage degrades per-page now — one unreadable
article no longer fails the whole pass — with a citation_coverage_
checks outcome (checked/skipped/failed) mirroring anchor_checks;
superseded-source mention matching is boundary-aware (auth-1 no
longer matches auth-10) via mentionsIdentity; dead extractCitations
removed; compile.go routes the supersession predicate through the
shared supersededFrom and the learning/ prefix through
store.LearningPrefix; SupersedeLearning accumulates warnings across
write legs instead of overwriting; ToolCount pins exact counts;
AGENTS.md backward-compatibility paragraph restored to the Store
Learning API section. Spec delta gains the chain-extension scenario
and the logical-link collapse wording under ES-FR-008.

Gate: build/vet/gofmt clean, full-repo race tests pass, Gaze
CRAPload 47/48, GazeCRAPload 3/45.
…task complete

Task 9.9 (run /uf.review-council until APPROVE) is the change's final
open checkbox; the code-review council returned APPROVE WITH ADVISORIES
(5/5 reviewers) with iteration-1 findings addressed in e85e787. The
checkbox edit rode the finale stage sweep so HEAD stays at the commit
the approving review artifact records.

Assisted-by: glm-5
Generated with AI assistance (glm-5)
@jflowers
jflowers enabled auto-merge (rebase) November 12, 2026 19:39

@uf-divisor uf-divisor left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Council Review: APPROVE WITH ADVISORIES

5 reviewers dispatched (divisor-adversary, divisor-architect, divisor-curator, divisor-guard, divisor-testing); 3 returned APPROVE WITH ADVISORIES, 2 returned APPROVE. All 7 findings are LOW severity — 6 advisories plus one positive test-quality assessment. No CRITICAL or HIGH findings.

CI: build-and-test and MegaLinter both pass. Linked issue: #150 — both acceptance criteria covered (synthesis prompt no longer resolves by recency; coverage check available as a lint kind and a compile report).

Findings

# Severity Category Location Reviewer
1 LOW error-handling tools/lint.go:993 (compiledPageContent) adversary
2 LOW injection tools/proposals.go:229 (sanitizeProposalRationale) adversary
3 LOW resilience tools/lint.go:980 (citationCoverageSources) adversary
4 LOW path-safety tools/learning_temporal.go:110 (ValidLearningIdentity) adversary
5 LOW DRY tools/compile.go:1200 (resolveCompiledSources) architect
6 LOW architectural tools/compile.go (file-wide, 1431 lines) architect
7 LOW test-quality (positive) tools/compile_test.go:2578 testing

Findings 1–5 and 7 are posted as inline comments. Finding 6 is file-wide and has no single anchor:

6. tools/compile.go has grown to 1431 lines handling clustering, synthesis prompting, proposal parsing/stripping, coverage reporting, and source validation. CI passes, but the file is the hub of this 37-file change and approaches the God-file boundary; the incremental ES-FR-001..013 additions accumulated in one file without a split.

Verdict rationale

All findings are LOW and non-blocking. The explicit-supersession design is well-executed: declared two-way links replace recency-based contradiction resolution, per-claim citations carry forward/backward coverage, the new supersede_learning tool validates the full ladder inside the lock hold, and the curator allowlist extension keeps the frontmatter and prompt-text copies byte-identical under parity tests.

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

Comment thread tools/lint.go

// compiledPageContent joins a page's store blocks into the article text
// lint checks — the persisted body, never a file on disk.
func (l *Lint) compiledPageContent(pageName string) (string, error) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LOW · error-handling (divisor-adversary)

compiledPageContent joins all of a compiled page's store blocks into one string with no size bound before CheckCitationCoverage scans it. A very large compiled article — from a hallucinating synthesis provider or content that bypassed truncation via store_compiled — places high memory and GC pressure on every lint pass. The per-page skip handles unreadable blocks but not oversized ones. Root cause: the lint path always loads the full article text; no size bound runs before CheckCitationCoverage. Capping the joined content the way the chunker caps chunks would bound the pass.

Comment thread tools/compile.go
@@ -1008,6 +1197,60 @@ func (c *Compile) writeEmptyIndex() error {
return os.WriteFile(indexPath, []byte(content), 0o644)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LOW · DRY (divisor-architect)

resolveCompiledSources (lines 1200–1214) and Lint.citationCoverageSources (tools/lint.go:973–992) both normalize identities via supersedesIdentity and resolve store.LearningPrefix + id lookups to learningSuperseded. The duplication is deliberate — store_compiled fails closed while lint stays advisory — but the shared normalize-and-lookup sequence now lives in two places and can drift apart. Extracting the common resolution into one helper with per-caller failure policies would keep both behaviors honest against each other.

Comment thread tools/compile_test.go
// out of the synthesized text, stripped from the stored article, and
// surfaced on the compile result with successor, target, rationale, and
// topic.
func TestCompile_ProposalsParsedStrippedSurfaced(t *testing.T) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LOW · test-quality, positive (divisor-testing)

The test coverage for this change is exemplary: the compile, citations, proposals, and supersede paths are exercised with isolated fixtures, table-driven cases, and concurrent race coverage aligned to ES-FR-001..013 (TestCompile_ProposalsParsedStrippedSurfaced here, plus the citations and supersede suites). No blocking gaps. Noted as a positive assessment, not a defect.

Comment thread tools/proposals.go
// — then bounds the result to maxProposalRationaleRunes runes (ES-FR-006).
// The rationale is data presented at the review gate, never instructions,
// so the same trust boundary the identities get applies here.
func sanitizeProposalRationale(s string) string {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LOW · injection (divisor-adversary)

sanitizeProposalRationale strips control and invisible Unicode correctly, but it drops characters silently with no observability. When over-sanitization empties a rationale, the drop reason reports empty_rationale, conflating a low-quality proposer with sanitization that removed everything. A debug log recording the removed-rune count — or a distinct drop reason when sanitization empties a non-empty input — would separate the two causes.

Comment thread tools/lint.go
for _, s := range sources {
id := supersedesIdentity(s)
if id == "" {
continue

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LOW · resilience (divisor-adversary)

citationCoverageSources silently skips empty identities (if id == "" { continue }) and treats missing learnings as non-superseded, diverging from store_compiled's fail-closed resolution (ES-FR-012). The divergence is intentional — lint is advisory — but malformed sources: [""] frontmatter yields source_count 0 and reports complete coverage instead of flagging the malformed entry. Surfacing skipped-empty sources in the report's Skipped list would make the signal visible.

@@ -109,6 +109,95 @@ func ValidLearningIdentity(identity string) bool {
return !strings.Contains(identity, "..")
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LOW · path-safety (divisor-adversary)

ValidLearningIdentity guards paths with a substring .. check plus rejection of /, \, and .. Combined with the strict isLearningIdentity grammar, traversal is blocked today, and no exploit exists through the current store.LearningPrefix + filepath.Join usage. The defense is character-based rather than canonicalization-based, so it relies on caller discipline. Applying filepath.Clean and re-checking the prefix would make the guard structural rather than positional.

@jflowers
jflowers merged commit 5147aa1 into unbound-force:main Nov 12, 2026
2 checks passed
jflowers added a commit that referenced this pull request Nov 12, 2026
- distill gate: withhold compiled articles whose sources a confirmed
  supersession touches (they predate the link); a failed apply no longer
  aborts every promotion; correct the claim that unconfirmed proposals
  resurface in lint.
- compile/store_compiled: drop proposals supersede_learning would refuse
  (link_conflict, unresolved_learning) or that conflict within the run
  (duplicate_proposal/target/successor, reverse_of_proposal).
- citations: an unmatched "[" is literal text, so interval notation can
  no longer swallow every later citation.
- identity grammar: accept empty hyphen segments that normalizeTag
  produces ("api - auth" -> "api---auth"), keeping those learnings
  citable.
- supersede_learning: refuse when the cycle walk exhausts its hop bound
  (raised to 256) instead of treating it as safe; roll back the
  successor leg when the target claim fails or is lost.
- proposals: strip every proposals section and ignore headings inside
  fenced code.
- lint: a citation-free (pre-upgrade) compiled article is one info
  finding instead of a warning per uncited source.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@jflowers
jflowers deleted the opsx/explicit-supersession-in-compile branch November 15, 2026 20:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants