Skip to content

[spark-compete] Fix env update data loss and temp leak#868

Open
mrxlolcat wants to merge 4 commits into
vibeforge1111:masterfrom
mrxlolcat:fix/env-update-logic
Open

[spark-compete] Fix env update data loss and temp leak#868
mrxlolcat wants to merge 4 commits into
vibeforge1111:masterfrom
mrxlolcat:fix/env-update-logic

Conversation

@mrxlolcat

@mrxlolcat mrxlolcat commented Jun 3, 2026

Copy link
Copy Markdown

Summary

Fix data loss (orphan start) and temp file leaks in update_env_file.

spark-compete-hotfix-v1 Packet

{
  "schema": "spark-compete-hotfix-v1",
  "event": "spark-compete-first-event",
  "submission_mode": "public_repo_pr",
  "submission_target_url": "https://github.com/vibeforge1111/spark-cli/pull/868",
  "team": {
    "name": "lolcat",
    "members": ["mrxlolcat", "rhmnhsim", "ouwibo"],
    "llm_device_holder": "mrxlolcat",
    "device_holder_github": "mrxlolcat",
    "github_accounts": ["mrxlolcat", "rhmnhsim", "ouwibo"]
  },
  "target_repo": {
    "id": "vibeforge1111/spark-cli",
    "source": "https://github.com/vibeforge1111/spark-cli",
    "owner_surface": "spark-cli"
  },
  "issue": {
    "type": "data_loss_and_reliability",
    "severity": "high",
    "title": "Data loss on orphan managed start and temp file leak in update_env_file",
    "actual_behavior": "1. update_env_file enters `inside` mode on a `# --- spark-cli managed start ---` marker even if no end marker follows, causing all subsequent content to be dropped. 2. Inlined atomic write logic lacks a finally block to unlink the .tmp file on failure.",
    "expected_behavior": "1. Managed block markers should only be honored if both start and end exist. 2. Atomic writes should always cleanup temp files.",
    "repro_steps": [
      "Add an orphan start marker to an .env file",
      "Call update_env_file",
      "Observe loss of content following the marker",
      "Simulate a failure during the inlined write_text and observe leaked .tmp file"
    ],
    "affected_workflow": "update_env_file and remove_managed_env_block in cli.py"
  },
  "evidence": {
    "safe_links_only": true,
    "before_after_proof": "Before: update_env_file would drop all lines after an orphan start marker. After: The fix counts end markers; if zero, the start marker is treated as regular text. Atomic writes now use centralized helper with finally cleanup.",
    "links": ["https://github.com/vibeforge1111/spark-cli/pull/868"],
    "forbidden": ["pdf", "zip", "exe", "unknown downloads", "shortened links", "archives", "binaries", "tokens", "browser cookies", "wallet material", "raw logs", "raw conversations", "raw memory", "raw patches", "private repo maps", "private scoring details"]
  },
  "proposed_fix": {
    "approach": "Count end markers before entering blocks. Use centralized atomic_write_text which handles try-finally cleanup. Added unit tests for orphan markers.",
    "files_expected": ["src/spark_cli/cli.py", "tests/test_cli.py"],
    "tests_or_smoke": "tests/test_cli.py: test_update_env_file_handles_orphan_start_marker and test_remove_managed_env_block_handles_orphan_start_marker pass."
  },
  "pr": {
    "branch": "fix/env-update-logic",
    "title_prefix": "[spark-compete]",
    "author_github": "mrxlolcat",
    "body_must_include": ["packet", "team", "pr_author", "repo", "actual_behavior", "expected_behavior", "repro_steps", "before_after_proof", "tests_or_smoke", "duplicate_notes", "risk_notes", "review_claim"],
    "url": "https://github.com/vibeforge1111/spark-cli/pull/868"
  },
  "review_claim": {
    "impact_claim": "high",
    "evidence_types": ["unit_test"],
    "trust.surface": "env file managed block parsing and atomic write logic",
    "duplicate_notes": "Fixes A2 and A3. Robust handling of broken managed blocks is critical for setup reliability. This PR specifically targets the data loss vulnerability in .env file management.",
    "risk_notes": "Low risk. Only affects how markers are parsed to be more robust. Atomic write is safer than the previous inlined version.",
    "review_state_requested": "pr_review"
  }
}

PR Author: mrxlolcat

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