Skip to content

fix(messages): preserve forward snapshots and attachment uid analysis#78

Merged
69gg merged 7 commits into
mainfrom
bugfix/bugs-11
Jun 24, 2026
Merged

fix(messages): preserve forward snapshots and attachment uid analysis#78
69gg merged 7 commits into
mainfrom
bugfix/bugs-11

Conversation

@69gg

@69gg 69gg commented Jun 24, 2026

Copy link
Copy Markdown
Owner

Summary

  • Snapshot received forward-message trees by conversation scope and let messages.get_forward_msg fall back to local snapshots when OneBot cannot re-read nested forwards.
  • Allow file_analysis_agent multimodal analysis to resolve internal pic_ / file_ attachment UIDs in the current session scope.
  • Clarify Release asset selection, bump all version manifests to 3.6.3, and add the v3.6.3 changelog entry.

Tests

  • pre-commit: ruff format --check, ruff check, mypy

Summary by CodeRabbit

  • New Features
    • Added forward-message snapshot caching to improve nested forwarded-content reliability.
    • Enhanced multimodal/file analysis support for internal attachment UIDs (where applicable).
  • Bug Fixes
    • Prevented duplicate insertion of current-message forwarded context.
    • Improved fallback behavior and diagnostics when forwarded content can’t be re-read.
    • Improved handling of unavailable nested forward metadata.
  • Documentation
    • Expanded release download guidance and deployment instructions; clarified forwarded/attachment behavior in docs.
  • Tests
    • Added coverage for snapshot caching, forward fallback, nested forwarding, and attachment UID workflows.
  • Chores
    • Version bumped to 3.6.3.

69gg and others added 6 commits June 22, 2026 20:21
Co-authored-by: GPT-5 Codex <noreply@openai.com>
Co-authored-by: GPT-5 Codex <noreply@openai.com>
Co-authored-by: GPT-5 Codex <noreply@openai.com>
Co-authored-by: GPT-5 Codex <noreply@openai.com>
@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.

@coderabbitai

coderabbitai Bot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: e2eb8f44-0be8-4db3-8445-ce434294a26b

📥 Commits

Reviewing files that changed from the base of the PR and between d4c93db and de73819.

📒 Files selected for processing (7)
  • docs/deployment.md
  • src/Undefined/attachments/forward_snapshot.py
  • src/Undefined/attachments/segments.py
  • src/Undefined/skills/agents/file_analysis_agent/tools/analyze_multimodal/handler.py
  • tests/test_attachments.py
  • tests/test_file_analysis_attachment_uid.py
  • tests/test_forward_snapshot.py
💤 Files with no reviewable changes (1)
  • src/Undefined/skills/agents/file_analysis_agent/tools/analyze_multimodal/handler.py
✅ Files skipped from review due to trivial changes (1)
  • docs/deployment.md
🚧 Files skipped from review as they are similar to previous changes (4)
  • tests/test_file_analysis_attachment_uid.py
  • tests/test_forward_snapshot.py
  • src/Undefined/attachments/forward_snapshot.py
  • src/Undefined/attachments/segments.py

📝 Walkthrough

Walkthrough

Version 3.6.3 adds forward snapshot caching, snapshot-first forward retrieval, attachment UID resolution in multimodal analysis, a history deduplication ordering change, version bumps, and related docs/tests updates.

Changes

Forward snapshot, attachment, and release flow

Layer / File(s) Summary
Forward snapshot cache infrastructure
src/Undefined/utils/paths.py, src/Undefined/attachments/forward_snapshot.py, src/Undefined/attachments/__init__.py, tests/test_forward_snapshot.py
Adds FORWARD_SNAPSHOT_CACHE_DIR, implements forward snapshot save/load/tree traversal with per-snapshot locking and inflight deduplication, re-exports the helpers, and adds snapshot round-trip, scope, normalization, recursion, and concurrency tests.
Forward attachment registration and tool retrieval
src/Undefined/attachments/segments.py, src/Undefined/handlers/message_flow.py, src/Undefined/skills/toolsets/messages/get_forward_msg/handler.py, tests/test_attachments.py, tests/test_get_forward_msg_tool.py
Adds snapshot-forward parameters to attachment registration, enables snapshot mode from message flow, rewrites get_forward_msg to prefer cached snapshots and emit structured unavailable responses, and updates the related attachment/tool tests.
Multimodal attachment UID resolution
src/Undefined/skills/agents/file_analysis_agent/tools/analyze_multimodal/handler.py, src/Undefined/skills/agents/file_analysis_agent/prompt.md, src/Undefined/skills/agents/file_analysis_agent/README.md, tests/test_file_analysis_attachment_uid.py
Adds pic_/file_ UID resolution through the attachment registry when a file path is missing, and updates the agent docs and tests for same-scope acceptance and cross-scope rejection.
History dedup, versions, and release docs
src/Undefined/ai/prompts/current_input.py, tests/test_prompt_builder_cognitive_query.py, src/Undefined/__init__.py, pyproject.toml, apps/undefined-chat/..., apps/undefined-console/..., CHANGELOG.md, README.md, docs/configuration.md, docs/pipelines.md, docs/usage.md, docs/app.md, docs/build.md, docs/deployment.md
Reorders history dedup message-id matching, bumps all version declarations to 3.6.3, and expands release and forward-snapshot documentation plus the changelog entry.

Sequence Diagram(s)

sequenceDiagram
  participant MessageHandler
  participant register_message_attachments
  participant snapshot_forward_tree
  participant get_forward_msg_handler
  participant load_forward_snapshot
  participant save_forward_snapshot
  participant get_forward_messages

  MessageHandler->>register_message_attachments: snapshot_forward_messages=True
  register_message_attachments->>snapshot_forward_tree: scope_key, forward_id, get_forward_messages
  snapshot_forward_tree->>load_forward_snapshot: lookup cached tree
  alt cache miss
    load_forward_snapshot-->>snapshot_forward_tree: empty
    snapshot_forward_tree->>get_forward_messages: fetch forward nodes
    get_forward_messages-->>snapshot_forward_tree: nodes
    snapshot_forward_tree->>save_forward_snapshot: persist snapshot
  end

  get_forward_msg_handler->>load_forward_snapshot: scope_key, forward_id
  alt snapshot hit
    load_forward_snapshot-->>get_forward_msg_handler: cached nodes
  else snapshot miss
    get_forward_msg_handler->>get_forward_messages: fetch forward nodes
    get_forward_messages-->>get_forward_msg_handler: nodes or error
    alt fetch fails
      get_forward_msg_handler-->>get_forward_msg_handler: structured unavailable response
    end
  end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • 69gg/Undefined#77: Directly precedes this PR with the earlier forward-message handling and get_forward_msg flow that this PR extends with snapshot caching and fallback logic.

Poem

🐇 I hop through forward trees so neat,
With cached snapshots tucked in repeat.
If a path goes missing, I still can see,
The breadcrumb trail from UID to tree.
One hop, two hops, soft ears high —
v3.6.3 skips the stale sky.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 11.76% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and accurately reflects the main changes: forward snapshot preservation and attachment UID analysis.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch bugfix/bugs-11

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 6

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/Undefined/attachments/segments.py (1)

369-383: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Wire snapshot_nested_forward_messages into the snapshot decision.

Line 370 adds a documented compatibility alias, but the body never reads it, so callers passing only snapshot_nested_forward_messages=True get a silent no-op instead of snapshotting.

Proposed fix
     visited_forward_ids: set[str] = set()
+    should_snapshot_forward_messages = (
+        snapshot_forward_messages or snapshot_nested_forward_messages
+    )

Then use should_snapshot_forward_messages in the forward branch:

-                            snapshot_forward_messages
+                            should_snapshot_forward_messages
@@
-                        if snapshot_forward_messages:
+                        if should_snapshot_forward_messages:
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/Undefined/attachments/segments.py` around lines 369 - 383, The
compatibility alias `snapshot_nested_forward_messages` is documented in
`scan_message_segments` but never used, so forwarding-only callers see no
snapshot behavior. Update the forward-message snapshot decision in
`scan_message_segments` (or the existing `should_snapshot_forward_messages`
helper/branch) to treat `snapshot_nested_forward_messages=True` the same as
`snapshot_forward_messages=True`, so either flag enables snapshotting.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/deployment.md`:
- Around line 5-6: The blockquote in the deployment docs is broken by a blank
line, which triggers MD028; update the quoted text so it remains one continuous
blockquote. In the affected markdown section, keep the “Release 下载提示” paragraph
and the following sentence in the same quote format without any empty line
between them, and ensure the blockquote syntax is consistent throughout
docs/deployment.md.

In `@src/Undefined/attachments/forward_snapshot.py`:
- Around line 24-25: The per-snapshot lock cache in _snapshot_locks is unbounded
and never evicted, unlike _snapshot_inflight, so update the snapshot
coordination flow in forward_snapshot.py to clean up locks after the last
in-flight task for a given key completes. Make the cleanup happen in the same
code paths that create and await the per-snapshot lock/task entries so the dict
cannot retain one asyncio.Lock per unique snapshot forever, while preserving the
existing locking behavior around _snapshot_locks and _snapshot_inflight.

In `@src/Undefined/attachments/segments.py`:
- Around line 599-630: The forward attachment loading in snapshot mode can leave
`forward_nodes` empty after `load_forward_snapshot`, which prevents the direct
resolver from ever running. Update the logic in the attachment expansion path
around `snapshot_forward_tree`, `load_forward_snapshot`, and
`_fetch_forward_nodes` so that an empty or unreadable snapshot falls back to
`_fetch_forward_nodes(forward_id)` before relying on `visited_forward_ids`. Keep
the visited check only for preventing repeated resolution, not for suppressing
the fallback when no nodes were loaded.

In
`@src/Undefined/skills/agents/file_analysis_agent/tools/analyze_multimodal/handler.py`:
- Line 6: The multimodal handler currently imports and uses a repo-local
`scope_from_context` fallback, which violates the skills boundary and bypasses
the intended injected scope flow. Remove the direct `Undefined.attachments`
dependency from the handler and rely only on `context`-provided `scope_key` or
`get_scope_from_context` inside the `analyze_multimodal`/handler path, letting
the existing “缺少会话作用域” error branch cover missing wiring.

In `@tests/test_file_analysis_attachment_uid.py`:
- Around line 237-239: The async test in test_file_analysis_attachment_uid is
still doing blocking disk checks via Path.is_file() and Path.read_bytes() on the
event loop. Update that assertion block to perform the file existence/read
verification through asyncio.to_thread(...) or the repo’s async I/O helper,
keeping the same checks but avoiding synchronous filesystem calls in this test.

In `@tests/test_forward_snapshot.py`:
- Around line 28-32: The forward snapshot tests are leaving module-level state
behind when patching the cache directory, which makes cases order-dependent. In
each test that monkeypatches FORWARD_SNAPSHOT_CACHE_DIR, also reset the
forward_snapshot module’s _snapshot_locks and _snapshot_inflight state before
using forward_snapshot helpers so reused forward IDs don’t collide across tests;
apply this consistently in the affected test cases that reference
forward_snapshot and its snapshot cache setup.

---

Outside diff comments:
In `@src/Undefined/attachments/segments.py`:
- Around line 369-383: The compatibility alias
`snapshot_nested_forward_messages` is documented in `scan_message_segments` but
never used, so forwarding-only callers see no snapshot behavior. Update the
forward-message snapshot decision in `scan_message_segments` (or the existing
`should_snapshot_forward_messages` helper/branch) to treat
`snapshot_nested_forward_messages=True` the same as
`snapshot_forward_messages=True`, so either flag enables snapshotting.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: a3a6a38b-f8a2-4137-8936-c206c8b1b752

📥 Commits

Reviewing files that changed from the base of the PR and between 4bb9edb and d4c93db.

⛔ Files ignored due to path filters (5)
  • apps/undefined-chat/package-lock.json is excluded by !**/package-lock.json
  • apps/undefined-chat/src-tauri/Cargo.lock is excluded by !**/*.lock
  • apps/undefined-console/package-lock.json is excluded by !**/package-lock.json
  • apps/undefined-console/src-tauri/Cargo.lock is excluded by !**/*.lock
  • uv.lock is excluded by !**/*.lock
📒 Files selected for processing (31)
  • CHANGELOG.md
  • README.md
  • apps/undefined-chat/package.json
  • apps/undefined-chat/src-tauri/Cargo.toml
  • apps/undefined-chat/src-tauri/tauri.conf.json
  • apps/undefined-console/package.json
  • apps/undefined-console/src-tauri/Cargo.toml
  • apps/undefined-console/src-tauri/tauri.conf.json
  • docs/app.md
  • docs/build.md
  • docs/configuration.md
  • docs/deployment.md
  • docs/pipelines.md
  • docs/usage.md
  • pyproject.toml
  • src/Undefined/__init__.py
  • src/Undefined/ai/prompts/current_input.py
  • src/Undefined/attachments/__init__.py
  • src/Undefined/attachments/forward_snapshot.py
  • src/Undefined/attachments/segments.py
  • src/Undefined/handlers/message_flow.py
  • src/Undefined/skills/agents/file_analysis_agent/README.md
  • src/Undefined/skills/agents/file_analysis_agent/prompt.md
  • src/Undefined/skills/agents/file_analysis_agent/tools/analyze_multimodal/handler.py
  • src/Undefined/skills/toolsets/messages/get_forward_msg/handler.py
  • src/Undefined/utils/paths.py
  • tests/test_attachments.py
  • tests/test_file_analysis_attachment_uid.py
  • tests/test_forward_snapshot.py
  • tests/test_get_forward_msg_tool.py
  • tests/test_prompt_builder_cognitive_query.py

Comment thread docs/deployment.md Outdated
Comment thread src/Undefined/attachments/forward_snapshot.py
Comment thread src/Undefined/attachments/segments.py Outdated
Comment thread tests/test_file_analysis_attachment_uid.py Outdated
Comment thread tests/test_forward_snapshot.py
Co-authored-by: GPT-5 Codex <noreply@openai.com>
@69gg 69gg merged commit f864726 into main Jun 24, 2026
4 checks passed
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