-
Notifications
You must be signed in to change notification settings - Fork 0
fix(knowledge): preserve retrieval identity across origins and expose historical search #214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ce6ad3d
chore(audit): transport verified retrieval repair on isolated branch
drewstone ff5dd09
fix(knowledge): preserve retrieval identity across origins and expose…
9501e0f
fix(knowledge): make origin citation handles round-trip without delim…
drewstone 3fe9377
chore(audit): apply exact citation review cleanup on existing repair …
drewstone 679d589
fix(knowledge): reuse the already selected citation audit sources
1d2de3b
docs(knowledge): document collision-free citation handles and legacy …
drewstone 43cf11b
test(knowledge): use the public citationIds contract for search round…
drewstone af1c930
chore(audit): reconcile pinned retrieval repair with merged Eval comp…
drewstone dce4b63
Merge Eval 0.183 compatibility into origin-safe retrieval repair
github-actions[bot] a89c128
test(knowledge): qualify reconciled retrieval against both supported …
drewstone File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| import { describe, expect, it } from 'vitest' | ||
| import { | ||
| formatKnowledgeCitationReference, | ||
| parseKnowledgeCitationReference, | ||
| resolveKnowledgeCitation, | ||
| } from './citation-resolution' | ||
| import { buildKnowledgeBrief } from './knowledge-brief' | ||
| import type { PageOrigin } from './run-scoped' | ||
| import type { KnowledgePage } from './types' | ||
|
|
||
| const page = (id: string, text: string): KnowledgePage => ({ | ||
| id, | ||
| text, | ||
| title: text, | ||
| path: `${id}.md`, | ||
| outLinks: [], | ||
| tags: [], | ||
| sourceIds: [], | ||
| frontmatter: { id }, | ||
| }) | ||
|
|
||
| describe('citation serialization is injective, including legacy delimiter collisions', () => { | ||
| it('round trips every supported origin/page pair without banning existing names', () => { | ||
| const origins: (PageOrigin | undefined)[] = [ | ||
| undefined, | ||
| 'here', | ||
| 'shared', | ||
| 'inherited:a', | ||
| 'inherited:a::b', | ||
| 'inherited:a:', | ||
| 'inherited:a%3A%3Ab', | ||
| 'inherited:∑:研究', | ||
| 'inherited:%/::x', | ||
| ] | ||
| const ids = [ | ||
| 'c', | ||
| 'b::c', | ||
| 'here::literal', | ||
| 'shared::', | ||
| 'knowledge-ref:v1:literal', | ||
| '%3A%3A', | ||
| 'quantum-∑', | ||
| 'a::b::c', | ||
| ] | ||
| const handles = new Set<string>() | ||
| for (const origin of origins) { | ||
| for (const pageId of ids) { | ||
| const reference = { pageId, ...(origin === undefined ? {} : { origin }) } | ||
| const handle = formatKnowledgeCitationReference(reference) | ||
| expect(parseKnowledgeCitationReference(handle)).toEqual(reference) | ||
| expect(handles.has(handle)).toBe(false) | ||
| handles.add(handle) | ||
| } | ||
| } | ||
| }) | ||
|
|
||
| it('leaves normal handles and legacy literal percent sequences unchanged', () => { | ||
| expect(formatKnowledgeCitationReference({ origin: 'inherited:a', pageId: 'c' })).toBe( | ||
| 'inherited:a::c', | ||
| ) | ||
| expect(parseKnowledgeCitationReference('inherited:a%3A%3Ab::c')).toEqual({ | ||
| origin: 'inherited:a%3A%3Ab', | ||
| pageId: 'c', | ||
| }) | ||
| expect(formatKnowledgeCitationReference({ pageId: 'plain' })).toBe('plain') | ||
| }) | ||
|
|
||
| it('keeps the two former colliding origins distinct through search and resolution', () => { | ||
| const first = page('c', 'Quantum first') | ||
| const second = page('b::c', 'Quantum second') | ||
| const visible = [ | ||
| { page: first, origin: 'inherited:a::b' as const }, | ||
| { page: second, origin: 'inherited:a' as const }, | ||
| { page: page('c', 'Banana local'), origin: 'here' as const }, | ||
| ] | ||
| const result = buildKnowledgeBrief(visible, 'quantum') | ||
| expect(result.results).toHaveLength(2) | ||
| expect(new Set(result.citationIds).size).toBe(2) | ||
| for (const [index, hit] of result.results.entries()) { | ||
| const resolved = resolveKnowledgeCitation( | ||
| visible, | ||
| parseKnowledgeCitationReference(result.citationIds[index]!), | ||
| ) | ||
| expect(resolved.resolved?.page).toBe(hit.page) | ||
| expect(resolved.resolved?.origin).toBe(hit.origin) | ||
| } | ||
| }) | ||
|
|
||
| it('retrieves literal reserved-prefix page names through the same formatter', () => { | ||
| const literal = page('knowledge-ref:v1:literal', 'Quantum reserved name') | ||
| const visible = [{ page: literal, origin: 'here' as const }] | ||
| const brief = buildKnowledgeBrief(visible, 'quantum') | ||
| expect(brief.results).toHaveLength(1) | ||
| expect( | ||
| resolveKnowledgeCitation(visible, parseKnowledgeCitationReference(brief.citationIds[0]!)) | ||
| .resolved?.page, | ||
| ).toBe(literal) | ||
| }) | ||
|
|
||
| it('rejects malformed encoded references instead of silently changing their identity', () => { | ||
| for (const value of ['%', '%5B%5D', '%5Bnull%5D', '%5Btrue%2C%22p%22%5D']) { | ||
| expect(() => parseKnowledgeCitationReference(`knowledge-ref:v1:${value}`)).toThrow( | ||
| /invalid encoded knowledge citation/, | ||
| ) | ||
| } | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a lineage contains an ancestor ID with
::—whichassertRunIdcurrently permits—this encoding is not injective:{ origin: 'inherited:a::b', pageId: 'c' }and{ origin: 'inherited:a', pageId: 'b::c' }both becomeinherited:a::b::c. The resulting clones are treated as duplicate IDs byrankByGraph, suppressing valid graph edges, and any emitted qualified handle for the first page is parsed back as the wrong origin/page pair. Either reject the citation delimiter in run IDs or use an escaped/structured identity for ranking and serialization.AGENTS.md reference: AGENTS.md:L7-L7
Useful? React with 👍 / 👎.