ES-CodeGen: Ethical Code Generation
- ES-CodeGen is a framework for ethically managing code generation across all lifecycle stages, addressing legal, technical, and socio-environmental issues.
- It integrates comprehensive taxonomies and audit mechanisms to ensure accountability, data provenance, and high code quality from data collection to deployment.
- Empirical studies reveal trade-offs between code quality and ethical concerns, guiding practices in bias detection, licensing, and sustainable development.
Searching arXiv for the cited ES-CodeGen and supporting code-generation ethics papers. Ethically Sourced Code Generation (ES-CodeGen) is a framework for managing code generation model development and operation through ethical and sustainable practices across the full lifecycle, from data collection to post-deployment monitoring. The term was introduced to consolidate disparate concerns in AI-based code generation—including unclear licensing, privacy, fairness, accountability, labor conditions, environmental impact, and code quality—into a single supply-chain perspective (Xu et al., 26 Jul 2025). In this formulation, ES-CodeGen is not limited to training-data legality or output filtering. It encompasses process and artifact management practices for training data, dependencies, model metadata, documentation, prompt templates, and generated outputs, with attention to subject rights, intellectual property, social justice, environmental sustainability, and software-centric quality constraints (Xu et al., 26 Jul 2025). Research on auditability and bias in programming language generation (PLG) provides concrete mechanisms relevant to this agenda, particularly CodeForensic’s end-to-end auditing pipeline and empirical studies of social bias in generated code (Ma et al., 2023, Liu et al., 2023).
1. Conceptualization and scope
ES-CodeGen was defined in 2025 as an extension of “ethical sourcing” from supply-chain management to AI-driven code generation systems (Xu et al., 26 Jul 2025). The concept is explicitly lifecycle-wide: it covers raw data ingestion, annotation, cleaning and preprocessing, training and fine-tuning, evaluation, deployment, and post-deployment monitoring. Its defining premise is that ethical sourcing for code generation must address both processes and artifacts, rather than only the final model or output (Xu et al., 26 Jul 2025).
A central feature of the ES-CodeGen formulation is its contrast with adjacent generative AI domains. Speech synthesis is characterized in the source literature as focusing on voice-donor consent, identity protection, and voice ownership, while image generation is described as emphasizing legal training-source curation and license safety. ES-CodeGen is presented as broader because it is software-centric, covers software supply-chain artifacts, adds technical dimensions such as code quality, and adopts a “triple bottom line” orientation in a software context (Xu et al., 26 Jul 2025). This suggests that code generation poses a distinctive combination of legal, technical, and socio-environmental issues: generated code is simultaneously a creative artifact, an executable engineering product, and a component in a software supply chain.
The empirical basis for the ES-CodeGen taxonomy combined a two-phase literature review and a practitioner survey. The review read 803 papers and identified 71 relevant papers. The survey included 32 practitioners, among them six developers who had submitted GitHub issues to opt out from the Stack dataset. The study reports that this mixed-method process refined an initial set of 10 dimensions into 11, adding code quality after practitioners emphasized its importance (Xu et al., 26 Jul 2025).
2. The eleven dimensions
The ES-CodeGen taxonomy groups 11 dimensions into three areas: Source, Society, and Environment (Xu et al., 26 Jul 2025). These dimensions are intended to apply across all supply-chain stages and artifacts.
| Area | Dimensions |
|---|---|
| Source | Subject Rights, Equity, Access, Accountability, IP Rights, Integrity, Code Quality |
| Society | Social Responsibility, Social Acceptability, Labor Rights |
| Environment | Environmental Sustainability |
Within the Source area, Subject Rights requires informed consent and privacy protection for human authors whose code appears in training corpora. The formal requirement is stated as $\forall s \in S, Consent_{(s)} \land Privacy_{(s)}$, with explicit preference among practitioners for opt-in over opt-out mechanisms (Xu et al., 26 Jul 2025). Equity concerns diversity, fairness, and representativeness in both training data and model performance, formalized as approximate parity in representation and performance across groups. Access addresses controlled access policies for resources such as model weights, datasets, and documentation. Accountability requires a tamper-evident trace function from data, model, and outputs to an audit log. IP Rights requires license compliance and generation distinctiveness, expressed as $LicenseCheck(L_i,o)=true \land Distinct(o,i)$ for each training input and output pair. Integrity concerns contamination control and provenance verification, including avoidance of recursive synthetic contamination. Code Quality adds software-specific requirements of accuracy, maintainability, and security, with a formal pass criterion based on test success rate (Xu et al., 26 Jul 2025).
Within the Society area, Social Responsibility requires positive or at least non-harmful net effects on affected communities. Social Acceptability concerns cultural and religious sensitivity in outputs. Labor Rights concerns wages, safe working conditions, and lawful employment for annotators and related workers (Xu et al., 26 Jul 2025).
The Environment area contains Environmental Sustainability, which constrains total carbon footprint for training and inference relative to a baseline, with subcomponents of energy consumption and emissions (Xu et al., 26 Jul 2025).
The taxonomy’s inclusion of code quality is particularly consequential. In the survey, 18.8% of open-ended responses introduced quality as a key dimension, and 12.5% cited low-quality code as a real-world harm. This positions software correctness and security not as secondary engineering concerns but as part of the ethical sourcing problem itself (Xu et al., 26 Jul 2025). A plausible implication is that, in code generation, harm can arise not only from how data were sourced or how workers were treated, but also from the operational properties of the generated artifact.
3. Supply-chain stages, artifacts, and governance logic
The ES-CodeGen study identifies seven supply-chain stages: data collection, annotation, cleaning and preprocessing, training and fine-tuning, evaluation, deployment, and post-deployment monitoring/inference (Xu et al., 26 Jul 2025). It also identifies six key artifacts: training data, dependencies, model metadata, documentation, prompt templates, and model outputs (Xu et al., 26 Jul 2025).
Participants in the study agreed that all dimensions apply across all stages and artifacts. The paper provides condensed mappings illustrating recurrent relevance, such as Subject Rights at collection and post-deployment, IP Rights at collection, training, evaluation, and deployment, Code Quality at training, evaluation, and post-deployment, and Environmental Sustainability at training. For artifacts, the mappings show, for example, Equity as relevant to data, documentation, prompts, and outputs, Integrity to data, and Code Quality especially to outputs (Xu et al., 26 Jul 2025).
This supply-chain framing differs from narrower compliance approaches. Rather than treating ethics as a single gate at model release, ES-CodeGen treats ethical risk as distributed across the entire pipeline. The consequences cataloged for “UnES-CodeGen” reinforce this interpretation. For model developers, the survey reports IP lawsuits (87.5%), privacy/security breaches (87.5%), harmful biased outputs (78.1%), environmental damage (78.1%), and loss of trust (71.9%). For end-users, it reports IP lawsuits (90.6%) and plagiarism claims (75%). The study also notes newly identified consequences including developer exploitation, low-quality code, AI monopolization, and harm to open-source software communities (Xu et al., 26 Jul 2025).
The governance logic is therefore multi-stakeholder. The recommendations include multi-stakeholder governance, scalable opt-in consent mechanisms, transparent SBOM/AIBOM-style disclosure, automated license and IP auditing, quality-gated deployment, social impact reporting, Green ML practices, and continuous monitoring with user feedback and opt-out flows (Xu et al., 26 Jul 2025). These recommendations connect the abstract taxonomy to operational controls.
4. Provenance, accountability, and forensic auditing
A major technical contribution relevant to ES-CodeGen is the holistic audit framework introduced by Ma et al. for PLG accountability, implemented as CodeForensic (Ma et al., 2023). The framework covers both model-development audits and deployment accountability. Its high-level pipeline has three components: training-usage audit through membership inference, neural-vs-human detection, and neural-code attribution, with the additional theoretical result that one-to-one attribution of a single snippet to a single model is infeasible in general (Ma et al., 2023).
For training-usage audit, the threat model assumes black-box or gray-box access to output probabilities or perplexities and asks whether a candidate snippet $x$ was in the target model’s training set. The method uses a likelihood ratio test with a target model $G_T$ and a reference model $G_R$. The paper defines the language-model joint probability and perplexity, then uses the log-likelihood-ratio statistic
$L(x)=\log \frac{Pr[x;G_R]}{Pr[x;G_T]}=\log \frac{PPL(x;G_T)}{PPL(x;G_R)}.$
The null hypothesis that $x$ is out-of-training is rejected when $L(x)<\tau$, with $\tau$ selected to control false positives (Ma et al., 2023). Reported results show that at $\mathrm{FPR}=5\%$, the true-positive rate exceeds 80% when a code-domain reference model such as InCoder is used on APPS and MBPP, and LRT-based audits outperform simple loss-based membership inference by more than 10 AUC points. A separate quantitative summary reports LRT-S AUC of 0.79–0.86 versus 0.55–0.70 for loss-only baselines (Ma et al., 2023).
For neural-code detection, the framework uses UniXcoder with a single linear layer and softmax as a binary classifier distinguishing human-written from neural code. Training uses standard cross-entropy on generated and human reference solutions from HumanEval, MBPP, and APPS. Reported performance is near perfect in-domain, with $LicenseCheck(L_i,o)=true \land Distinct(o,i)$0, and remains high in cross-model and cross-dataset settings at 0.85–0.98 and greater than 80%, respectively. The study further reports that generic text detectors plateau near random chance, indicating that code-specific pretraining is critical (Ma et al., 2023).
For attribution, the paper formalizes the single-snippet case as a single-instance goodness-of-fit problem and adapts a theorem implying that no test $LicenseCheck(L_i,o)=true \land Distinct(o,i)$1 can achieve power greater than $LicenseCheck(L_i,o)=true \land Distinct(o,i)$2 against all alternatives without knowing the alternative distribution. In the worst case, single-snippet one-to-one attribution reduces to random guessing (Ma et al., 2023). This negative result is methodologically important for ES-CodeGen because it limits what can be claimed about provenance from isolated outputs.
The paper therefore proposes two feasible alternatives. Attribution classification treats the problem as multiclass prediction among $LicenseCheck(L_i,o)=true \land Distinct(o,i)$3 candidate PLG models using UniXcoder and a $LicenseCheck(L_i,o)=true \land Distinct(o,i)$4-way linear head. Reported empirical performance includes 87–99% mono-lingual accuracy, about 93% multi-lingual accuracy across eight languages, generalization across prompt distributions at about 92%, and the ability to distinguish CodeGen-Mono variants of different parameter scales at about 84% accuracy (Ma et al., 2023). Attribution verification tests whether a set of snippets $LicenseCheck(L_i,o)=true \land Distinct(o,i)$5 comes from a suspect model using unbiased Maximum Mean Discrepancy in UniXcoder embedding space with a Gaussian kernel and a permutation test for significance. The paper states an asymptotic guarantee that power approaches 1 as $LicenseCheck(L_i,o)=true \land Distinct(o,i)$6 grows under the alternative, and empirically reports that with about 20–30 suspicious snippets, $LicenseCheck(L_i,o)=true \land Distinct(o,i)$7 reaches 80–100% across models and languages; a summary result notes that with $LicenseCheck(L_i,o)=true \land Distinct(o,i)$8, TPR approaches 95–100% at 5% FPR (Ma et al., 2023).
These mechanisms directly instantiate the Accountability and IP Rights dimensions of ES-CodeGen. The same paper describes a deployment pattern in which each generation call is routed through membership audit, neural detection, attribution classification, and periodic attribution verification on accumulated logs. CodeForensic exposes these as Python APIs and CLI tools, with modules such as core/audit.py, core/detect.py, core/attrib_classify.py, and core/attrib_verify.py, and provides JSON-RPC endpoints for integration into CI/CD pipelines or IDE plugins (Ma et al., 2023). This suggests a concrete operational interpretation of the tamper-evident trace function required by the ES-CodeGen accountability dimension.
5. Fairness, representational harms, and social acceptability
Social bias in code generation is an explicit concern within ES-CodeGen’s Equity and Social Acceptability dimensions, and it has been empirically studied using prompt-based probes and quantitative metrics (Xu et al., 26 Jul 2025, Liu et al., 2023). The study by Wang et al. develops a prompt-construction paradigm designed to elicit demographic associations in generated code. Each prompt contains two dummy functions over inanimate data and a third incomplete function signature of the form def find_ADJ_people(people, HumanAttribute):, where ADJ is a judgmental modifier and HumanAttribute belongs to one of eight demographic dimensions: ethnicity, religion, gender, sexuality, disability, age, politics, and occupation (Liu et al., 2023).
The dataset comprises 49 modifiers across eight dimensions, yielding 392 prompts. For each prompt, 10 completions are generated per model, resulting in 3,920 snippets per model. Human annotation was performed by three computer science postgraduates, who labeled snippets as “biased” or “acceptable.” The paper reports approximately 8,900 annotated snippets for human evaluation and 5,488 for classifier training, with a 70/20/10 split on pooled InCoder and CodeGen data (Liu et al., 2023).
To quantify bias, the paper defines three metrics using a binary code-bias classifier based on BERT-Base with 95% held-out accuracy. The Code Bias Score (CBS) is the fraction of generated snippets flagged as biased. The UnFairness Score (UFS) is a normalized directional gap between two focal demographics for a given dimension. The standard deviation $LicenseCheck(L_i,o)=true \land Distinct(o,i)$9 across valid demographics measures dispersion of biased targeting across groups (Liu et al., 2023). These metrics allow both overall and fine-grained analysis.
The reported results indicate severe social biases in the evaluated models. The paper presents overall CBS values of 23.52 for InCoder 1.3B, 32.55 for InCoder 6.7B, 9.36 for CodeGen 350M, 45.15 for CodeGen 2.7B, 62.65 for CodeGen 6.1B, and 82.64 for Codex code-davinci-002. For InCoder 6.7B, fine-grained UFS and $x$0 analyses reveal large unfairness in dimensions such as Gender and Ethnicity and high dispersion, including approximately 50% $x$1 in Gender for RoBERTa-Neg prompts (Liu et al., 2023). Human evaluation closely tracks automatic CBS, with Pearson correlation approximately 0.96 (Liu et al., 2023).
The study also reports a quality-bias trade-off: larger models and code-davinci-002 show stronger code quality, with Pass@1 up to about 47% and Pass@100 about 92%, but also the worst CBS, exceeding 80%. By contrast, CodeGen 350M has the lowest overall CBS, about 9%, albeit with weaker code quality (Liu et al., 2023). Hyperparameter analyses indicate that CBS peaks around temperature 0.3–0.5 and around top-$x$2, while larger randomness beyond 0.6 temperature can reduce bias by diluting strong demographic associations (Liu et al., 2023).
Within an ES-CodeGen frame, these findings operationalize Equity and Social Acceptability. They also complicate simplistic assumptions that better-performing or larger models are necessarily ethically preferable. A plausible implication is that ethical sourcing in code generation cannot be reduced to data provenance alone; output behavior under realistic prompting and decoding regimes must also be evaluated continuously.
6. Operationalization in practice
The ES-CodeGen literature makes explicit recommendations for deployment and governance, while the auditing and bias papers provide candidate mechanisms for implementation (Xu et al., 26 Jul 2025, Ma et al., 2023, Liu et al., 2023). A practical ES-CodeGen workflow can therefore be understood as a layered control architecture spanning data, model, output, and organizational process.
At the data and training stages, opt-in or at least robust opt-out consent mechanisms, privacy screening, provenance verification, contamination control, and automated license detection align with Subject Rights, Integrity, and IP Rights (Xu et al., 26 Jul 2025). The CodeForensic membership-inference module provides one audit mechanism for suspected training-data inclusion and is specifically motivated by concerns over licensed or copyrighted code in training sets (Ma et al., 2023).
At the evaluation and deployment stages, code-quality gates, security tests, fairness probes, and provenance logging align with Code Quality, Equity, Accountability, and Social Acceptability (Xu et al., 26 Jul 2025). The social-bias paper recommends embedding a code-bias classifier in the generation loop, integrating CBS, UFS, and $x$3 into monitoring dashboards, and using the 392-prompt suite as a regression test for new models (Liu et al., 2023). The same source also recommends prompt-level safeguards, model and sampling choices tuned for fairness, anti-stereotype data augmentation, and routing flagged outputs to a human reviewer or automated policy engine (Liu et al., 2023).
At post-deployment, continuous monitoring becomes central. The ES-CodeGen study recommends runtime audits such as privacy scanners and bias detectors, together with user opt-out flows and social impact reporting (Xu et al., 26 Jul 2025). CodeForensic’s deployment pattern—membership audit, neural detection, attribution classification, and periodic set-level verification—provides a concrete instantiation of continuous provenance monitoring (Ma et al., 2023). Because single-snippet attribution is theoretically unreliable in the worst case, post-deployment monitoring benefits from aggregating logs and applying set-level statistical verification rather than overclaiming certainty about individual outputs (Ma et al., 2023).
The literature also emphasizes documentation and disclosure. Recommended artifacts include Code-Bill-of-Materials-style reporting of data sources, licenses, dependencies, and compute footprints, along with model cards or “Model Social Cards” describing community benefits, labor practices, and fair-wage policies (Xu et al., 26 Jul 2025). This supports the Access and Accountability dimensions by making resource policies and process choices inspectable.
7. Debates, limitations, and research directions
Several tensions recur across the literature. One is the trade-off between openness and controlled access. ES-CodeGen includes Access as a dimension precisely because public release of weights, data, and documentation may aid transparency and scientific scrutiny, yet unrestricted access may create confidentiality or misuse risks (Xu et al., 26 Jul 2025). Another is the trade-off between code quality and other ethical goals. The social-bias study reports that larger models with stronger HumanEval performance can exhibit substantially worse CBS, which indicates that optimization for programming benchmarks does not guarantee equitable behavior (Liu et al., 2023).
A further debate concerns consent mechanisms. Although datasets such as The Stack v2 are described as allowing opt-out, practitioners in the ES-CodeGen survey, especially impacted users, strongly prefer opt-in over opt-out (Xu et al., 26 Jul 2025). This distinction matters because the Subject Rights dimension is not merely about formal removability but about the prior legitimacy of inclusion. Similarly, the IP Rights dimension is not exhausted by avoiding verbatim memorization; it also includes source acknowledgement, license compliance, and distinctiveness requirements (Xu et al., 26 Jul 2025).
Theoretical limitations also shape the field. The impossibility result for single-snippet attribution means that provenance claims must be calibrated carefully. Overstating certainty about the origin of an isolated code snippet would conflict with the Accountability dimension’s emphasis on traceability grounded in valid evidence (Ma et al., 2023). This result encourages a shift from deterministic provenance assertions toward probabilistic classification and set-level verification.
The ES-CodeGen survey additionally reports an important sociotechnical blind spot: before reflection, 56.3% of respondents ignored Social Acceptability, and 46.9% ignored Social Responsibility and Labor Rights; after reflection, more than 80% rated these as moderately or very relevant (Xu et al., 26 Jul 2025). This suggests that current practice may overemphasize legal and technical issues while underweighting community impact, worker treatment, and culturally situated harms. The taxonomy’s inclusion of these dimensions is therefore corrective rather than merely descriptive.
Research directions implied by the existing literature include scalable opt-in workflows, stronger privacy and license audits, anti-bias evaluation suites integrated with code-generation benchmarks, environmental accounting for both training and inference, and formal interfaces for audit logs and supply-chain metadata (Xu et al., 26 Jul 2025). The combined body of work indicates that ES-CodeGen is not a single algorithmic solution but an organizing framework for aligning provenance, fairness, quality, accountability, and sustainability in code generation systems.