Skip to content

fix: Answer facets from one envelope on both surfaces - #5178

Merged
Sinity merged 1 commit into
masterfrom
fix/facets-operation-parity
Sep 15, 2026
Merged

Sinity merged 1 commit into
masterfrom
fix/facets-operation-parity

Conversation

@Sinity

@Sinity Sinity commented Sep 15, 2026

Copy link
Copy Markdown
Owner

Summary

analyze --facets and polylogue facets returned different documents for the same question. This is a real product defect, not a test drift, and the parity test was correctly reporting it.

Evidence

Receipt .cache/verify/runs/20260914T233651Z-all-207009-89ddea6b (verify_all, job 1699, 22,540 selected, 29 failed).

Caveat on that receipt: its run.json records git_head: f7964acd12b25134c0e2e4cd8f73f9e6557a4a4f — the tip of branch rebase-5165, not master and not an ancestor of it — and final_git_head: 724d17535. The shared checkout advanced across 7 merged PRs during the run, so it is not evidence of a frozen tree. I re-ran all 29 node ids at true master HEAD: 17 reproduce, 12 do not. This one is among the 17.

Observed diff: {'family_status': {}} against a populated per-family state map, and {'deadline_s': None} against {'deadline_s': 2.0}.

Per-failure classification

Failure Classification Cause
test_plain_cli_snapshots::test_facets_command_json_matches_analyze_facets product defect operations/daemon_reads._facets_payload is a drifted hand-copy of the canonical envelope assembly in api/archive.py

Problem

Two implementations answered the same envelope:

  • analyze --facets → query_verbs.py → env.polylogue.facets(...) → the canonical builder in api/archive.py.
  • polylogue facets → commands/facets.py → configured_read_operation(config, "facets", …) → daemon_reads._facets_payload.

_facets_payload's docstring claimed "Reuse the API's canonical aggregate implementation over this reader", but it reused only _archive_facet_buckets — the bucket scan — and restated the assembly around it. That restatement had drifted:

  • never emitted family_status, availability, deadline_s, elapsed_s, stale_age_s;
  • hard-coded budget_exceeded=False and cost_class="cheap" instead of reading the projection contract, so a facets run over budget reported itself cheap and within budget;
  • carried its own divergent family lists — omitted in both complete and deferred, total_counts missing entirely — versus _FACET_CORE_FAMILIES / _FACET_DEFERRED_FAMILIES;
  • had no PostFilterScopeTooLargeError handling, so a scope too large to post-filter raised instead of degrading. That one is the sharpest: it is directly against the rule that a named gap must never read as an empty scope, and it made the two surfaces disagree about whether the question was answerable at all.

Breaking PR: #4867 (1d901ec73), which deleted the API fallback from facets_command, so the daemon-less path stopped answering from the shared builder and started answering from _facets_payload.

Solution

Adding the five missing keys by hand would reproduce the same drift on the next change to either side, so the assembly is extracted once:

  • api/archive.py gains build_facets_response(...) — availability, family lists, family_status, gap classification, buckets, IDF, outcome — and Polylogue.facets delegates to it.
  • daemon_reads._facets_payload builds the same model (including the PostFilterScopeTooLargeError → degraded path it previously lacked) and dumps it with model_dump(by_alias=True, mode="json").

The two surfaces are now equal by construction rather than by keeping two key lists in agreement.

Anti-vacuity

The existing parity test is the condition, and it is a strong one: drop any field from the shared builder, or reintroduce a second assembly on either side, and test_facets_command_json_matches_analyze_facets goes red on the exact key. It compares complete documents, so it cannot be satisfied by patching individual keys.

Verification

devtools test tests/unit/cli/test_plain_cli_snapshots.py tests/unit/archive/test_facets.py \
  tests/unit/operations/test_daemon_reads.py tests/unit/cli/test_daemon_golden_parity.py
devtools test: PASSED exit=0 diagnosis=pytest_passed receipt=.cache/verify/runs/20260915T015123Z-focused-test-334855-17879b1d/run.json

Because this changes a product read path, I ran the wider facets/daemon-read surface as well:

devtools test tests/unit/archive/test_facets.py tests/unit/api/test_facade_contracts.py \
  tests/unit/operations/test_daemon_reads.py tests/unit/operations/test_daemon_protocol.py \
  tests/unit/cli/test_daemon_golden_parity.py tests/unit/daemon/test_daemon_http_contracts.py \
  tests/unit/insights/test_projection_contracts.py tests/unit/cli/test_query_verbs_runtime.py \
  tests/unit/daemon/test_web_reader.py
devtools test: PASSED exit=0 diagnosis=pytest_passed receipt=.cache/verify/runs/20260915T014520Z-focused-test-329027-25d72753/run.json
devtools verify --quick
17/17 gates ok (format, lint, mypy, generated-surfaces, layering, patterns, doc-commands,
schema-manifest, oracle-integrity, testmon-selection, consumer-reachability, test-packages,
timestamp-doctrine, durable-enum-checks, schema-privacy, atlas, population-coverage)

Schema closure

devtools schema closure polylogue/api/archive.py
out  polylogue/api/archive.py
devtools schema closure polylogue/operations/daemon_reads.py
out  polylogue/operations/daemon_reads.py

Both OUT of the derived schema-identity closure. Does not need to land before an archive rebuild.

Residuals

  • This PR also turns test_json_status_snapshot green, which was failing in the original receipt but did not reproduce at HEAD — I am not claiming it as a fix, only noting it now passes.
  • cwd_prefixes and time_range are set by neither surface. That was true before this change and is unchanged; the shared builder makes it visible in one place rather than two.

🤖 Generated with Claude Code

https://claude.ai/code/session_01DYUNBGoE652b3nfmq3CtqK

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@coderabbitai

coderabbitai Bot commented Sep 15, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 34 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Advanced

Run ID: b723cbba-de70-49f3-b078-e0afda491105

📥 Commits

Reviewing files that changed from the base of the PR and between 4105e36 and af20216.

📒 Files selected for processing (2)
  • polylogue/api/archive.py
  • polylogue/operations/daemon_reads.py

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

`analyze --facets` and `polylogue facets` returned different documents for the
same question. The first routed to the canonical builder in `api/archive.py`;
the second routed to `_facets_payload` in `operations/daemon_reads.py`, whose
docstring claimed to reuse that implementation but reused only the bucket
scan and restated the assembly around it.

The restatement had drifted. It emitted no `family_status`, `availability`,
`deadline_s`, `elapsed_s` or `stale_age_s`; hard-coded `budget_exceeded=False`
and `cost_class="cheap"` rather than reading the projection contract; carried
its own family lists, with `omitted` in both complete and deferred and
`total_counts` missing; and had no `PostFilterScopeTooLargeError` handling, so
a scope too large to post-filter raised instead of degrading -- against the
rule that a named gap must not read as an empty scope.

#4867 caused it by deleting the API fallback from `facets_command`, so the
daemon-less path stopped answering from the shared builder.

Adding the five missing keys by hand would restart the same drift, so the
assembly is extracted into `build_facets_response` and both callers build the
same model. The daemon read dumps it. The two surfaces are now equal by
construction rather than by keeping two key lists in agreement.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01DYUNBGoE652b3nfmq3CtqK
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 15, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
🔒 Security Review ✅ Completed 2026-09-15T01:57:28.001221Z 9aaeee9 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@Sinity
Sinity force-pushed the fix/facets-operation-parity branch from 9aaeee9 to af20216 Compare September 15, 2026 01:58
@Sinity
Sinity merged commit 5672c8b into master Sep 15, 2026
3 checks passed
@Sinity
Sinity deleted the fix/facets-operation-parity branch September 15, 2026 02:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant