Code Lifespan Survival Analysis (CLSA): Predicting the Survival of Source Code Lines Using AST-Aware Mining

summary

The gist

Line-level survival modeling is tractable and yields interpretable, largely statically-computable risk signals (from AST structure and lexical features) for software evolution The Kaplan–Meier…

In short

This research introduces Code Lifespan Survival Analysis (CLSA) to model individual source line deletion risk using structural and contextual features from code. It uses a rigorous 5-stage matching pipeline to filter out noise, finding that repository identity is the strongest predictor of line survival, while specific structural elements like 'in_function' offer stable protection.

Key concepts

Code Lifespan Survival Analysis (CLSA)
A framework designed to predict how long an individual line of source code will persist. It treats each line as a subject in a survival study, estimating its deletion risk based on its structure, context, and when it appears in the codebase.
Change Topologies
The paper categorizes code changes into three types: migrations (lines moved), modifications (semantically rewritten lines), and true deaths (permanent deletions). This classification helps accurately distinguish real line deletions from refactoring noise during data mining.
Repository Frailty Model
This statistical model accounts for the inherent differences between different software repositories. It estimates a variance ($ heta = 1.451$) that captures how much a specific repository's history influences line survival, showing that repository identity is the primary driver of long-term prediction accuracy.

Terminology used across episodes

This episode discusses

The paper

Code Lifespan Survival Analysis (CLSA): Predicting the Survival of Source Code Lines Using AST-Aware Mining · Read on arXiv

DOI: 10.5281/zenodo.20714794

Transcript

Introduction to the show: ident: Computer Science. The day in computer science: software, systems and theory on arXiv.

Tom: We're looking at the paper: "Code Lifespan Survival Analysis (CLSA)".

Jane: Here's the gist of the paper. Line-level survival modeling is tractable and yields interpretable, largely statically-computable risk signals (from AST structure and lexical features) for software evolution The Kaplan–Meier median survival time is 1,335–1,352 days (about 3.7 years, consistent across the analytical sample, the full 32.5-million-line population, and an independent resample) The clearest time dynamic is contextual: lines in conditional branches show no detectable effect at birth (HR = 0.98, 0–90 days, not significant) but become a risk factor after 90 days (HR = 1.23) Repository identity is the single largest predictive factor: a shared gamma frailty model (variancetheta = 1.451) raises concordance from 0.587 to 0.676 Pruning redundant reasoning tokens The study introduces Code Lifespan Survival Analysis (CLSA), the first framework to model the deletion risk of individual source lines from covariates It treats each source line as a right-censored survival subject and estimates its deletion risk from structural, contextual, and temporal covariates The framework distinguishes three change topologies: migrations (lines relocated across files), modifications (semantically rewritten lines matched via composite Sørensen–Dice + Ratcliff/Obershelp similarity), and true deaths (permanent deletions without a semantic successor) This 5-stage bipartite matching pipeline prevents 8.3 million false deaths in the full population—a prerequisite for unbiased line-level survival estimation How the training signal is built The data mining process involves mining 32.5 million line birth events from 120 active open-source TypeScript repositories A rigorous 5-stage matching pipeline isolates true line deletions from refactoring noise through intra-file exact structural matching, global AST-equivalent detection, Hungarian algorithm–based lexico-semantic assignment, cross-file similarity matching, and high-confidence ASTagnostic intra-file matching Structural context features include nesting depth and four binary flags—in loop, in condition, in try catch, and in function—which are derived from tree-sitter’s parent-chain traversal Lexical features include line token count (log-tokens) and log-todo-distance, which operationalize proximity to acknowledged technical debt Where the gains come from The analysis utilizes a 5-stage statistical pipeline, including non-parametric estimation via Kaplan–Meier curves, semi-parametric modeling with Cox Proportional Hazards regression, and a shared gamma frailty model The time-stratified landmark analysis resolves which covariate effects are genuinely time-varying by fitting separate Cox models on three landmark time bands (< 90 days, 90–365 days, 365+ days) The shared frailty model estimates repository-level heterogeneity with a variancetheta = 1.451 across the analyzed repositories, confirming that repository-level heterogeneity is the dominant source of survival variance Structural Context and Temporal Dynamics The analysis reveals that in condition shows no detectable effect at birth (HR = 0.981, 0–90 days, not significant) but becomes a risk factor after 90 days (HR = 1.229) Line token count is a steady protective lexical factor (HR = 0.87 in the main model) whose effect is essentially flat with age (HR 0.89–0.91 across the three regimes, with no proportional-hazards violation) In function is shown to be a strong and stable protective effect (HR = 0.81, 95% CI

0.80, 0.82: ) across all sensitivity models Repository Heterogeneity and Robustness The dominance of repository frailty is confirmed by the C-index improving from 0.587 to 0.676 when incorporating the shared gamma frailty model Sensitivity analysis confirms that log tokens is a strong protective lexical factor (HR = 0.87, ↓12.8%) and in function shows a strong and stable protective effect (HR = 0.81, ↓19.0%) across all sensitivity models The results are robust to distributional alternatives as AFT models confirm that all 15 of 15 covariates are directionally consistent between Cox PH and both AFT models Practical Implications for IDEs The strongest and most stable predictors identified in the study—log-tokens, ast group expression, in function, and in condition—are all derivable statically from a single source file without any git history This enables an IDE plugin to use tree-sitter to extract structural features for each code block and display an inline risk indicator The dominant predictive signal is not any structural covariate but the repository frailty term (̂theta = 1.451), which accounts for the C-index lift from 0.587 to 0.676 Threats to Validity The pipeline's conservative design achieves a precision of 1.000 (zero false positives among 100 predicted deaths) and a recall of 0.769, with an oracle agreement rate of 0.700 However, the three-way change classification prevents 8.3 million false deaths from inflating hazard estimates The lack of independence between lines within the same function or file is addressed by fitting a marginal Cox model with clustered sandwich standard errors by commit id The C-index of 0.586 indicates that structural features alone are insufficient to predict code survival, and repository-level information is the dominant predictive signal The study cautions that high survivorship in low-activity repositories should be interpreted accordingly, as censoring is anchored to each repository’s own last commit rather than a single global snapshot date In the present work, survival analysis provides a statistically coherent and empirically productive framework for modeling the persistence of individual source code lines Code survival is time-varying for some covariates, but not all: Landmark time-stratified Cox analysis shows that covariate effects can differ substantially across three time bands (< 90d, 90–365d, 365+d) Repository heterogeneity is the dominant predictive signal: The shared gamma frailty model estimates ̂theta = 1.451 (LRTchi2 = 41,571, p ≈ 0), confirming that between-repository variation dominates cross-project survival differences Line token count is a robust protective lexical predictor: Lexically richer lines show a 12.8% hazard reduction (HR = 0.87, main model), stable across all sensitivity checks, all three time bands (flat, no PH violation), and both AFT models Structural context features are stable and actionable: in function is a strong, time-stable protective predictor (HR = 0.762–0.810 across marginal and frailty R models) The 5-stage pipeline is a prerequisite, not a preprocessing detail: The bipartite matching pipeline prevented 8.3 million false deaths—43% of all pipeline-processed deletion events (8.3M false + 11.0M confirmed = 19.

Paper summary: Lu: So wrapping up the "Code Lifespan Survival Analysis Code Lifespan Survival Analysis Predicting the Survival of Source Code Lines Using AST Aware Mining" paper, the main point is that while line survival is time-varying for some covariates, it’s not all of them >

Tom: Exactly. The sharpest dynamic we saw was contextual: in condition shows no effect early on but becomes a risk after ninety days with a hazard ratio of one point two three >

Jane: And the other big finding is that repository heterogeneity is the dominant predictive signal, confirmed by fitting the shared gamma frailty model which estimates theta equal to one point four five one across those repositories >

Meng: So to put it simply, for a developer or maintenance planner, this means you can’t just look at the code structure alone; you have to know which repository you're looking at because that project's inherent risk profile is what matters most >

Tom: And line token count remains a robust protective lexical predictor with a hazard ratio of zero point eight seven and it stays flat across all three time bands, even in the main model >

Jane: So for people who only listen to the show, this paper suggests that understanding which repository you're working in is more important than obsessing over every tiny detail of the code structure >

Lu: The five stage pipeline they built was a prerequisite for all this because it prevented eight point three million false deaths from inflating those hazard estimates >

Meng: That pipeline is crucial because without it, the whole analysis would be way too noisy to actually trust when you try to use it in a production environment >

Tom: And the authors have a limitation: they flag that high survivorship in low activity repositories needs interpretation based on how their censoring is anchored >

Jane: So, while this work provides a statistically coherent way to model line persistence, the core message is that repository level variation dominates cross-project survival differences >

Conclusion: Tom: So we’ve looked at how this Code Lifespan Survival Analysis framework works and what it finds about code lines lasting over time, and now we need to talk about where this whole thing actually lands.

Jane: Yeah, the title is pretty descriptive, "Code Lifespan Survival Analysis Code Lifespan Survival Analysis Predicting the Survival of Source Code Lines Using AST-Aware Mining," which tells you exactly what’s happening here.

Lu: It’s about treating every line of source code like a patient in a survival study and trying to predict when it's going to disappear, or die, from the project.

Meng: And the authors are focused on making sure they don't get those false predictions wrong by using this five stage matching pipeline to isolate real deletions from just refactoring noise.

Tom: Exactly. The implication for us is that we can finally start building tools in our IDEs that give us a risk score for code blocks based on what’s actually happening in the repository structure, not just some surface level code feature.

Jane: It moves the conversation from looking at a single file to understanding the bigger health of the entire codebase and which projects are more likely to stay alive long term.

Lu: The most important thing they found is that repository identity, or which project you're working in, is the biggest factor influencing whether a line survives.

Meng: That makes sense from an engineering standpoint because it means your risk assessment needs to be project specific rather than just looking at general coding patterns across all projects.

Tom: And the paper confirms this by showing that a shared frailty model, which estimates how different each repository is from others, significantly boosts the accuracy of their predictions.

Jane: So basically, they’ve shown us that project-level differences are what really drive code survival across different software ecosystems.

Lu: It leaves us wondering how this kind of structural analysis could be used to proactively manage technical debt before it becomes a massive deletion event for a whole line of code.

More episodes

← Home