Skip to content

fix: hydrate chat files from artifact ledger#4232

Open
samrusani wants to merge 2 commits into
tinyhumansai:mainfrom
samrusani:codex/3226-chat-files-cold-load
Open

fix: hydrate chat files from artifact ledger#4232
samrusani wants to merge 2 commits into
tinyhumansai:mainfrom
samrusani:codex/3226-chat-files-cold-load

Conversation

@samrusani

@samrusani samrusani commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Adds a thread-scoped artifact listing helper around openhuman.ai_list_artifacts.
  • Hydrates the chat files chip from the persisted artifact ledger when Redux starts cold.
  • Merges only ready, valid artifacts into chatRuntime.artifactsByThread[threadId].
  • Adds focused Vitest coverage for service mapping/failure cases and the cold-redux UI path.

Problem

Solution

  • listArtifactsForThread(threadId) wraps the Tauri call, normalizes response rows, ignores pending/malformed artifacts, and returns a non-throwing success/failure outcome.
  • ChatFilesChip now runs the thread-scoped hydration once per thread change and dispatches upsertArtifactReadyForThread for ready artifacts.
  • The hydration trigger lives in ChatFilesChip because it is the always-mounted owner for this surface; ChatFilesPanel cannot mount when Redux has zero ready files because the chip returns null.
  • The backend is unchanged. The mount call is thread-scoped and effect-driven, not run per render, to avoid redundant scans.

Submission Checklist

  • Tests added or updated (happy path + at least one failure / edge case) per Testing Strategy
  • Diff coverage >= 80% - GitHub Frontend Checks (quality, i18n, docs, coverage) passed for PR fix: hydrate chat files from artifact ledger #4232.
  • Coverage matrix updated - N/A: behavior-only change to an existing chat artifact surface; no feature row added/removed/renamed.
  • All affected feature IDs from the matrix are listed in the PR description under ## Related - N/A: no matrix feature row changed.
  • No new external network dependencies introduced (mock backend used per Testing Strategy)
  • Manual smoke checklist updated if this touches release-cut surfaces (docs/RELEASE-MANUAL-SMOKE.md) - N/A: no release manual smoke surface changed.
  • Linked issue closed via Closes #NNN in the ## Related section

Impact

  • Desktop/web chat runtime: chat file availability can recover from persisted artifact metadata after Redux is empty.
  • No storage migration, backend command change, or new dependency.
  • Failure fallback is conservative: if hydration fails, the chip remains hidden until normal in-memory artifact events arrive.

Related


AI Authored PR Metadata (required for Codex/Linear PRs)

Linear Issue

  • Key: N/A
  • URL: N/A

Commit & Branch

  • Branch: codex/3226-chat-files-cold-load
  • Commit SHA: 1dcb0a1

Validation Run

  • corepack pnpm --dir app exec vitest run --config test/vitest.config.ts src/components/chat/__tests__/ChatFilesChip.test.tsx src/services/__tests__/artifactDownloadService.test.ts --reporter=dot
  • corepack pnpm --dir app exec eslint src/components/chat/ChatFilesChip.tsx src/components/chat/__tests__/ChatFilesChip.test.tsx src/services/artifactDownloadService.ts src/services/__tests__/artifactDownloadService.test.ts
  • corepack pnpm --dir app exec prettier --check .
  • cargo fmt --manifest-path Cargo.toml --all --check
  • cargo fmt --manifest-path app/src-tauri/Cargo.toml --all --check
  • corepack pnpm --filter openhuman-app compile
  • git diff --check origin/main..HEAD
  • Pre-push hook with repo-pinned pnpm@10.10.0 via corepack pnpm shim: format check, app lint, Rust check, and command token lint passed.
  • GitHub PR CI Frontend Checks (quality, i18n, docs, coverage) passed for PR fix: hydrate chat files from artifact ledger #4232.

Validation Blocked

  • command: plain pnpm ... from the Codex runtime
  • error: runtime pnpm was 11.7.0 while the repo pins pnpm@10.10.0; it tried to remove node_modules non-interactively and failed with ERR_PNPM_ABORTED_REMOVE_MODULES_DIR_NO_TTY.
  • impact: reran validation with corepack pnpm so the pinned repo package manager was used. The app package still warns that local Node is v22.22.3 while it wants >=24.0.0.
  • command: sandboxed corepack pnpm --filter openhuman-app test:coverage
  • error: failed before running tests with listen EPERM: operation not permitted 127.0.0.1:5005.
  • impact: reran unsandboxed past the listener failure, then stopped the redundant local run after GitHub CI completed the frontend coverage job successfully.

Behavior Changes

  • Intended behavior change: a chat with persisted ready artifacts can repopulate the files chip from ai_list_artifacts({ thread_id }) after Redux starts empty.
  • User-visible effect: the chat files chip/panel can reappear for existing per-thread artifacts without waiting for a new artifact event.

Parity Contract

  • Legacy behavior preserved: existing in-memory artifact events still drive the same Redux slice and panel rendering.
  • Guard/fallback/dispatch parity checks: malformed, pending, and failed artifact listing results are ignored; hydration dispatches through upsertArtifactReadyForThread.

Duplicate / Superseded PR Handling

Summary by CodeRabbit

  • New Features
    • Thread attachments now auto-load when a chat opens, showing any ready files already available for that conversation, and the files chip updates its count/visibility accordingly.
  • Bug Fixes
    • The chip now normalizes thread identifiers to ensure files show under the correct conversation.
    • If loading artifacts fails, the chip remains hidden.
    • Added safeguards to avoid stale updates after the view is closed.

@coderabbitai

coderabbitai Bot commented Jun 27, 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c6ccb3a9-aa3c-496a-83ca-6c105ad210ec

📥 Commits

Reviewing files that changed from the base of the PR and between 1dcb0a1 and 3da26df.

📒 Files selected for processing (4)
  • app/src/components/chat/ChatFilesChip.tsx
  • app/src/components/chat/__tests__/ChatFilesChip.test.tsx
  • app/src/services/__tests__/artifactDownloadService.test.ts
  • app/src/services/artifactDownloadService.ts
🚧 Files skipped from review as they are similar to previous changes (4)
  • app/src/services/artifactDownloadService.ts
  • app/src/services/tests/artifactDownloadService.test.ts
  • app/src/components/chat/tests/ChatFilesChip.test.tsx
  • app/src/components/chat/ChatFilesChip.tsx

📝 Walkthrough

Walkthrough

Adds listArtifactsForThread to fetch ready artifacts for a thread from openhuman.ai_list_artifacts, then hydrates ChatFilesChip from that result and stores ready artifacts in chatRuntime.artifactsByThread using a trimmed thread id.

Changes

Cold-start artifact hydration

Layer / File(s) Summary
listArtifactsForThread service types and implementation
app/src/services/artifactDownloadService.ts
Exports ListedArtifactKind, ListedThreadArtifact, ListThreadArtifactsOutcome and implements listArtifactsForThread with thread-id validation, paginated RPC calls, ready-artifact filtering, and typed output mapping.
ChatFilesChip Redux hydration effect
app/src/components/chat/ChatFilesChip.tsx
Adds Redux dispatch/select hooks, normalizes threadId, hydrates ready artifacts on mount/update, stores them with upsertArtifactReadyForThread, and passes the normalized id to ChatFilesPanel.
Service and component tests for hydration
app/src/services/__tests__/artifactDownloadService.test.ts, app/src/components/chat/__tests__/ChatFilesChip.test.tsx
Adds coverage for validation, RPC pagination and mapping, hydration success, thread-id normalization, and failed hydration behavior.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

agent

Poem

🐇 I hopped through the ledger, quick as a beam,
Found ready files waiting in a disk-dream.
The chip now remembers what cold starts forgot,
Trimmed ids and fresh state keep the panel on spot.
A carrot for Redux, a bundle of cheer,
Artifacts return when the thread reappears!

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR adds frontend hydration and a listing helper, but it does not implement the linked issue's backend thread_id field or ai_list_artifacts filter. Add thread_id to ArtifactMeta, implement ai_list_artifacts thread_id filtering in the backend, and add legacy-thread handling and tests.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 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 summarizes the main change: hydrating chat files from the artifact ledger.
Out of Scope Changes check ✅ Passed All changes are directly related to chat file hydration, artifact listing, and their tests.

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.

@samrusani samrusani marked this pull request as ready for review June 27, 2026 21:40
@samrusani samrusani requested a review from a team June 27, 2026 21:40
@coderabbitai coderabbitai Bot added the agent Built-in agents, prompts, orchestration, and agent runtime in src/openhuman/agent/. label Jun 27, 2026

@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: 1dcb0a19b3

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

try {
const raw = await callCoreRpc<AiListArtifactsData>({
method: 'openhuman.ai_list_artifacts',
params: { thread_id: trimmedThreadId, offset: 0, limit: 200 },

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Fetch every artifact page before hydrating

When a thread has more than 200 persisted artifacts, this helper only requests the first page and ignores the RPC's total, while ChatFilesChip runs hydration only once per thread change. Ready artifacts beyond the first page are therefore never upserted after a cold Redux load, so the Files panel permanently hides older files in long artifact-heavy chats; please keep paging with increasing offset until all thread artifacts have been considered.

Useful? React with 👍 / 👎.

@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: 2

🤖 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 `@app/src/components/chat/ChatFilesChip.tsx`:
- Around line 29-35: Normalize the thread identifier in ChatFilesChip before it
is used with Redux state or actions. The current use of raw threadId in
artifactsByThread lookup and related dispatches can create a separate bucket
from the canonical trimmed ID used by listArtifactsForThread(). Introduce a
single normalized/canonical thread ID in ChatFilesChip and use it consistently
in the useMemo selector, any artifact-related dispatches, and any other
thread-scoped references in this component so all reads and writes hit the same
thread state.

In `@app/src/services/artifactDownloadService.ts`:
- Around line 156-163: Fetch all paginated artifact results before returning
from the artifact download flow. In artifactDownloadService’s list-artifacts
logic, the current call to openhuman.ai_list_artifacts only processes the first
page with a fixed limit, so update this path to loop through subsequent pages
using offset/limit until no more artifacts are returned, then merge and map
through readyListedArtifact before returning the final artifacts array.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a79b29f7-6080-43d5-af1c-a7317cc318b3

📥 Commits

Reviewing files that changed from the base of the PR and between 5a41a4f and 1dcb0a1.

📒 Files selected for processing (4)
  • app/src/components/chat/ChatFilesChip.tsx
  • app/src/components/chat/__tests__/ChatFilesChip.test.tsx
  • app/src/services/__tests__/artifactDownloadService.test.ts
  • app/src/services/artifactDownloadService.ts

Comment thread app/src/components/chat/ChatFilesChip.tsx
Comment thread app/src/services/artifactDownloadService.ts Outdated
@samrusani

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: 3da26dff30

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent Built-in agents, prompts, orchestration, and agent runtime in src/openhuman/agent/.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ai_list_artifacts: thread_id filter + ArtifactMeta.thread_id field

1 participant