Skip to content

🐛 Add retry to create-rollback cleanup to context-service - #603

Merged
evaline-ju merged 5 commits into
rossoctl:mainfrom
evaline-ju:quota-leak-fix
Oct 23, 2026
Merged

evaline-ju merged 5 commits into
rossoctl:mainfrom
evaline-ju:quota-leak-fix

Conversation

@evaline-ju

@evaline-ju evaline-ju commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Add a bounded retry on the create-rollback's cleanup call to Context Service when the connection fails. If Context Service becomes briefly unreachable during a failed create, the record no longer gets stuck in deleting with its per-user quota slot held. The rollback's cleanup succeeds on a retry, the record transitions to deleted, and the slot is freed.

Addresses (within retry window) part of #601

Assisted-By: Claude (Anthropic AI) [email protected]

Checklist

  • Commits are signed off (git commit -s).
  • make lint and the tests for the touched packages pass.
  • Docs: changed behavior, flags or environment variables are reflected in the relevant README or
    docs/ page, with the right maturity label (see docs/CONTRIBUTING-DOCS.md).
  • Docs: make check-links passes if any Markdown changed.
  • A new spec or ADR is registered in docs/specs/README.md or docs/adrs/README.md - N/A

@evaline-ju
evaline-ju requested a review from pdettori as a code owner October 23, 2026 18:41
Signed-off-by: Evaline Ju <[email protected]>
@evaline-ju evaline-ju added the ready-for-ai-review Request automated AI code review from clawgenti label Oct 23, 2026

@ingpaolodettori-dev ingpaolodettori-dev 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.

Bounded retry on the create-rollback's deleteContext while Context Service is unreachable looks correct. Only transport failures (no HTTP status) are retried. deleteContext already accepts 404, so retrying after a timed-out-but-executed DELETE is idempotent. The record/quota transition is unchanged: deleted + quota freed on success, deleting + quota held on a sustained outage, and the owner's DELETE still finishes the cleanup. Both paths are tested. No blocking issues. The inline comments are about making the "unreachable" classification explicit before the helper gets reused, and the attempts-vs-retries wording in the docs.

Author: evaline-ju (MEMBER — maintainer)
Areas reviewed: TypeScript (knative-server context-service/workloads), tests, Docs
Agent/IDE config (.claude/.vscode): none
Commits: 4 commits, all signed-off: yes
CI status: passing (all 16 checks green)

}

/** True when the Context Service call never got a response (vs got an error response). */
isUnreachable(): boolean {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion — isUnreachable() infers "no HTTP response" from status === undefined, but ContextServiceError is also thrown without a status for replies Moca did get and rejected: 'Context Service returned an invalid Context' (L175), '… invalid upload grant' (L233), '… invalid bundle content type', '… bundle stream failed', '… exceeds MOCA_CONTEXT_BUNDLE_MAX_BYTES', etc. For deleteContext that can't happen (it only goes through request(), which sets status on every answered error), so this PR's behavior is correct. But retryWhileUnreachable is exported with a generic contract ("no HTTP response ever arrived"), and the next caller that wraps e.g. createContext or a bundle export would retry semantic failures. Consider making it explicit: e.g. a readonly unreachable = false ctor flag (or a ContextServiceUnreachableError subclass) set only in request()'s fetch().catch, and have isUnreachable() read that.

Comment thread docs/context-service.md Outdated
| `MOCA_CONTEXT_MAX_STORAGE_GIB` | Largest `workspace.size`, default `10` |
| `MOCA_CONTEXT_STORAGE_CLASSES` | Comma-separated StorageClasses a caller may name; empty allows none |
| `MOCA_WORKLOAD_DELETED_TTL_SECONDS` | How long `GET` still reports a deleted workload, default `86400` |
| `MOCA_CONTEXT_ROLLBACK_RETRY_ATTEMPTS` | Retries of the create-rollback's Context Service cleanup while it is unreachable, default `3` |

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion — The name and docs say retries, but the code treats the value as total attempts: with the default 3, deleteContext runs 3 times (1 + 2 retries), and 1 means no retry at all. Please align the wording (e.g. "Attempts at the create-rollback's Context Service cleanup, including the first, default 3") here and in docs/reference/configuration.md:143. Also worth one clause: each attempt can take up to CONTEXT_SERVICE_TIMEOUT_MS, and the rollback runs before the 502 is sent. So when Context Service is black-holed rather than refusing connections, a failed create now takes about 5 s + 3×5 s + 2×0.5 s ≈ 21 s to answer by default, versus about 10 s before.

Comment thread docs/reference/configuration.md Outdated
| `MOCA_CONTEXT_MAX_STORAGE_GIB` | `10` | |
| `MOCA_CONTEXT_MAX_WORKLOADS_PER_OWNER` | `5` | |
| `MOCA_WORKLOAD_DELETED_TTL_SECONDS` | `86400` | TTL of the deleted-workload record |
| `MOCA_CONTEXT_ROLLBACK_RETRY_ATTEMPTS` | `3` | Create-rollback cleanup retries while Context Service is unreachable |

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit — Same "retries" vs total-attempts mismatch as in docs/context-service.md:267.

vi.stubEnv('MOCA_CONTEXT_ROLLBACK_RETRY_ATTEMPTS', '3');
vi.stubEnv('MOCA_CONTEXT_ROLLBACK_RETRY_BACKOFF_MS', '10');
cs.failures.set('grant', 500);
cs.unreachable.set('delete', 10); // more unreachables than retries: outage outlasts the budget

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit — Neither new test pins the retry budget. Here, after the 502 you could assert cs.unreachable.get('delete') is 7 (exactly 3 attempts consumed), so an off-by-one in the loop or a regression to "attempts + 1" would be caught. The current assertions pass for any attempt count below 10.

@ingpaolodettori-dev ingpaolodettori-dev 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.

Thanks — 1e3f480 addresses all four points from the previous round: the explicit unreachable flag set only in request()'s fetch-catch, the attempts-vs-retries wording (plus the worst-case latency note) in both docs, and the pinned DELETE count in both rollback tests. LGTM.

@evaline-ju
evaline-ju merged commit b09b6ab into rossoctl:main Oct 23, 2026
15 checks passed
@evaline-ju
evaline-ju deleted the quota-leak-fix branch October 23, 2026 19:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-ai-review Request automated AI code review from clawgenti

Projects

None yet

Development

Successfully merging this pull request may close these issues.

workloads create: failed rollback leaks per-user quota when Context Service is unavailable

2 participants