Repository navigation
🐛 Add retry to create-rollback cleanup to context-service - #603
Conversation
Signed-off-by: Evaline Ju <[email protected]>
Signed-off-by: Evaline Ju <[email protected]>
Signed-off-by: Evaline Ju <[email protected]>
Signed-off-by: Evaline Ju <[email protected]>
ingpaolodettori-dev
left a comment
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
| | `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` | |
There was a problem hiding this comment.
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.
| | `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 | |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
Signed-off-by: Evaline Ju <[email protected]>
ingpaolodettori-dev
left a comment
There was a problem hiding this comment.
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.
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
git commit -s).make lintand the tests for the touched packages pass.docs/page, with the right maturity label (seedocs/CONTRIBUTING-DOCS.md).make check-linkspasses if any Markdown changed.docs/specs/README.mdordocs/adrs/README.md- N/A