When implementing API-facing features, ensure request/response contracts are consistent across all code paths, correctly shaped for the upstream/downstream API, and complete under pagination/time-windowing.

Rules: 1) Keep serialization/parsing round-trips structurally identical

2) Validate upstream API method signatures and data fields

3) Make state transitions scope-safe; don’t mix per-item windows with global cursor side effects

4) Ensure pagination/windowing is complete (no permanent omission)

Example patterns:

export function parseSessionId(pathname: string) { // Mirror writer: anchor to the last occurrence if writer used last-match logic. return pathname.match(/\/session\/([^/]+)\/?$/)?.[1]; }

// Test: expect(parseSessionId(buildSessionPathname(‘/app/session/’, ‘real-id’))) === ‘real-id’

- Avoid wrong-typed external calls by removing casts and using correct method signatures:
```ts
// Prefer typed signatures; do not do api.Issues.show(chatId, { issueIId: ... })
// If SDK says show(issueId, { projectId }), pass issueId as number and projectId as string.

Adopting these rules prevents silent drops, permanent omissions, and contract drift—common failure modes in API integration code.