Skip to content

[fix] make shared dictionary output fail safely - #204

Merged
vt128 merged 2 commits into
masterfrom
codex/fix-shared-output-safety-20261115
Nov 15, 2026
Merged

vt128 merged 2 commits into
masterfrom
codex/fix-shared-output-safety-20261115

Conversation

@vt128

@vt128 vt128 commented Nov 15, 2026 •

Copy link
Copy Markdown
Member

SharedDict.String and direct Go ToJSON read the mapping without synchronization. JSON/Set iteration can also race between readers. This change repairs default formatting, SnapshotString, and Go/script JSON output with nonblocking output coordination.

Formatting captures each visited SharedDict before invoking formatting callbacks. JSON checks native data and uses the official encoder while holding the mapping lock. Type names use atomic storage; attribute lookup uses fixed metadata. Script methods retain the caller thread and avoid freezing the receiver through a bound to_json closure.

Behavior changes:

  • Held mapping/output locks produce shared_dict(<busy>) for formatting, or an empty string plus ErrSharedDictBusy for Go JSON; script JSON raises the error. Retry outside the current critical section.
  • SharedDict JSON accepts native scalars, containers, structs/modules, duration and the pinned interpreter’s immutable range/string/bytes views. Other Go-backed values, including GoStruct, GoMap, GoSlice and custom JSON/attribute implementations, are rejected. Convert them to independently owned plain data first. The general EncodeStarlarkJSON helper keeps its existing behavior and caller synchronization requirements.
  • Native aliases shared by independent owners still require common ownership or application synchronization. This does not provide an atomic snapshot of an arbitrary mutable graph. Normal output order and configured names remain.

Validation:

  • Go 1.27.4 and Go 1.19.13 baseline/candidate builds, full race-count=2 suites, vet and complete Go examples pass. Coverage increases with no lost coverage in unchanged functions/files; revised/new functions cover 204/207 statements, with three defensive guards classified.
  • The fresh ecosystem comparison passes all 84 legs, including Starbox, StarCLI, kit/examples and domain consumers. Forty consumer profile pairs retain exactly the same 16,012 coverage blocks. Eight real CLI demonstrations pass. An interrupted run retained 60 completed legs and resumed only the remaining 24; original results were not rerun. One overwritten start-metadata record is disclosed separately; command outputs and source guards remain intact.
  • One identical two-reader/no-writer race program reproduces the old iterator race and passes on the candidate.
  • Final documentation updates leave all 115 Go/test/module files byte-identical to the fully tested runtime candidate. Normal commit hooks pass. Go minimum versions, interpreter pin and dependencies are unchanged.

A fixed benchmark cohort compares the previous Starlet implementation (14b31e93) with this runtime, using identical harnesses and compiler per pair: 24 serial processes, 312 rows, no extra samples. Set formatting takes about 15% more time on the native host and 47% on the emulated Go 1.19 floor; JSON cases add about 10–20%. JSON also adds temporary allocations; nonempty name updates add 16 bytes and one allocation. Ordinary Get/SetKey add no allocations. These are descriptive, machine/data-dependent observations, not an equivalence or zero-overhead guarantee. The usage guide includes the qualitative costs and benchmark command.

The native-data JSON input contract above is intentional to prevent host callbacks under the mapping lock. The final head passes all 23 required checks, all 24 latest checks, both Codecov contexts, review/comment inspection and checks-watch.

@codacy-production

codacy-production Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 9 minor

Results:
9 new issues

Category Results
CodeStyle 9 minor

View in Codacy

🟢 Metrics 250 complexity · 4 duplication

Metric Results
Complexity 250
Duplication 4

View in Codacy

🟢 Coverage 97.64% diff coverage · +0.06% coverage variation

Metric Results
Coverage variation ✅ +0.06% coverage variation (-1.00%)
Diff coverage ✅ 97.64% diff coverage

View coverage diff in Codacy

Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (14b31e9) 8622 8209 95.21%
Head commit (0f9614e) 8745 (+123) 8331 (+122) 95.27% (+0.06%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#204) 212 207 97.64%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@codecov

codecov Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.22222% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.20%. Comparing base (14b31e9) to head (0f9614e).

Files with missing lines Patch % Lines
dataconv/share.go 97.22% 3 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #204      +/-   ##
==========================================
+ Coverage   94.12%   94.20%   +0.07%     
==========================================
  Files          53       53              
  Lines        6913     7024     +111     
==========================================
+ Hits         6507     6617     +110     
- Misses        258      259       +1     
  Partials      148      148              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@vt128
vt128 merged commit 4628c04 into master Nov 15, 2026
24 checks passed
@vt128
vt128 deleted the codex/fix-shared-output-safety-20261115 branch November 15, 2026 05:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant