Skip to content

fix: guard navigation and submit against corrupted state - #196

Merged
andyrewlee merged 1 commit into
mainfrom
advisor/023-corrupt-state-robustness
Sep 28, 2026
Merged

andyrewlee merged 1 commit into
mainfrom
advisor/023-corrupt-state-robustness

Conversation

@andyrewlee

Copy link
Copy Markdown
Owner

Summary

Three corrupt-state.json hardening fixes (audit round 2, plan 023):

  • st top spun forever on cyclic metadata — the only unguarded
    child-walk in the codebase; adds the seen set every sibling topology
    helper already carries.
  • st submit dereferenced PushBranches' nil result on
    argument-validation failure (panic → exit 70); now returns the wrapped
    error cleanly.
  • decodeState enforces map-key == Branch.Name (corruption → clear
    error) and backfills legacy missing names.

Test plan

  • New TestTopRefusesParentCycle, TestSubmitInvalidBranchNameCleanError, TestDecodeStateBranchNameIntegrity
  • make ci green locally (Actions retired — make ci is the gate)

Three hardening fixes for hand-edited/corrupted state.json input — a
supported, repairable scenario (st validate reports ParentCycle, st
repair fixes it), so the CLI must degrade gracefully:

- runTop walked single-child links in a bare loop with no visited set;
  every sibling topology helper already carries a cycle guard. A cyclic
  state file made `st top` spin at 100% CPU forever. Now errors naming
  the cycle and pointing at validate/repair.
- PushBranches returns (nil, err) on argument-validation failures
  (invalid remote or branch name); submit dereferenced the nil result
  before the error path ran, turning a clean usage error into a panic /
  exit 70. Guard before the first use.
- decodeState now enforces map-key == Branch.Name and backfills a missing
  Name (legacy v0), refusing self-inconsistent records at the single
  point all serialized state enters through.
@andyrewlee
andyrewlee merged commit e5f3ffc into main Sep 28, 2026
3 checks passed
@andyrewlee
andyrewlee deleted the advisor/023-corrupt-state-robustness branch September 29, 2026 05:32
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