gortex icon indicating copy to clipboard operation
gortex copied to clipboard

contracts: an unscoped request never completes on a large multi-workspace install while any repository is being edited

Open britishbadger opened this issue 2 weeks ago • 0 comments

Summary

On a large workspace, an unscoped contracts request (/v1/contracts, or analyze contracts with no workspace) never completes while any one repository is being edited. Every target's attachment key is composed over the input witnesses of every tracked repository, so one contract-relevant edit anywhere supersedes the whole job.

unscoped request -> one ContractActor over all N repos
  key(target) = H(witness(repo_1) ... witness(repo_N))
  convergence scan: inputs.Validate over all N  -> !Settled -> errContractJobKeyMoved

The matcher already pairs contracts only inside one EffectiveWorkspace (contracts/contract.go), so repositories in different workspaces cannot change each other's matches. They are coupled only through the job's key, plus a few name lookups described below.

Observed

The run used a copy of a real store: about 120 repositories in 9 effective workspaces, and about 160k contract paths. One repository with no configured workspace was under active development, with a contract-relevant edit about every 6 minutes (median).

  • A cold fill of the whole cohort needs about 4,000 s or more.
  • In 2 h 10 min: 4 jobs, 0 published (3 superseded_key_moved, 1 preempted at shutdown).
  • The aborts come from the convergence scans' !Settled checks, not backgroundCurrent. That one only runs after an early publish, and nothing published.
  • The proven-unit checkpoint was 0.75 to 2.4 GB, above the 512 MiB contractDeltaCacheMaxBudget, so every retry was cold.
  • With no published cohort there is no predecessor to serve, so every request returned 500 required_capability_incomplete.

Cross-workspace reads in today's attachment

Before proposing a split I checked what an unscoped attachment reads outside its own workspace. Every case is a name-only fallback that takes a match from any repository in the cohort:

  • upgradeContractBareTypeRefs and upgradeBareTypeNames: a bare request_type or response_type such as User with no same-repo type resolves to another repository's type, including one in another workspace.
  • Handler resolution (resolveProviderHandlers / pickHandlerCandidate), envelope bare types in attachInlinedShapes, and the TS/Rust import disambiguation have the same kind of fallback.
  • Contract node rows for an ID that two workspaces share come from the first record across the whole cohort.

A workspace-scoped request already resolves all of these within its workspace, because its cohort is that workspace. So the unscoped and workspace-scoped answers can differ today.

Proposal

  1. Bound those fallbacks to the contract's effective workspace, the same rule as the matcher and as workspace-scoped requests. Same-repo preference is unchanged.
  2. Split an unscoped request into one actor per effective workspace.
    • The answer is fresh when every group is fresh.
    • It is served (fresh:false) when every group has a current view or a served predecessor.
    • A request that resolves to one group keeps today's actor and key, byte for byte.
  3. Count the sibling actors of one split as one admission unit against QueueCapacity and the actor bound, and evict them as a unit.
  4. Small related fix: backgroundCurrent aborts on a.want.seq > want.seq alone. Comparing the keys avoids aborting when the newer want has the same key.

Point 1 changes published results wherever a namesake in another workspace was picked before. That is why I'd like your view on the direction before opening a PR.

I have an implementation with tests on britishbadger:fix/contract-cohort-per-workspace. I ran it on the same store copy, with the same repository being edited throughout.

  • Every workspace group published. Small groups took 1 to 80 s and the largest (81 repositories) 260 to 420 s per pass.
  • The unscoped request returned fresh:true, state:complete 73 minutes after a cold start.
  • Most of that time went on groups re-running as their repositories finished warming up after the restart. That is a separate, smaller issue.
  • Before the change, nothing had published after 2 h 10 min.

Environment

  • Built from main at 5d832ba72.
  • About 120 repositories, 4 named workspaces and 5 repositories with no workspace.

Related: misleading error from the predecessor fallback

When an actor has no published cohort, openContractPredecessorBinding falls back to OpenPreviousContractCohort. That fallback only recovers when exactly one input slot is unpublished (contract_previous_cohort.go:69-70). With several moved repositories, which is the normal state for a large cohort that has never published, it returns ErrContractProjectionIncomplete, whose text is "contract projection owner source missing". The request's error then names an owner source problem that isn't there. Wrapping it with the actual reason, for example %w: N inputs moved since the last published cohort, would keep errors.Is working and make the error diagnosable.

britishbadger avatar Nov 15 '26 14:11 britishbadger