popoto.recipes.view_resolver¶
popoto.recipes.view_resolver
¶
Belief-sheet view resolver — read-path claim resolution over the journal (#565).
The assistant's read path can rank and truncate memory candidates but cannot
remove one because another record retracts it, has no reader-scoped
visibility, and emits no claim-level output: ContextAssembler.assemble()
is additive-then-truncate, so a retracted claim keeps its rank and is
injected into the prompt as if it were live.
This module is the view layer that fixes that. :class:BeliefSheetResolver
wraps an inner: ContextAssembler (the AdaptiveAssembler composition
precedent — wrap, never extend assemble()) and computes a
:class:BeliefSheet: surviving claims (retracted dropped, superseded
collapsed to winners, disjunctions shown as explicit uncertainty), each with
a provenance handle, a per-entry staleness annotation, and deterministic,
replayable resolution — a pure function over the journal parameterized by a
plain policy dict.
Per-resolve() I/O budget (enforced by the call-count spy test)::
1 assemble + <=1 gate batch + <=K chain reads
The gate batch is zero when visibility resolves from already-fetched record
fields (no reader tags); otherwise it is the single batched tag-membership
read _resolve_tag_keys already performs. Chains are fetched only for the
already-truncated top-K, and membership stays on the V0 exclusion path — no
chain walk decides membership. Winner confirmations resolve from the
winner's own chain when the winner was also selected, and read 0 otherwise.
Example
from popoto.recipes.context_assembler import ContextAssembler from popoto.recipes.view_resolver import BeliefSheetResolver
resolver = BeliefSheetResolver( ContextAssembler(model_class=JournalEntry, score_weights={...}) ) sheet = resolver.resolve( {"subject": "launch"}, reader={"agent_id": "agent-1", "purpose": "answer"}, ) for claim in sheet.claims: print(claim.key, claim.provenance)
POLICY_KEYS = ('prefer', 'staleness_threshold', 'gate_overfetch_multiplier', 'max_backfill_pulls')
module-attribute
¶
Recognized policy dict keys. Unknown keys are ignored with a warning.
PREFER_OPTIONS = ('recent', 'self-stated', 'confirmed')
module-attribute
¶
Winner precedence when competing supersessions disagree.
self-stated prefers the correction stated outright (stated=True),
confirmed prefers the most corroborated, recent prefers the latest.
A complete tie is flagged as an unresolved contradiction for downstream
(escalation-only) LLM handling — the deterministic fold never guesses.
Claim
dataclass
¶
One surviving claim on the belief sheet.
Attributes:
| Name | Type | Description |
|---|---|---|
key |
str
|
Stable provenance handle — the record's Redis key, matching
the |
rank |
int
|
Position in the final sheet order (0-based). |
score |
float | None
|
Injection-time score proxy from the trace, or None when the record was not trace-attached. |
source |
str
|
|
content |
str
|
The claim text ( |
staleness |
float | None
|
Decayed relevance score, or None when the model has no
DecayingSortedField in |
stale |
bool | None
|
True when |
provenance |
dict[str, Any]
|
|
Source code in src/popoto/recipes/view_resolver.py
BeliefSheet
dataclass
¶
Ordered surviving claims plus operational warnings.
Deterministic in (journal, policy): :meth:serialize renders a
canonical byte string, so the same journal snapshot + policy dict
replays byte-identical. Wall-clock-derived fields (retrieval timing)
are deliberately excluded from the serialization.
Source code in src/popoto/recipes/view_resolver.py
serialize()
¶
Canonical JSON rendering for replay comparison.
Source code in src/popoto/recipes/view_resolver.py
BeliefSheetResolver
¶
Read-path view over a ContextAssembler plus the journal (#565).
Wraps inner: ContextAssembler (never extends assemble()) and
owns gate → resolve → annotate → emit. The resolver performs no writes,
so it cannot race itself; concurrent annotations landing between
retrieval and chain resolution are dropped with a warning via the
chain re-check in :func:resolve_entries (Race 1), and replay pins a
journal snapshot so it stays deterministic.
Per-resolve() I/O budget: 1 assemble + <=1 gate batch + <=K
chain reads. The gate batch is zero when the reader carries no tags
(visibility resolves from already-fetched fields); otherwise it is one
batched tag-membership read. Back-fill pulls (capped by policy) each
cost one further assemble.
Source code in src/popoto/recipes/view_resolver.py
610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 | |
resolve(query_cues=None, *, reader=None, policy=None, as_of=None, exclude_keys=None, now=None, **assemble_kwargs)
¶
Resolve the belief sheet for a concrete reader under a policy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query_cues
|
dict[str, Any] | None
|
Retrieval cues, passed through to |
None
|
reader
|
dict[str, Any] | None
|
Concrete |
None
|
policy
|
dict[str, Any] | None
|
Plain dict (see :func: |
None
|
as_of
|
float | None
|
Point-in-time membership, passed through to |
None
|
exclude_keys
|
Any
|
Caller suppression keys, unioned per pull. |
None
|
now
|
float | None
|
Clock override for the staleness read (replay pins this). |
None
|
assemble_kwargs
|
Any
|
Further |
{}
|
Returns:
| Type | Description |
|---|---|
BeliefSheet
|
class: |
BeliefSheet
|
mid-gating) fail CLOSED without raising: an empty sheet plus a |
BeliefSheet
|
|
Source code in src/popoto/recipes/view_resolver.py
639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 | |
resolve_policy(policy)
¶
Merge a caller policy dict over library defaults.
None selects every default (read from :class:Defaults at call
time, so deploy-level overrides apply). Unknown keys are ignored with
a warning per key, never a crash. An invalid prefer falls back to
the default with a warning.
Source code in src/popoto/recipes/view_resolver.py
resolve_entries(records, chains_by_key, policy, *, handles_by_key=None, staleness_by_key=None)
¶
Fold selected records + annotation chains into a belief sheet.
Pure function: no Redis, no clock, no RNG. Drop retracted stragglers,
collapse superseded losers to their winners (loser→winner handle links
on the winner's provenance["supersedes"]), count confirmations,
pair structural disjuncts as explicit uncertainty, and flag unresolved
contradictions for downstream LLM escalation only.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
records
|
list[Any]
|
Selected record objects in rank order. |
required |
chains_by_key
|
dict[str, list[Any]]
|
|
required |
policy
|
dict[str, Any] | None
|
Plain dict (see :func: |
required |
handles_by_key
|
dict[str, dict[str, Any]] | None
|
|
None
|
staleness_by_key
|
dict[str, tuple[Any, bool]] | None
|
|
None
|
Membership notes: a record targeted by ANY closing annotation (supersede/retract, including one that landed after the V0 snapshot — the Race 1 window) is dropped as a loser, never kept. That re-check costs no extra read because the chain postdates the snapshot.
Source code in src/popoto/recipes/view_resolver.py
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 | |