Skip to content

refactor: Untangle Context contracts and shared API helpers - #1237

Open
sidneyswift wants to merge 2 commits into
mainfrom
codex/untangle-2026-11-09
Open

sidneyswift wants to merge 2 commits into
mainfrom
codex/untangle-2026-11-09

Conversation

@sidneyswift

@sidneyswift sidneyswift commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Separate Context schemas from execution; unify chat-title and AbortError policy; retire duplicate billing validator and superseded unused image adapter. Public request schema bytes and wire behavior are unchanged.

Verification

2,334 tests pass before obsolete adapter retirement; 239 active Sites/Higgsfield tests pass afterward. Repository lint and response-contract typecheck pass. Full TypeScript check retains exactly the same 214 baseline diagnostics, with zero additions. Independent review completed.

Scope and review

Part of the user-requested Recoup monorepo untangle-codebase workflow. Audit and decision log preceded implementation. Changes stay in this owning repository; no production deployment or main-branch merge requested. No broad comment/test-pruning sweep. Existing local work and retired checkouts preserved.

Each repository PR is independently reviewable; the Mono report will collect the coordinated audit, retained cases and check limitations.


Summary by cubic

Separates Context request schemas from execution logic and consolidates shared API helpers without changing any public request schema or wire behavior.

  • Moves contextOperationSchema into its own module so contract consumers no longer load authenticated execution services; a new boundary test enforces this.
  • Consolidates isAbortError into lib/errors/ and relocates generateChatTitle to lib/chats/.
  • Removes duplicate billing validation, the superseded Higgsfield image adapter, and their tests.

Written for commit beacfbd. Summary will update on new commits.

View guided diff Turn on auto-fix

@vercel

vercel Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

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

Project Deployment Actions Updated
api Ready Ready Preview Nov 9, 2026 4:15am UTC

Request Review

@coderabbitai

coderabbitai Bot commented Nov 9, 2026

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@cubic-dev-ai cubic-dev-ai 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.

2 issues found across 29 files

Confidence score: 4/5

  • processContextOperation.ts and contextOperationSchema.ts are both well over the under-100-line guideline, which makes these areas harder to maintain. Split the dispatch logic and schema action groups into cohesive modules.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="lib/context/processContextOperation.ts">

<violation number="1" location="lib/context/processContextOperation.ts:15">
P2: Custom agent: **Enforce Clear Code Style and Maintainability Practices**

`processContextOperation.ts` remains 407 lines, well above the rule’s under-100-line limit; split the remaining action dispatch into cohesive modules.</violation>
</file>

<file name="lib/context/contextOperationSchema.ts">

<violation number="1" location="lib/context/contextOperationSchema.ts:17">
P2: Custom agent: **Enforce Clear Code Style and Maintainability Practices**

`contextOperationSchema.ts` is 180 lines, exceeding the guideline's under-100-line limit. Extract action groups into separate schema modules and compose them here.</violation>
</file>
Architecture diagram
sequenceDiagram
    participant CC as Contract Consumer
    participant BOC as buildContextOperationCatalog
    participant COS as contextOperationSchema
    participant PCO as processContextOperation
    participant PO as Process Operations
    participant AO as authorizeContextOwner
    participant RPC as RPC/Dispatch
    
    Note over CC,BOC: Contract-only consumers (no execution deps)
    CC->>BOC: get request schemas
    BOC->>COS: import schema
    COS-->>BOC: validation schema
    BOC-->>CC: request catalog
    
    Note over PCO,PO: Execution path (isolated from contracts)
    PCO->>COS: import schema
    PCO->>PO: dispatch operations
    PO->>AO: authorize owner
    AO-->>PO: context
    PO->>RPC: rpc/dispatch calls
    
    Note over PCO,RPC: NEW: Boundary enforced - contracts no longer load execution services
    
    alt HTTP API path
        CC->>PCO: POST /api/context
        PCO->>PO: process operation
    else MCP tool path
        CC->>PCO: handleContextToolOperation
        PCO->>PO: process operation
    end
    
    alt Abort handling (unified)
        PCO->>PCO: isAbortError (lib/errors)
        Note over PCO: Shared error policy across workflows
    end
Loading

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

normalizeCatalogPlanningModule,
} from "./normalizeCatalogPlanningModule";
import { normalizeCatalogPlanningModule } from "./normalizeCatalogPlanningModule";
import { contextOperationSchema } from "./contextOperationSchema";

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: Custom agent: Enforce Clear Code Style and Maintainability Practices

processContextOperation.ts remains 407 lines, well above the rule’s under-100-line limit; split the remaining action dispatch into cohesive modules.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At lib/context/processContextOperation.ts, line 15:

<comment>`processContextOperation.ts` remains 407 lines, well above the rule’s under-100-line limit; split the remaining action dispatch into cohesive modules.</comment>

<file context>
@@ -1,198 +1,19 @@
-  normalizeCatalogPlanningModule,
-} from "./normalizeCatalogPlanningModule";
+import { normalizeCatalogPlanningModule } from "./normalizeCatalogPlanningModule";
+import { contextOperationSchema } from "./contextOperationSchema";
 
-const briefFields = {
</file context>

@@ -0,0 +1,180 @@
import { z } from "zod";

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: Custom agent: Enforce Clear Code Style and Maintainability Practices

contextOperationSchema.ts is 180 lines, exceeding the guideline's under-100-line limit. Extract action groups into separate schema modules and compose them here.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At lib/context/contextOperationSchema.ts, line 17:

<comment>`contextOperationSchema.ts` is 180 lines, exceeding the guideline's under-100-line limit. Extract action groups into separate schema modules and compose them here.</comment>

<file context>
@@ -0,0 +1,180 @@
+  max_characters: z.number().int().min(1000).max(32000).default(12000),
+};
+
+export const contextOperationSchema = z.discriminatedUnion("action", [
+  ...catalogCaseOperationSchemas,
+  ...evidenceAttachmentOperationSchemas,
</file context>

This branch was successfully deployed

1 active deployment
Preview — beacfbd3 Deployed Nov 9, 2026 by vercel[bot]
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