Skip to content

Commit 34c2d81

Browse files
jirispilkaclaude
andauthored
docs: Add July 2026 refactoring sweep results (#1068)
Document the full-codebase sweep conducted on 2026-07-08, capturing defects and refactoring opportunities across src, tests, tooling, and configs. ## Changes - **Added `res/refactoring-sweep-2026-07.md`**: Comprehensive sweep results including: - Three filed issues (#1064, #1065, #1066) with defects and quick wins - Umbrella issue #658 tracking sync/task tool-call dispatch dedup - Unfiled M/L backlog items: `types.ts` split, payment seam closure, `RunResponse` assembly dedup, `call_actor.ts` core extraction, `actor_run_response.ts` split, `internals.js` export narrowing, server-mode lifecycle encapsulation, `pricing_info.ts` formatter consolidation, test import time analysis, and smaller items - "Checked and healthy" section confirming no action needed on design decisions - **Updated `res/index.md`**: Added reference to the new sweep document with brief summary and guidance to pull from backlog instead of re-sweeping. ## Notes Line numbers in the sweep are as of 2026-07-08 and should be verified before use. The document is a planning artifact for future refactoring work, not a change to production code. https://claude.ai/code/session_01SxD2vVDBSJEJWVbsmhN82w Co-authored-by: Claude <noreply@anthropic.com>
1 parent ce264a5 commit 34c2d81

2 files changed

Lines changed: 123 additions & 0 deletions

File tree

res/index.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ PR-by-PR breakdown of the audit above. Live plan (#777); sub-issues #750–#754,
4646
Checklist and notes for ChatGPT MCP Apps store submission. In progress — verify line
4747
references against current source before relying on them.
4848

49+
### [refactoring-sweep-2026-07.md](./refactoring-sweep-2026-07.md)
50+
Full-codebase sweep results: defects and refactorings filed as #1064/#1065/#1066, plus the
51+
unfiled M/L backlog (types.ts split, payment seam, `internals.js` narrowing, test import
52+
time). Pull from the backlog instead of re-sweeping.
53+
4954
### [web-widget-bundle-size.md](./web-widget-bundle-size.md)
5055
Keeping widget bundles small (narrow `@apify/ui-library/dist/src/...` imports, markdown stack
5156
cost). Re-measure when changing widget dependencies or markdown rendering.

res/refactoring-sweep-2026-07.md

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
# Refactoring sweep — July 2026
2+
3+
Full-codebase sweep (src, tests, tooling, configs) for defects and refactoring
4+
opportunities. Line numbers are as of 2026-07-08 — verify before use.
5+
6+
Filed as issues (do not duplicate here):
7+
8+
- **#1064** — defects: helper-tool `inputSchema` required/default bug, `smithery.yaml`
9+
broken entry path, Node-floor drift, payment-client bypass, hardcoded store URL.
10+
- **#1065**`defineHelperTool` factory + `mockApifyClient()` + context-stub merge.
11+
- **#1066** — quick wins: `getTaskOrThrow`, loader mode-gate dedup, `resolveWidgets`
12+
memoization, `catchNotFound`, search-actors strings, `injectMcpSessionId`, widget
13+
boolean split, dead Python tooling, vitest timeout split.
14+
- **#658** (umbrella) — sync/task tool-call dispatch dedup; sub-issues #1061, #684,
15+
#1062, #1063, #974.
16+
17+
## Backlog — not filed, pull when there's appetite
18+
19+
### `types.ts` split (M)
20+
21+
746 lines mixing six concerns. Move types next to their owners (pattern already used by
22+
`WidgetActor` in `actor_card.ts`, `PricingTier` in `pricing_info.ts`): telemetry types
23+
(`ToolCallTelemetryProperties`, `CallDiagnostics`, `AjvErrorDetails`) → beside
24+
`tool_status.ts`/`telemetry.ts`; `StructuredActorCard`/`ActorCardOptions`/
25+
`ConsoleLinkContext``actor_card.ts`/`console_link.ts`; `ServerCard`
26+
`server_card.ts`. Keep the tool model (`ToolBase`, `ToolEntry`, `TOOL_TYPE`) + `Input` as
27+
the lean core. Do as pure moves + re-exports first. Also: `types.ts` holds runtime values
28+
(`TOOL_TYPE`, `SERVER_MODE`) despite the name.
29+
30+
### Payment seam closure (M) — sequence after #1062
31+
32+
`PAYMENT_REQUIRED_HEADER` + its base64→JSON decode exist twice (`payments/x402.ts` and
33+
`utils/payment_errors.ts`); `server.ts` branches on `isX402PaymentRequiredError` directly
34+
in both catch blocks instead of the provider owning its error path; `prepareToolCallContext`
35+
(`payments/helpers.ts`) carries a split-me TODO and registers the x402 axios interceptor
36+
for every client regardless of provider. Fix: unify header consts/decode in
37+
`payments/const.ts`; add a `buildPaymentRequiredResult(error)` hook to `PaymentProvider`
38+
so a third provider needs no `server.ts` edits. The catch blocks are exactly what #1062's
39+
`mapToolCallError` extracts — do this as its follow-up, not in parallel.
40+
41+
### `RunResponse` assembly dedup (S/M)
42+
43+
The canonical structuredContent + `respondOk` mirror is hand-assembled in
44+
`buildStartRunResponse`, `fetchActorRunData`, and re-implemented (~20 lines) in
45+
`abort_actor_run.ts`. Extract `buildRunResponseContent(run, storages)` +
46+
`respondRunResponse(...)` so abort stops drifting from get-actor-run.
47+
48+
### `call_actor.ts` core extraction (M)
49+
50+
Lines 47–543 are helpers exported mainly for `widgets/call_actor_widget.ts`
51+
(`callActorPreExecute`, `resolveAndValidateActor`, `buildCallActorErrorResponse`,
52+
`callOptionsSchema`); the tool entry itself is ~30 lines at the tail. Move the shared
53+
engine to `actors/call_actor_core.ts`; the widget then depends on an explicit core module
54+
instead of reaching into a sibling tool file.
55+
56+
### `actor_run_response.ts` split (M/L)
57+
58+
875 lines, four banner-separated jobs: field normalization + response types;
59+
status→summary/nextStep templates (~210 lines, the most-edited part); storage
60+
fetch/enrichment; wait/orchestration (`raceAbort`, `waitForRunWithProgress`). Mechanical
61+
4-file split; watch storage tools importing `normalizeDatasetFields`.
62+
63+
### `internals.js` export narrowing (M/L, cross-repo)
64+
65+
`index_internals.ts` exports raw tool-catalog functions the hosted repo consumes directly
66+
(`getDefaultTools`, `getCategoryTools`, `getActorsAsTools`, `processParamsGetTools`,
67+
`getToolPublicFieldOnly`, …) against the stated "expose methods on `ActorsMcpServer`"
68+
policy, plus deprecated aliases awaiting internal migration (`addActor as addTool`,
69+
`redactSkyfirePayId` — see #604, `HelperTools`). Convert one export at a time to a server
70+
method; needs internal-repo coordination per export.
71+
72+
### Server-mode lifecycle encapsulation (M)
73+
74+
One lifecycle ("auto → resolved on initialize, buffer tool loads until then") tracked by
75+
five mutable fields (`serverModeOption`, `serverMode`, `serverModeResolved`,
76+
`pendingToolsAfterModeResolved`, `clientSupportsUi`) mutated from four places; invariants
77+
comment-enforced. Extract a `ServerModeResolver` owning option/resolved/buffer. Land the
78+
#1066 loader-dedup first — it shrinks this.
79+
80+
### `pricing_info.ts` formatter consolidation (M, deliberately deprioritized)
81+
82+
Five pricing models × (complete|simplified) × (text|structured) run in near-parallel
83+
function pairs; tier logic re-walked four ways. Fix: one resolved intermediate per model,
84+
thin renderers on top. Well-tested and correctness-sensitive (see
85+
`pricing_output_contract.md`) — risk offsets payoff; only touch with the E1–E8 oracle
86+
green.
87+
88+
### Test import time (M, measure first)
89+
90+
`test:unit`: 7s running tests, ~30s importing modules (vitest transform+import stats).
91+
Likely heavy barrel imports (`tools/index.js`, server construction) pulled by most of the
92+
72 files. Measure the dep graph before changing anything; do NOT blindly flip
93+
`isolate: false` — the suite leans on `vi.mock`.
94+
95+
### Smaller items
96+
97+
- **Evals type-check policy**: CI type-checks only `src`+`tests`; standalone eval scripts
98+
(`run_evaluation.ts`, `create_dataset.ts`, `eval_single.ts`) are never compiled, and
99+
oxlint ignores `evals/*.ts` but lints `evals/*/**.ts`. Pick one policy for the tree.
100+
- **Log field vocabulary**: `statusCode` vs `failureHttpStatus` vs `failure_http_status`
101+
for the same concept; mixed `[HandlerName]` tag conventions. Standardize when it next
102+
bites an alert query.
103+
- **Web mock typing**: `MOCK_ACTOR_DETAILS_RESPONSE` (`web/src/utils/mock-actor-details.ts`)
104+
is an untyped literal with fields absent from the `Actor` type it mocks; annotate it so
105+
drift becomes a type error. Longer term, generate `web/src/types.ts` from server schemas.
106+
- **`TTLLRUCache.set()`** does a redundant get-then-remove before add; module-global cache
107+
singletons in `state.ts` have no reset hook (stale ~30 min across hot-reloads).
108+
- **`structured_output_schemas.ts`**: `apifyConsoleUrl` property object hand-written 4×,
109+
`userTier` enum 3× — extract consts (or fold into the #1065 factory work).
110+
111+
## Checked and healthy — no action
112+
113+
- Zod+AJV double validation is consistent by design (every tool compiles the same schema).
114+
- `legacyToolNameToNew` shim is small, documented, load-bearing.
115+
- content/structuredContent mirroring is intentional for mixed MCP clients.
116+
- Lint suppressions are not piling up (16 across 9 files, scattered).
117+
- `scripts/` (check-agents-links, check_widgets, dev_standby) are solid.
118+
- `evals/workflows` TS code is live and unit-tested (unlike the Python side — #1066).

0 commit comments

Comments
 (0)