Skip to content

Add a gate command that remembers allowed steps between calls - #720

Merged
gerardrecinto merged 1 commit into
masterfrom
barrier-check-cli
Nov 5, 2026
Merged

gerardrecinto merged 1 commit into
masterfrom
barrier-check-cli

Conversation

@gerardrecinto

Copy link
Copy Markdown
Collaborator

A hook or script runs once per command, so it cannot hold a trace in memory the way the MCP server does. sop-mcp-server gate asks the barrier about one step and keeps the allowed steps in a small file per session. Exit 0 allowed, 1 blocked with the reason and the steps to run first, 2 usage error. A session name cannot contain a path, a blocked step records nothing, and a saved file that no longer matches the runbook is refused instead of trusted.

Seven tests pass with -race, and I ran plan and apply by hand: apply first is blocked, plan is allowed, apply after plan is allowed. This orders steps only. It does not run anything.

Thanks,
Gerard

@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown

Gemini PR Review

Reviewed commit: fe23c63d36e8f5d1dfecad1ee94960263aab54a6
Verdict: PASS

  • cmd/sop-mcp-server/gate.go: The gateSessionRE regular expression (^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$) used to validate session names is effective in preventing path traversal attacks by disallowing characters like /, \, and ... Combined with filepath.Join and strict file permissions (0o700 for directories, 0o600 for files), this ensures session files are stored securely and predictably within the designated state directory.

  • cmd/sop-mcp-server/gate.go: The saveGateState function implements an atomic write operation using os.CreateTemp followed by os.Rename. This design prevents data corruption or loss in the event of a crash during file writing, ensuring the integrity of the session state.

  • cmd/sop-mcp-server/gate.go: The loadGateTrace function includes a critical correctness check by replaying all previously recorded steps against the current workflow rules (wf.CheckAndCommit). If any saved step no longer passes the runbook (e.g., due to a runbook update), it returns an error and forces a session reset. This prevents the system from silently operating under outdated or inconsistent rules.

  • cmd/sop-mcp-server/gate_test.go: The test TestGateRefusesStateThatNoLongerMatchesTheRunbook specifically verifies the robust error handling for cases where saved session state becomes inconsistent with a modified runbook. This is an excellent test for an important edge case and demonstrates strong correctness.

@gerardrecinto
gerardrecinto merged commit 3b2140a into master Nov 5, 2026
37 of 38 checks passed
@gerardrecinto
gerardrecinto deleted the barrier-check-cli branch November 5, 2026 04:05
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