Skip to content

Guard desktop startup against legacy provider state#1027

Open
Amer-alsayed wants to merge 3 commits intopingdotgg:mainfrom
Amer-alsayed:codex/fix-orchestration-legacy-provider
Open

Guard desktop startup against legacy provider state#1027
Amer-alsayed wants to merge 3 commits intopingdotgg:mainfrom
Amer-alsayed:codex/fix-orchestration-legacy-provider

Conversation

@Amer-alsayed
Copy link

@Amer-alsayed Amer-alsayed commented Mar 13, 2026

What Changed

  • Desktop preload fetches the authenticated WS URL via IPC so the renderer always connects to the correct backend endpoint.
  • ProviderSessionDirectory drops unknown persisted providers (e.g., legacy gemini) instead of failing startup.
  • OrchestrationEventStore skips legacy/unreadable events and logs a warning rather than crashing the server.

Why

Persisted legacy provider data can cause orchestration event decode failures at startup, which restarts the backend and leaves the UI stuck (e.g., Add project hangs). This keeps startup resilient and preserves UX while still logging the issue.

UI Changes

None.

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • No UI changes
  • Tests run: bun fmt, bun lint, bun typecheck

Note

Guard desktop startup against legacy provider state and undecodable events

  • readFromSequence in OrchestrationEventStore.ts now skips individual decode failures (logging a warning) rather than failing the stream, and advances pagination based on the last row sequence instead of the last decoded event.
  • getBinding in ProviderSessionDirectory.ts deletes and drops invalid provider sessions instead of propagating a decode error, preventing stale/legacy state from blocking startup.
  • The desktop preload now fetches wsUrl synchronously from the main process via a new desktop:get-ws-url IPC channel instead of reading from an environment variable, returning null on failure.

Macroscope summarized d226081.

@chatgpt-codex-connector
Copy link

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@github-actions github-actions bot added size:XL 500-999 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list. labels Mar 13, 2026
@coderabbitai
Copy link

coderabbitai bot commented Mar 13, 2026

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 8167c66a-3eb9-4f31-b03c-b384ab36b8fc

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
📝 Coding Plan
  • Generate coding plan for human review comments

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.

Tip

You can validate your CodeRabbit configuration file in your editor.

If your editor has YAML language server, you can enable auto-completion and validation by adding # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json at the top of your CodeRabbit configuration file.

if (normalizedLimit === 0) {
return Stream.empty;
}
const readPage = (
Copy link
Contributor

Choose a reason for hiding this comment

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

🔴 Critical Layers/OrchestrationEventStore.ts:216

When a row fails decoding, its sequence is excluded from events, so the pagination cursor (events[events.length - 1]!.sequence) advances past only successfully decoded events. The next query fetches from that cursor, re-retrieving the failed row which fails decoding again, creating an infinite loop. For example: rows with sequences [1,2,3] are fetched, row 3 fails decoding, events becomes [{seq:1},{seq:2}], cursor becomes 2, next query refetches row 3, which fails again.

🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
In file apps/server/src/persistence/Layers/OrchestrationEventStore.ts around line 216:

When a row fails decoding, its sequence is excluded from `events`, so the pagination cursor (`events[events.length - 1]!.sequence`) advances past only successfully decoded events. The next query fetches from that cursor, re-retrieving the failed row which fails decoding again, creating an infinite loop. For example: rows with sequences [1,2,3] are fetched, row 3 fails decoding, `events` becomes [{seq:1},{seq:2}], cursor becomes 2, next query refetches row 3, which fails again.

Evidence trail:
apps/server/src/persistence/Layers/OrchestrationEventStore.ts lines 230-241 (decode failure returns Option.none), lines 248-261 (pagination logic with cursor based on last successful event's sequence at line 258)

@github-actions github-actions bot added size:M 30-99 changed lines (additions + deletions). and removed size:XL 500-999 changed lines (additions + deletions). labels Mar 13, 2026
@Amer-alsayed
Copy link
Author

Updated pagination to advance using the last row sequence when skipping invalid events, preventing decode loops. Desktop WS URL IPC fix and legacy provider cleanup unchanged. Tests: bun fmt, bun lint, bun typecheck.

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

Labels

size:M 30-99 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant