Skip to content

fix(mothership): stop persisting log resources from get_workflow_logs and self-heal stale log panel entries#4424

Merged
waleedlatif1 merged 3 commits intostagingfrom
fix/log-deets
May 4, 2026
Merged

fix(mothership): stop persisting log resources from get_workflow_logs and self-heal stale log panel entries#4424
waleedlatif1 merged 3 commits intostagingfrom
fix/log-deets

Conversation

@waleedlatif1
Copy link
Copy Markdown
Collaborator

@waleedlatif1 waleedlatif1 commented May 4, 2026

Summary

  • Removed GetWorkflowLogs from RESOURCE_TOOL_NAMES in extraction.tsget_workflow_logs is a read-only tool and should never auto-persist log IDs as chat resources. Logs now only enter the resource panel via open_resource, which already validates existence before emitting
  • Added self-healing to EmbeddedLog: when useLogDetail returns a 404, the component fires an onNotFound callback that removes the stale resource from both local state and the DB (DELETE /api/mothership/chat/resources) so it doesn't reappear on next chat load
  • Extended removeResource in use-chat.ts to persist deletions — symmetric with addResource which already persists additions

Fixes the bug where Mothership opens log entries that no longer exist, showing "Log not found - This log may have been deleted or is no longer available."

Root cause: three cooperating issues — get_workflow_logs auto-persisted every returned log ID on each call, persisted resources had no TTL, and the panel auto-selects the last resource on chat load. Free-tier 30-day log cleanup made stale IDs inevitable.

Type of Change

  • Bug fix

Testing

Tested manually

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel
Copy link
Copy Markdown

vercel Bot commented May 4, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped May 4, 2026 7:05am

Request Review

@cursor
Copy link
Copy Markdown

cursor Bot commented May 4, 2026

PR Summary

Medium Risk
Medium risk because it changes how chat resources are persisted/removed (new DELETE side-effect) and adds automatic removal behavior on 404s, which could incorrectly drop resources if errors are misclassified.

Overview
Prevents get_workflow_logs tool results from auto-creating persisted log resources, so logs only appear in the resource panel when explicitly opened.

Adds a self-healing path for the log panel: EmbeddedLog detects a 404 from useLogDetail, triggers an onNotFound callback, and MothershipView removes the stale log resource.

Makes resource removals persistent by extending useChat.removeResource to also DELETE /api/mothership/chat/resources, keeping local UI state and stored chat resources in sync.

Reviewed by Cursor Bugbot for commit 6ce9f59. Configure here.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 4, 2026

Greptile Summary

This PR fixes a bug where Mothership's resource panel displayed stale "Log not found" entries caused by three cooperating issues: get_workflow_logs auto-persisting every returned log ID, no TTL on persisted resources, and the panel auto-selecting the last resource on load. The fix removes GetWorkflowLogs from the auto-persist list, adds self-healing (EmbeddedLog fires onNotFound on 404 which removes the resource from both local state and the DB), and makes removeResource symmetric with addResource by persisting deletions.

Confidence Score: 5/5

Safe to merge — all three cooperating causes of the stale-resource bug are addressed correctly with no new defects introduced.

No P0 or P1 findings. The self-heal flow is correct: 404 fires exactly once before the component unmounts, local state and DB are both cleaned up symmetrically, and the retry guard prevents unnecessary delay. The extraction.ts removal is clean. All changed paths are narrow and well-contained.

No files require special attention.

Important Files Changed

Filename Overview
apps/sim/lib/copilot/resources/extraction.ts Removes GetWorkflowLogs from RESOURCE_TOOL_NAMES and its extraction case — correct because get_workflow_logs is a read-only tool that should never auto-persist log IDs.
apps/sim/hooks/queries/logs.ts Adds a retry guard to useLogDetail that skips retries on 404 errors, making self-healing instantaneous for deleted logs.
apps/sim/app/workspace/[workspaceId]/home/components/mothership-view/components/resource-content/resource-content.tsx Adds onNotFound prop to EmbeddedLog; uses useRef + useEffect to detect 404 errors and fire the callback exactly once before the component unmounts.
apps/sim/app/workspace/[workspaceId]/home/components/mothership-view/mothership-view.tsx Wires onNotFound to onRemoveResource('log', resourceId) so a 404 on the active log resource triggers both local-state and DB cleanup.
apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.ts Extends removeResource to fire-and-forget DELETE /api/mothership/chat/resources, making it symmetric with addResource's persist-on-add behavior.

Sequence Diagram

sequenceDiagram
    participant Panel as ResourcePanel
    participant EmbeddedLog
    participant RQ as React Query (useLogDetail)
    participant API as /api/mothership/chat/resources
    participant DB as Database

    Panel->>EmbeddedLog: render log (stale logId)
    EmbeddedLog->>RQ: useLogDetail(logId)
    RQ->>API: GET log detail
    API-->>RQ: 404 (log deleted)
    Note over RQ: retry: skip on 404
    RQ-->>EmbeddedLog: error (404)
    EmbeddedLog->>EmbeddedLog: useEffect detects 404
    EmbeddedLog->>Panel: onNotFound(resourceId)
    Panel->>Panel: removeResource('log', id) / setResources / setActiveResourceId
    Panel->>API: DELETE /api/mothership/chat/resources {chatId, resourceType, resourceId}
    API->>DB: UPDATE copilotChats remove resource from JSONB array
    DB-->>API: updated resources
    Note over Panel: EmbeddedLog unmounts, stale entry gone permanently
Loading

Reviews (3): Last reviewed commit: "fix(mothership): simplify onNotFoundRef ..." | Re-trigger Greptile

@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@cursor review

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit fd31526. Configure here.

@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@cursor review

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 6ce9f59. Configure here.

@waleedlatif1 waleedlatif1 merged commit 578fc50 into staging May 4, 2026
14 checks passed
@waleedlatif1 waleedlatif1 deleted the fix/log-deets branch May 4, 2026 19:44
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