Skip to content

fix(sources): close live tool-results/file-history-snapshot classification gaps - #3663

Merged
Sinity merged 5 commits into
masterfrom
feature/sources/omsw-tool-result-file-history-sidecars
Aug 3, 2026
Merged

Sinity merged 5 commits into
masterfrom
feature/sources/omsw-tool-result-file-history-sidecars

Conversation

@Sinity

@Sinity Sinity commented Aug 3, 2026

Copy link
Copy Markdown
Owner

Summary

Closes two live artifact-taxonomy classification gaps described in polylogue-omsw: tool-results/*.json sidecars and file-history-snapshot-only Claude Code JSONL streams could still be admitted as independent sessions under specific acquisition conditions, despite recent work (PR #3614) already fixing the primary daemon-watcher path. Adds a non-destructive reclassification actuator for already-contaminated raw rows, declares the required SEMANTIC_REPARSE index-schema bump, and regenerates the demo-tour evidence that bump legitimately shifts.

Problem

polylogue import <path> --explain against synthetic fixtures reproduced two live gaps at HEAD (evidence, not just code reading, per the bead's own AC):

  1. classify_artifact_path(path, provider=Provider.UNKNOWN) never consults the Claude Code tool_result_sidecar OriginArtifactRule, because artifact_rule_for_path gates on an exact provider match. Any acquisition route that cannot pre-fix the provider (the daemon's shared "inbox" import source backing polylogue import <path>, and this taxonomy's own pre-decode path-only callers) admitted a tool-results/*.json sidecar as an independent session whenever its content happened to resemble a different provider's session-document shape. Reproduced live: a claude-ai-export-shaped payload under tool-results/ became session:claude-ai:... with 1 message.

  2. A Claude Code projects/<proj>/<uuid>.jsonl file whose only records are file-history-snapshot/progress checkpoints (never a chat turn) matches the exact same path shape as a genuine coordinator_session_stream, so the path-only OriginArtifactRule always won and classified it parse_as_session=True. require_positive_conversational_evidence already refuses to materialize this as an index-tier session post-parse, but the raw-tier artifact_taxonomy/raw_artifacts classification is a separate layer that must independently say "sidecar", not "session that later turned out empty".

A live read-only query (source.db, 2026-08-03) also confirmed the bead's third question: the workflow-journal family (polylogue-lzh8) is closed -- 0 sessions join to raw_artifacts.artifact_kind='workflow_journal' -- with one unrelated residual (1 unclassified zero-message session whose raw_artifacts row was never materialized; noted as a minor follow-up, not contamination).

Solution

  • polylogue/archive/artifact_taxonomy/runtime.py: _classify_artifact_path_strong now also checks the Claude Code tool_result_sidecar rule regardless of the caller-supplied provider hint, scoped narrowly to that one rule kind (tool-results/ is a directory name specific enough to Claude Code to check provider-agnostically; coordinator_session_stream's generic pattern is not). classify_artifact's path-rule fast path now runs a content override (_file_history_snapshot_override) before returning a session verdict, refusing when every decoded record's type is file-history-snapshot/progress.
  • polylogue/archive/artifact_taxonomy/models.py / support.py: new ArtifactKind.FILE_HISTORY_SNAPSHOT + looks_like_file_history_snapshot_only_stream, mirroring the type set archive/raw_materialization.py's parsed_non_session_artifact_reason already checks post-parse.
  • polylogue/storage/tool_result_history_sweep.py + devtools/tool_result_history_sweep_report.py + devtools/tool_result_history_reclassify_apply.py: read-only sweep and --apply-gated actuator, mirroring the existing binary_artifact_sweep/binary_artifact_reclassify_apply pattern (polylogue-hbtj2). Persists raw_artifacts rows via the existing materialize_artifact_observations primitive; never touches raw_sessions, revision_authority, or index.db. Registered in devtools/command_catalog.py as devtools workspace tool-result-history-sweep / ...-reclassify-apply.
  • polylogue/storage/sqlite/archive_tiers/index.py + lifecycle.py: bumps INDEX_SCHEMA_VERSION 57->58 with a SEMANTIC_REPARSE declaration (same shape as v42/v44/v45/v46/v48), since the classification change alters parse_as_session for identical input bytes. devtools lab policy classifier-fingerprints manifest entries recorded via --ack.
  • docs/examples/demo-tour/: regenerated (polylogue demo tour --force) because polylogue/demo/receipts.py embeds PRAGMA user_version (== INDEX_SCHEMA_VERSION) in its completion-claim sample-manifest hash.

Not run: the reclassification actuator was built and tested against a synthetic fixture archive only, per instruction. It was NOT run with --apply against the real archive (/realm/db/polylogue) -- that live mutation, and the polylogue ops reset --index && polylogued run this SEMANTIC_REPARSE bump requires to actually re-materialize the affected sessions, are left as explicit operator follow-ups. devtools workspace tool-result-history-sweep --json (read-only, safe to run directly) reports the live count/disposition first: 3 tool-results rows found (matching the operator's own prior investigation), 0 file-history-snapshot-only raw rows found in the current live scan.

Verification

  • devtools test tests/unit/sources/test_artifact_taxonomy.py -> 15 passed
  • devtools test tests/unit/storage/test_tool_result_history_sweep.py -> 3 passed
  • devtools test -k "artifact_taxonomy or sidecar" -> 151 passed
  • devtools test tests/unit/storage/test_index_fast_forward_lifecycle.py tests/unit/storage/test_index_fast_forward_executor.py tests/unit/devtools/test_archive_schema_fast_forward.py tests/unit/storage/test_schema_policy_contracts.py -> 60 passed
  • devtools verify --quick -> exit 0 (format, lint, mypy, render-all, layering, all lab policy gates including classifier-fingerprints and schema-versioning, demo-tour-freshness)
  • Manual scratch reproduction: polylogue import <path> --explain against synthetic fixtures under a scratch dir, before/after the fix, confirming sessions: 0 for both shapes post-fix (was sessions: 1 for each, pre-fix)
  • Read-only live query against /realm/db/polylogue (mode=ro) confirming the workflow-journal family closure and the tool-results sweep counts cited above

Ref polylogue-omsw

Sinity added 4 commits August 3, 2026 18:51
Problem: bd polylogue-omsw asks for a scratch acquisition run (not code
reading) proving the current discovery path no longer mints independent
sessions for tool-results/*.json and file-history-snapshot-only files.
`polylogue import <path> --explain` reproduced two live gaps:

1. classify_artifact_path(path, provider=Provider.UNKNOWN) never consults
   the Claude Code tool_result_sidecar OriginArtifactRule, because
   artifact_rule_for_path gates on an exact provider match. Any acquisition
   route that cannot pre-fix the provider (the daemon's shared "inbox"
   import source backing `polylogue import <path>`, and this taxonomy's
   own pre-decode path-only callers) admitted a tool-results/*.json sidecar
   as an independent session whenever its content happened to resemble a
   different provider's session-document shape (reproduced live: a
   claude-ai-export-shaped payload).

2. A Claude Code projects/<proj>/<uuid>.jsonl file whose only records are
   file-history-snapshot/progress checkpoints (never a chat turn) matches
   the exact same path shape as a genuine coordinator_session_stream, so
   the path-only OriginArtifactRule always won and classified it
   parse_as_session=True. require_positive_conversational_evidence already
   refuses to materialize this as an index-tier session post-parse, but
   the raw-tier artifact_taxonomy/raw_artifacts classification is a
   separate layer that must independently say "sidecar", not "session
   that later turned out empty".

Solution:
- runtime.py: _classify_artifact_path_strong now also checks the Claude
  Code tool_result_sidecar rule regardless of the caller-supplied provider
  hint, scoped narrowly to that one rule kind (tool-results/ is a
  directory name specific enough to Claude Code to check provider-
  agnostically; coordinator_session_stream's generic pattern is not).
- runtime.py: classify_artifact's path-rule fast path now runs a content
  override (_file_history_snapshot_override) before returning a session
  verdict, refusing when every decoded record's type is
  file-history-snapshot/progress.
- models.py: new ArtifactKind.FILE_HISTORY_SNAPSHOT.
- support.py: looks_like_file_history_snapshot_only_stream, mirroring the
  type set archive/raw_materialization.py's
  parsed_non_session_artifact_reason already checks post-parse.
- tests/unit/sources/test_artifact_taxonomy.py: two new regression tests
  pinning both fixes, including a sanity check that genuine sessions at
  the same path shapes are unaffected.

Verification: `devtools test tests/unit/sources/test_artifact_taxonomy.py`
-> 15 passed in 12.37s. Manually re-ran the exact scratch reproduction
(`polylogue import <path> --explain` against synthetic fixtures under
/realm/tmp/work/omsw-scratch/) before and after the fix, confirming
sessions=0 for both shapes post-fix.

Ref polylogue-omsw
Problem: polylogue-omsw AC #3 requires that already-ingested tool-results/
file-history-snapshot rows be RECLASSIFIED, never deleted, following the
2026-07-22 hook-inflation postmortem's durable-tier evidence retention
precedent, and that the count/disposition be recorded. No actuator existed
scoped to this bead's two families (the existing
devtools/binary_artifact_reclassify_apply.py covers an unrelated binary-
database miscapture class, polylogue-hbtj2).

Solution, mirroring the binary_artifact_sweep/reclassify_apply pattern
exactly:
- polylogue/storage/tool_result_history_sweep.py: read-only sweep over
  claude-code-session raw_sessions rows, reusing inspect_raw_artifact (now
  correctly classifying both families after the artifact_taxonomy fix) as
  a pure function. Never mutates source.db.
- devtools/tool_result_history_sweep_report.py: CLI report over the sweep
  (human-readable + --json).
- devtools/tool_result_history_reclassify_apply.py: --apply-gated actuator
  that persists raw_artifacts rows via the existing
  materialize_artifact_observations primitive (the same durable-observation
  machinery binary_artifact_reclassify_apply.py already uses). Default is
  dry-run; never touches raw_sessions, revision_authority, or index.db.
- devtools/command_catalog.py + docs/devtools.md (rendered): registers both
  as `devtools workspace tool-result-history-sweep` /
  `...-reclassify-apply`.
- tests/unit/storage/test_tool_result_history_sweep.py: seeds a source.db
  with one tool-results row, one file-history-snapshot-only row, and one
  genuine session, and proves (a) the sweep finds exactly the two
  contaminated rows, (b) dry-run writes nothing, (c) --apply persists the
  correct raw_artifacts.artifact_kind for each row while leaving
  raw_sessions row count unchanged (never deletes).

Not run: this actuator is built and tested against a synthetic fixture
archive only. Per instruction, it was NOT run with --apply against the
real archive (/realm/db/polylogue) -- that live mutation is left as an
explicit follow-up for an operator with that authority. `devtools
workspace tool-result-history-sweep --json` (read-only, safe to run
directly) reports the live count/disposition first.

Verification: `devtools test tests/unit/storage/test_tool_result_history_sweep.py`
-> 3 passed in 10.26s. `mypy` clean on all three new modules.
`ruff format --check` / `ruff check` clean.

Ref polylogue-omsw
Problem: devtools lab policy classifier-fingerprints (part of devtools
verify --quick) failed after the artifact_taxonomy fix: classify_artifact's
logic changed classification decisions for identical input bytes (a
tool-results/*.json sidecar with a non-Claude-Code provider hint, and a
file-history-snapshot-only stream) without a declared INDEX_SCHEMA_VERSION
delta. Per docs/internals.md's schema-versioning model and the polylogue-lzh8
precedent (4db6b83, v48), an undeclared semantic classification change
leaves already-materialized wrong-classification rows untouched forever --
fast-forward convergence has no version transition to act on.

Solution: bump INDEX_SCHEMA_VERSION to 58 (archive_tiers/index.py) and add
its IndexDeltaDeclaration (storage/sqlite/lifecycle.py) with
classes=(SEMANTIC_REPARSE,) and no fast-forward operations -- the same
"values depend on parser semantics, no clone-safe SQL delta" shape as v42/
v44/v45/v46/v48. Also recorded the classifier-fingerprint manifest entries
(devtools lab policy classifier-fingerprints --ack) for classify_artifact
(semantic_reparse_version=58) and the new
looks_like_file_history_snapshot_only_stream helper (acknowledged_safe).

This does NOT run any rebuild. The operator must run `polylogue ops reset
--index && polylogued run` deliberately to apply it.

Verification: `devtools lab policy classifier-fingerprints` ->
"Classifier fingerprint policy intact." `devtools lab policy
schema-versioning` -> "Schema evolution policy intact." `devtools test
tests/unit/storage/test_index_fast_forward_lifecycle.py
tests/unit/storage/test_index_fast_forward_executor.py
tests/unit/devtools/test_archive_schema_fast_forward.py
tests/unit/storage/test_schema_policy_contracts.py` -> 60 passed.

Ref polylogue-omsw
Problem: devtools lab policy demo-tour-freshness (part of devtools verify
--quick) started failing after the polylogue-omsw INDEX_SCHEMA_VERSION 57->58
bump. polylogue/demo/receipts.py's completion-claim sample manifest embeds
`PRAGMA user_version` (== INDEX_SCHEMA_VERSION) directly into its hash
payload, so bumping the schema version legitimately changes the manifest
hash the demo tour prints -- this is the same mechanism every prior
SEMANTIC_REPARSE bump has needed a matching regeneration for.

Solution: ran `polylogue demo tour --out-dir polylogue-demo-tour --force`
and copied the regenerated transcript.txt, report.md, report.json,
recording.tape, and command-output/*.txt into docs/examples/demo-tour/
per the tool's own fix instruction. Only the sample-manifest hash line and
wall-clock timing fields changed; the mask-aware freshness check's own
comparison (which zeroes timing) confirms no unmasked drift remains.

Verification: `devtools lab policy demo-tour-freshness` -> "fresh tour
output matches committed docs/examples/demo-tour/ (masked)".

Ref polylogue-omsw
@coderabbitai

coderabbitai Bot commented Aug 3, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

@Sinity, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 9 minutes

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

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: f5b998ed-3876-42bd-887d-ecafbecd4f42

📥 Commits

Reviewing files that changed from the base of the PR and between 3af8223 and 00ddc56.

📒 Files selected for processing (17)
  • devtools/command_catalog.py
  • devtools/tool_result_history_reclassify_apply.py
  • devtools/tool_result_history_sweep_report.py
  • docs/devtools.md
  • docs/examples/demo-tour/command-output/01-claim-versus-receipt.txt
  • docs/examples/demo-tour/report.json
  • docs/examples/demo-tour/report.md
  • docs/examples/demo-tour/transcript.txt
  • docs/plans/classifier-fingerprints.json
  • polylogue/archive/artifact_taxonomy/models.py
  • polylogue/archive/artifact_taxonomy/runtime.py
  • polylogue/archive/artifact_taxonomy/support.py
  • polylogue/storage/sqlite/archive_tiers/index.py
  • polylogue/storage/sqlite/lifecycle.py
  • polylogue/storage/tool_result_history_sweep.py
  • tests/unit/sources/test_artifact_taxonomy.py
  • tests/unit/storage/test_tool_result_history_sweep.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.

…w-tool-result-file-history-sidecars

# Conflicts:
#	docs/devtools.md
@Sinity
Sinity merged commit 449c387 into master Aug 3, 2026
2 of 3 checks passed
@Sinity
Sinity deleted the feature/sources/omsw-tool-result-file-history-sidecars branch August 3, 2026 17:43
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