Skip to content

[codex] Structure client state key errors#3374

Open
juliusmarminge wants to merge 1 commit into
mainfrom
codex/client-state-key-errors
Open

[codex] Structure client state key errors#3374
juliusmarminge wants to merge 1 commit into
mainfrom
codex/client-state-key-errors

Conversation

@juliusmarminge

@juliusmarminge juliusmarminge commented Jun 20, 2026

Copy link
Copy Markdown
Member

Summary

  • replace generic project/thread atom-key failures with distinct Schema-tagged errors carrying malformed keys
  • validate project-reference and asset-collection keys while preserving exact native JSON or Schema causes
  • reuse the shared thread-key parser in environment thread atoms instead of maintaining a duplicate raw-error path

Validation

  • pnpm vp test packages/client-runtime/src/state/assets.test.ts packages/client-runtime/src/state/entities.test.ts packages/client-runtime/src/state/threads-atoms.test.ts
  • pnpm vp check (20 pre-existing warnings)
  • pnpm vp run typecheck

No active open PR modifies these files.


Note

Low Risk
Localized error-handling and key parsing in client state atoms; behavior on valid keys is unchanged and failures become more explicit rather than riskier.

Overview
Client-runtime atom family keys now fail with typed, inspectable errors instead of generic Error or unchecked JSON.parse casts.

In entities.ts, parseProjectKey and parseThreadKey throw distinct tagged errors that include the malformed key; parseProjectRefCollectionKey validates JSON as an array of [string, string] tuples and wraps parse/decode failures with the original cause. assets.ts adds the same pattern for asset collection keys (EnvironmentId + AssetResource[]) via parseAssetCollectionKey and InvalidAssetCollectionKeyError.

threads.ts drops its duplicate thread-key helpers and uses shared threadKey / parseThreadKey from entities.ts. New unit tests cover malformed keys, invalid shapes, and preserved causes for assets and scoped entity keys.

Reviewed by Cursor Bugbot for commit 6274e96. Bugbot is set up for automated code reviews on this repo. Configure here.

Note

Replace generic errors with structured tagged error classes for client state key parsing

  • Introduces InvalidAssetCollectionKeyError, InvalidScopedProjectKeyError, InvalidScopedThreadKeyError, and InvalidScopedProjectRefCollectionKeyError as Schema.TaggedErrorClass instances, each carrying the offending key and underlying cause.
  • Adds parseAssetCollectionKey, parseProjectKey, parseThreadKey, and parseProjectRefCollectionKey utilities that validate key shape via effect/Schema and throw the appropriate structured error on failure.
  • Updates createAssetEnvironmentAtoms and createEnvironmentThreadStateAtoms to use these shared parse utilities instead of inline JSON.parse calls.
  • Behavioral Change: callers that previously caught generic Error on malformed keys will now receive typed tagged errors with structured fields.

Macroscope summarized 6274e96.

@coderabbitai

coderabbitai Bot commented Jun 20, 2026

Copy link
Copy Markdown

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: ae9beceb-58a4-4551-ab44-38a46c885f43

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
  • Commit unit tests in branch codex/client-state-key-errors

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:M 30-99 changed lines (additions + deletions). labels Jun 20, 2026
Co-authored-by: codex <codex@users.noreply.github.com>
@juliusmarminge juliusmarminge force-pushed the codex/client-state-key-errors branch from 9a3c08a to 6274e96 Compare June 20, 2026 13:50
@github-actions github-actions Bot added size:L 100-499 changed lines (additions + deletions). and removed size:M 30-99 changed lines (additions + deletions). labels Jun 20, 2026
@macroscopeapp

macroscopeapp Bot commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Approved

This PR replaces generic error throws with structured error classes for better debugging, adds Schema validation for key parsing, removes duplicate code, and includes comprehensive tests. The changes only affect error paths and don't alter happy-path runtime behavior.

You can customize Macroscope's approvability policy. Learn more.

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

Labels

size:L 100-499 changed lines (additions + deletions). vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant