Skip to content

fix(antigravity): flag fragmented brain-metadata sessions degraded - #1856

Merged
Sinity merged 1 commit into
masterfrom
feature/fix/antigravity-degraded-1764
Jun 13, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/fix/antigravity-degraded-1764

Conversation

@Sinity

@Sinity Sinity commented Jun 13, 2026

Copy link
Copy Markdown
Owner

Summary

Implements the v1 AC from #1764: flags fragmented brain-metadata sessions as
degraded:brain-metadata-fragment so they are excludable from primary session
counts and insight rollups. Uses ParsedSession.ingest_flags — a new in-memory
field that the storage layer drains into auto-tags at write time — so no schema
version bump is required
.

Problem

Antigravity's brain-metadata fallback path builds a composite
provider_session_id of {parent_dir}:{artifact_name} per *.metadata.json
file. Under the v1 identity law every artifact becomes its own single-message
session. One logical work session shatters into N sessions, polluting session
counts and insight rollups silently.

Solution

Three touch-points, no schema change:

polylogue/sources/parsers/base_models.py — adds ingest_flags: list[str]
to ParsedSession. Parsers set flags to communicate structural quality issues;
the storage layer writes them as (auto, parser) session_tags. Default: empty
list (all other parsers are unaffected).

polylogue/sources/parsers/antigravity.py — parse_brain_metadata sets
ingest_flags=["degraded:brain-metadata-fragment"]. Exports BRAIN_METADATA_FRAGMENT_FLAG
constant for use in filters and tests.

polylogue/storage/sqlite/archive_tiers/write.py — _write_ingest_flag_tags
helper writes each flag as a session_tags row (tag_source='auto',
method='parser') inside the same with conn: block as the session row. The
session_tags table in index.db already supports tag_source='auto'; no new
column or version bump needed.

Also records the two investigation findings as an issue comment:

  • Grouping key: artifact_path.parent.name is a reliable per-session directory
    key → option A (aggregate) is viable.
  • Language-server availability: binary is Nix/install-dependent, not
    universally available → option C requires a fallback; brain-metadata path
    remains necessary.

Verification

# Format + lint
nix develop /realm/project/polylogue --command ruff format <touched files>
nix develop /realm/project/polylogue --command ruff check <touched files>
# → 0 issues

# Types
nix develop /realm/project/polylogue --command mypy <touched files>
# → Success: no issues found in 5 source files

# Parser-level regression tests (6 pass)
devtools test tests/unit/sources/parsers/test_antigravity.py -v
# → 6 passed in 0.69s

# Storage roundtrip tests (3 new pass)
devtools test tests/unit/storage/test_archive_tiers_write.py -k "ingest_flag" -v
# → 3 passed in 0.74s

# Broader sources regression (1332 pass)
devtools test tests/unit/sources/ -v
# → 1332 passed in 52.46s

# Full quick gate (all 15 checks green)
git push  # pre-push hook ran devtools verify --quick
# → exit 0, 30.42s total

Closes #1764

…1764)

Problem: The brain-metadata fallback path in the Antigravity parser builds a
composite `provider_session_id` of `{parent_dir}:{artifact_name}` per artifact.
Under the v1 identity law every metadata file materialises as its own single-
message session.  One work session shatters into N tiny sessions, polluting
session counts and insight rollups.

What changed:
- `ParsedSession` gains an `ingest_flags: list[str]` field (default empty).
  Parsers set flags to communicate structural quality issues without requiring
  new storage columns.
- `parse_brain_metadata` sets `ingest_flags=["degraded:brain-metadata-fragment"]`
  on every session it produces.
- `write_parsed_session_to_archive` calls the new `_write_ingest_flag_tags`
  helper inside its existing `with conn:` transaction, writing each flag as an
  `(auto, parser)` tag row into the index.db `session_tags` table.  No schema
  version bump is required — the `session_tags` table already exists in
  INDEX_DDL and already supports `tag_source='auto'`.
- Three storage roundtrip tests verify: flags write as auto-tags, clean sessions
  gain no spurious tags, and re-ingest is idempotent.
- Two parser-level tests verify: brain-metadata sessions carry the flag and
  markdown-export sessions do not.

Schema impact: none — uses the existing `session_tags` table (index.db,
`tag_source IN ('user', 'auto')`).  No column additions, no version bump.

Ref #1764

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@coderabbitai

coderabbitai Bot commented Jun 13, 2026

Copy link
Copy Markdown

Warning

Review limit reached

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

More reviews will be available in 4 minutes and 11 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

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.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 74b02579-a425-4bd6-bde2-c1c13e2e5642

📥 Commits

Reviewing files that changed from the base of the PR and between b2c3066 and bbcb006.

📒 Files selected for processing (5)
  • polylogue/sources/parsers/antigravity.py
  • polylogue/sources/parsers/base_models.py
  • polylogue/storage/sqlite/archive_tiers/write.py
  • tests/unit/sources/parsers/test_antigravity.py
  • tests/unit/storage/test_archive_tiers_write.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/fix/antigravity-degraded-1764

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 and usage tips.

@Sinity
Sinity merged commit 83efea0 into master Jun 13, 2026
10 of 14 checks passed
@Sinity
Sinity deleted the feature/fix/antigravity-degraded-1764 branch June 13, 2026 11:42

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bbcb0061a6

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Sinity added a commit that referenced this pull request Aug 2, 2026
…sions

Problem

Every antigravity-session row in the live archive (116/116, measured
2026-07-31) is a 1-message fragment materialized from a per-artifact
~/.gemini/antigravity/brain/<uuid>/*.md.metadata.json sidecar -- metadata,
not conversation content. Real conversation content lives in
conversations/*.pb trajectories; acquiring those was already fixed by PR
#3441 (merged), which also stopped classifying future metadata sidecars as
sessions. That fix is forward-only: the 116 already-materialized phantom
sessions and their unclassified raw rows are untouched by it. This closes
the retroactive half of polylogue-eo81/polylogue-msia (the two beads
describe the same finding).

Solution

- polylogue/storage/antigravity_phantom_sweep.py: read-only
  scan_antigravity_phantom_sessions() joins sessions to session_tags on the
  existing degraded:brain-metadata-fragment auto-tag (written at ingest
  time by PR #1856) -- precise, already-present evidence, no new content
  classification needed. Cross-checks each candidate's raw_id against
  source.db's raw_sessions row when a source connection is given, and
  reports (rather than assumes) when that raw row is already missing.
- polylogue/storage/artifacts/persistence.py: adds
  materialize_artifact_observations_for_raw_ids(), a scoped sibling of the
  existing materialize_artifact_observations() full census, so an actuator
  that already knows exactly which raw ids it touched doesn't have to pay
  for a 43k-row census just to classify a handful of rows.
- devtools/antigravity_phantom_sweep_report.py: read-only report CLI.
- devtools/antigravity_phantom_purge_apply.py: --apply-gated actuator.
  Dry-run by default; --apply calls ArchiveStore.delete_sessions() on the
  flagged session ids (the same primitive CLI delete / MCP
  write(operation='delete_session') already reach -- rebuild-safe, since
  PR #3441's ingest-side classifier already refuses *.md.metadata.json as
  session content) and materialize_artifact_observations_for_raw_ids() on
  their raw ids (persists an explicit AGENT_SIDECAR_META classification).
- Registered both as `devtools workspace antigravity-phantom-sweep` /
  `antigravity-phantom-purge-apply`, mirroring the binary-artifact-sweep
  pattern from polylogue-hbtj2 (PR #3576).

Real .pb conversation acquisition: out of scope here, already done.

PR #3441 (merged 2026-07-31) already built acquisition for
conversations/*.pb -- not a raw protobuf parser, but calling Antigravity's
own local language-server RPC (ConvertTrajectoryToMarkdown) to export each
cascade to markdown, verified against 44 real files on the live machine
(2,162 real messages, blob sizes matching on-disk .pb sizes). No new
protobuf-format work was needed or attempted in this change; the only
remaining step is operational (sinnix redeploy + reingest), not code.

Verification

devtools test tests/unit/storage/test_antigravity_phantom_sweep.py
  -> 5 passed (real parse_brain_metadata/parse_markdown_export fixtures,
     real ArchiveStore.write_raw_and_parsed writer; dry-run leaves the
     session untouched; --apply deletes only the tagged phantom and
     leaves a co-located real antigravity session and its raw row alone)
devtools test tests/unit/devtools/test_command_catalog.py \
  tests/unit/devtools/test_render_devtools_reference.py \
  tests/unit/devtools/test_devtools_main.py
  -> 17 passed
devtools verify --quick
  -> exit_code 0 (ruff format/check, mypy --strict, render all --check,
     topology, layering, closure-matrix, schema/manifest/policy lab checks)

Not run: devtools verify --all (no seeded testmon db in this worktree;
--quick plus the two focused pytest runs above are the verification
evidence for this PR, per repo convention for a worktree without a
pre-seeded testmon cache).

Ref polylogue-eo81, polylogue-msia

Co-Authored-By: Claude <[email protected]>
Sinity added a commit that referenced this pull request Aug 2, 2026
…sions (#3581)

## Summary

Retroactive half of the antigravity-inversion finding (polylogue-eo81 / polylogue-msia, the same finding described in two beads): adds a read-only sweep and an `--apply`-gated actuator that delete the 116 already-materialized brain-metadata phantom sessions in the live archive and persist an explicit non-session classification for their raw rows.

## Problem

Every `antigravity-session` row in the live archive (116/116, measured 2026-07-31) is a 1-message fragment materialized from a per-artifact `~/.gemini/antigravity/brain/<uuid>/*.md.metadata.json` sidecar -- metadata, not conversation content. Real conversation content lives in `conversations/*.pb` trajectories.

Acquiring those `.pb` conversations was already fixed by PR #3441 (merged 2026-07-31): it calls Antigravity's own local language-server RPC (`ConvertTrajectoryToMarkdown`) to export each cascade to markdown -- not a raw protobuf parser, since the language server already exposes trajectory content over RPC -- and verified against all 44 real files on this machine (2,162 real messages, blob sizes matching on-disk `.pb` sizes). That PR also stopped classifying *future* metadata sidecars as sessions (`AGENT_SIDECAR_META`).

That fix is forward-only. The 116 already-materialized phantom sessions, and their still-unclassified raw rows in `source.db`, are untouched by it -- PR #3441's own notes call this out explicitly as deliberately out of scope, deferred to a follow-up. This PR is that follow-up.

## Solution

- `polylogue/storage/antigravity_phantom_sweep.py`: read-only `scan_antigravity_phantom_sessions()`. Joins `sessions` to `session_tags` on the existing `degraded:brain-metadata-fragment` auto-tag (written at ingest time by PR #1856) -- precise, already-present evidence, no new content classification needed. Cross-checks each candidate's `raw_id` against `source.db`'s `raw_sessions` row when a source connection is given, and reports (rather than assumes) when that raw row is already missing.
- `polylogue/storage/artifacts/persistence.py`: adds `materialize_artifact_observations_for_raw_ids()`, a scoped sibling of the existing `materialize_artifact_observations()` full census (from polylogue-hbtj2 / PR #3576), so an actuator that already knows exactly which raw ids it touched doesn't pay for a 43k-row census just to classify a handful of rows. (Also fixes a latent bug in the new function: the connection needs `row_factory = sqlite3.Row` set before `_row_to_raw_session` can read columns by name -- caught by this PR's own test.)
- `devtools/antigravity_phantom_sweep_report.py`: read-only report CLI (text or `--json`).
- `devtools/antigravity_phantom_purge_apply.py`: `--apply`-gated actuator. Dry-run by default; `--apply` calls `ArchiveStore.delete_sessions()` on the flagged session ids (the same primitive CLI `delete` / MCP `write(operation='delete_session')` already reach -- rebuild-safe, since PR #3441's ingest-side classifier already refuses `*.md.metadata.json` as session content and won't resurrect them on re-ingest) and `materialize_artifact_observations_for_raw_ids()` on their raw ids (persists an explicit `AGENT_SIDECAR_META` classification).
- Registered both as `devtools workspace antigravity-phantom-sweep` / `antigravity-phantom-purge-apply`, mirroring the binary-artifact-sweep pattern from polylogue-hbtj2.

## Real `.pb` conversation acquisition: already done, not attempted here

Item 2 of both beads' AC ("decide and, if tractable, implement real `.pb` conversation acquisition") was already resolved by PR #3441 before this session started. No protobuf reverse-engineering was needed: the fix routes through Antigravity's own local language-server export RPC rather than parsing the wire format directly. The only remaining step is operational (Sinnix redeploy of the daemon + a reingest pass to acquire the 44 real conversations), not code -- confirmed still pending as of this PR (`raw_sessions` has zero rows referencing `antigravity/conversations` in the live archive checked during this session).

## Verification

```
devtools test tests/unit/storage/test_antigravity_phantom_sweep.py
  -> 5 passed
```
Builds the phantom shape through the real production parser (`parse_brain_metadata`) and the real archive writer (`ArchiveStore.write_raw_and_parsed`), plus a co-located real antigravity session (`parse_markdown_export`, no degraded flag) to prove the sweep and purge never touch it. Confirms: dry-run mutates nothing; `--apply` deletes only the tagged phantom, leaves the real session and its raw row alone, and writes exactly one `raw_artifacts` row with `artifact_kind = AGENT_SIDECAR_META` for the purged raw id.

```
devtools test tests/unit/devtools/test_command_catalog.py tests/unit/devtools/test_render_devtools_reference.py tests/unit/devtools/test_devtools_main.py
  -> 17 passed
```

```
devtools verify --quick
  -> exit_code 0 (ruff format/check, mypy --strict, render all --check, topology,
     layering, closure-matrix, schema/manifest/policy lab checks)
```

Not run: `devtools verify --all` (no seeded testmon db in this worktree). `--quick` plus the two focused pytest runs above are the verification evidence for this PR.

Manual, read-only cross-check against the live archive (`/realm/db/polylogue`, no writes): confirmed the exact shape both beads describe -- 116 `antigravity-session` rows, all `message_count=1`, all tagged `degraded:brain-metadata-fragment`, all `raw_sessions.source_path` ending `.md.metadata.json`, zero existing `raw_artifacts` rows for any of them, and zero `raw_sessions` rows referencing `antigravity/conversations` (the redeploy+reingest for PR #3441's fix has not happened yet). This PR's actuator was not run against the live archive -- per instruction, only built and tested against fixtures.

Ref polylogue-eo81, polylogue-msia
@Sinity

Sinity commented Oct 1, 2026

Copy link
Copy Markdown
Owner Author

Historical Codex triage: evidence checked at 5ebcfe5. This records that source revision; it does not claim a fresh review of current master.

  • 71.F083 / P2: fixed-already at the checked revision: The unchanged-content ingestion path now upserts parser ingest flags before returning at polylogue/pipeline/services/ingest_batch/_core.py:1645. A parsed session with unchanged conversational content therefore receives newly supplied parser tags without requiring those tags to enter its content hash.

Only the rows listed above are dispositioned. Held findings remain open.

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.

fix(parser): antigravity brain-metadata path fragments one work session into N single-message sessions

1 participant