Skip to content

perf(relay): reconcile multiline env values without rescanning prefixes - #31196

Merged
juliusmarminge merged 4 commits into
pingdotgg:mainfrom
hieu-lee:hieu-lee/linear-env-multiline-reconciliation
Nov 15, 2026
Merged

juliusmarminge merged 4 commits into
pingdotgg:mainfrom
hieu-lee:hieu-lee/linear-env-multiline-reconciliation

Conversation

@hieu-lee

@hieu-lee hieu-lee commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Problem

reconcileEnvFile restarts its closing-quote search at line zero for every targeted multiline assignment. Repeated multiline values therefore cause quadratic prefix scans.

Solution

Start each closing-quote scan at the next line and skip the same completed span. This focused performance fix preserves existing .env output, duplicate handling and unclosed-value behavior. For B input characters and E update entries, time becomes O(B + E); existing O(B + E) space is unchanged. Successful scans cover disjoint spans, and only three quote types can cause an unsuccessful suffix scan.

Validation (tests extended before production code):

  • vp test run infra/relay/src/clientConfig.test.ts: 10 tests passed before and after, including filesystem publication through the Alchemy action.
  • vp run check:changed: all selected checks passed.
  • Actual-source differential proof: 10,005 exact-output cases passed. At 1,024 repeated multiline assignments, instrumented callbacks plus includes calls drop from 1,051,648 to 2,048. These are operation counts, not elapsed time or production-latency measurements.
  • Three independent Codex reviews returned clean.

Related configuration pipeline: #12401. #31111 changes a separate error field in this module; its complete diff does not overlap this algorithm. This is a small, behavior-preserving performance fix, not a new feature; no maintainer approval is claimed.

TLDR

complexity-env.mp4

Model: GPT-6.1 Sol. Harness: Codex in T3 Code.

@github-actions github-actions Bot added vouch:unvouched Author is not yet trusted in the VOUCHED list. size:XS 0-9 changed lines (additions + deletions). labels Nov 4, 2026
@coderabbitai

coderabbitai Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 9d0c904 and f8f883b.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

No actionable comments were generated in the recent review.

Walkthrough

reconcileEnvFile now scans forward when it processes a multiline quoted assignment. Tests cover replacement of repeated assignments, preservation of unrelated lines, and later assignments after an unterminated quote.

Changes: Environment assignment reconciliation

Layer / File(s) Summary
Multiline assignment scan
infra/relay/src/clientConfig.ts, infra/relay/src/clientConfig.test.ts
The scan checks later lines for the first occurrence of the opening quote and skips through that line. Tests cover multiline values with different quote styles, repeated assignments, and later assignments after an unterminated quote.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Refactor

Suggested reviewers: juliusmarminge

Merge Risk: Minimal · previous review 9d0c9

This change removes repeated prefix scanning when reconciling multiline environment values, and its tests cover repeated assignments and unclosed quotes. No concrete merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: reconciling multiline env values in relay config without rescanning prefixes. It uses a conventional commit prefix and matches the performance fix in reconcileEnvFile …
Description check Passed The description follows the template well. It has a clear Problem section, a Solution (Change) section that explains the algorithm fix, and a Verification section with specific test commands, results,…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: reconciling multiline env values in relay config without rescanning prefixes. It uses a conventional commit prefix and matches the performance fix in reconcileEnvFile described in the summary and objectives.

Full details: Description check

Explanation

The description follows the template well. It has a clear Problem section, a Solution (Change) section that explains the algorithm fix, and a Verification section with specific test commands, results, and operation counts. It also states that the change is a bug-style performance fix with no maintainer approval claimed. The Scope section does not link an issue and does not explain why no issue is needed. The author cites related PR #12401 but does not say whether it is an issue. Measured counts are reported as operation counts, not timings, and the description states this. The model/harness line is present as the template requests.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 0025e63 and 9d0c904.

Files selected for processing: 1

  • infra/relay/src/clientConfig.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Comment thread infra/relay/src/clientConfig.test.ts Outdated
{ A: "new", B: "updated" },
),
).toBe('# earlier "quote"\nA=new\nKEEP=1\nB=updated\n');
expect(reconcileEnvFile('A="one\ntwo"\n'.repeat(128), { A: "new" })).toBe("A=new\n");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This repeats the duplicate multiline behavior already covered above without checking the scan cost, so it cannot catch the performance regression. Consider removing it.

Suggested change
expect(reconcileEnvFile('A="one\ntwo"\n'.repeat(128), { A: "new" })).toBe("A=new\n");

Posted via Macroscope — Test Signal

@macroscopeapp

macroscopeapp Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Approved at 0025e63

Macroscope's review found this PR approvable — The multiline environment-value search now skips already-scanned prefixes while preserving existing reconciliation behavior. File destinations, configuration defaults, and secret handling are unchanged.

You can add or adjust custom eligibility rules. Learn more.

@hieu-lee

hieu-lee commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

@maria-rcks could you review this focused reconciliation change? All eligible current-head checks pass on 0025e63, CodeRabbit has no actionable findings or unresolved threads, and the 15-minute quiet gate passed. The change avoids rescanning earlier lines while preserving multiline quote handling. Tests were extended before the implementation; the 10 focused tests, 10,005 actual-source equivalence cases, and changed-file checks pass.

@hieu-lee

Copy link
Copy Markdown
Contributor Author

@juliusmarminge could you review this when you have a moment?

Written by Claude Sonnet 5.5 via Claude Code in T3 Code.

@juliusmarminge juliusmarminge added the takeover:in-progress A takeover lead is working on this PR label Nov 15, 2026
@juliusmarminge

Copy link
Copy Markdown
Member

Evidence

Ran production PublishClientConfig against identical synthetic files on Linux x64 / Ryzen 9 9950X / Node v26.13.1. Each case used five warmups and 31 measured invocations, with two rounds in base/head/head/base order. Input restoration and byte verification were untimed.

Before After
f5ca0f9427 9d0c90499c
Captured measurement output Captured measurement output
16,384 multiline assignments: round 1 median 155.199 ms, range 127.865–177.172 ms; round 2 median 151.945 ms, range 133.107–167.747 ms. Same input: round 1 median 8.081 ms, range 6.660–11.288 ms; round 2 median 5.841 ms, range 4.035–8.439 ms.

Median improvements of 147.118 ms and 146.104 ms exceed even the combined before/after spreads in their respective rounds. Every multiline case produced exactly the same seven entries once; single-line controls preserved every KEEP=1 line. All output hashes matched across commits. The 1,024-assignment improvement was smaller than run-to-run noise.

Driver script · All samples and hashes

Not shown:

  • Full relay deployment was not exercised: the driver invoked the production publishing action locally without provisioning cloud resources.
  • Measurements establish the improvement for the reported repeated closed multiline assignments; they do not prove the general O(B + E) bound for every possible input.
  • At 1024 assignments, the measured improvement did not exceed run-to-run spread.

@juliusmarminge juliusmarminge added takeover:ready Takeover done; auto-lands when gates pass and removed takeover:in-progress A takeover lead is working on this PR labels Nov 15, 2026
@juliusmarminge

Copy link
Copy Markdown
Member

Evidence

Measured the production PublishClientConfig action with real file reads and writes on Linux x64, Node v26.13.1. Identical synthetic inputs, five warmups and 31 measured calls per size per session; two sessions per commit in base/head/head/base order. Seed creation excluded. Every output checked byte-for-byte.

Before After
a6d7695064 f8f883b1d8
Session 1 output, session 2 output Session 1 output, session 2 output
4,096 multiline: median 8.537 ms 4,096 multiline: median 1.085 ms
8,192 multiline: median 30.825 ms 8,192 multiline: median 1.892 ms
16,384 multiline: median 117.995 ms; range 107.351–161.786 ms 16,384 multiline: median 3.955 ms; range 3.189–6.360 ms

At 16,384 assignments, the action is 29.84× faster. The 114.041 ms median improvement exceeds the base's 54.435 ms full spread and head's 3.171 ms full spread. All 1,440 production writes matched expected contents, including preservation of control KEEP lines. At 1,024 assignments, the difference is smaller than observed noise.

Driver script · Comparison and environment · Raw samples

Not shown:

  • Full cloud deployment and Alchemy planning/state-cache behavior were not measured; the driver executed the production action body directly.
  • Finite measurements support improved scaling for the reported closed-quote inputs but do not establish O(B + E) for every possible input.
  • No timing improvement beyond observed spread was established at 1,024 or 2,048 assignments.
  • Malformed or unclosed multiline quote cases were not measured.

@juliusmarminge
juliusmarminge merged commit 4cb8da6 into pingdotgg:main Nov 15, 2026
32 checks passed
@juliusmarminge juliusmarminge removed the takeover:ready Takeover done; auto-lands when gates pass label Nov 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XS 0-9 changed lines (additions + deletions). vouch:unvouched Author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants