Repository navigation
feat(jmcp): commit check before commit, dry run, and commit confirmed - #34
Conversation
- load_and_commit_config always runs a commit check before committing; a failed check rolls back the candidate and commits nothing. - load_and_commit_config gains dry_run (check + diff + rollback). - load_and_commit_config and render_and_apply_j2_template gain confirm_timeout_mins (commit confirmed N, validated to 1..65535). - New confirm_commit tool confirms a pending commit confirmed; it refuses when the candidate holds uncommitted changes. - Unit tests in tests/test_commit_confirmed.py. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…it confirmed (#94) Add junos-mcp-server with commit confirmed (jgrizzuti/junos-mcp-server fork, proposed upstream as Juniper/junos-mcp-server#34) as a third server in both capability mappings. It is identified by its confirm_commit tool; both skills warn that re-sending load_and_commit_config does not confirm there. srx-mnha-builder pushes stages with a 10-minute confirmed commit and lets an unverified stage roll back. Field-confirmed on vSRX 24.4R2.21, 2026-10-02. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
|
Glad someone did this - letting an agent commit to network device with no net has always made me uneasy, and the clean-candidate guard in |
|
Hi Alex - Glad you like it !! I am building skills to use the MCP server with SRXs - During the creation of MNHA Skill , I need to use the commit confirm but the tool was not there - I asked Claude Code how to improve the MCP Server and it suggested the tool - I am a new user to Github, I only did forks on projects and now I try to collaborate
…________________________________
De: Alex Levit ***@***.***>
Enviado: domingo, 4 de octubre de 2026 08:10
Para: Juniper/junos-mcp-server ***@***.***>
Cc: Javier Grizzuti ***@***.***>; Author ***@***.***>
Asunto: Re: [Juniper/junos-mcp-server] feat(jmcp): commit check before commit, dry run, and commit confirmed (PR #34)
[https://avatars.githubusercontent.com/u/24719762?s=20&v=4]axlev left a comment (Juniper/junos-mcp-server#34)<#34 (comment)>
Glad someone did this - letting an agent commit to network device with no net has always made me uneasy, and the clean-candidate guard in confirm_commit is a nice touch. Out of curiosity: what pushed you to write it - an actual incident, or just that it felt wrong without one? I'm working on the layer above this (tracking the pending commit, confirming from a probe rather than a human), so the "why" interests me as much as the code.
—
Reply to this email directly, view it on GitHub<#34?email_source=notifications&email_token=ACOO5QJZK6OYLESUSZEOBLL5SIV2JA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKOJXHEZTENJUGA22M4TFMFZW63VGMF2XI2DPOKSWK5TFNZ2KYZTPN52GK4S7MNWGSY3L#issuecomment-5979325405>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/ACOO5QNFWHIWORYF6IUPHSD5SIV2JAVCNFSNUABGKJSXA33TNF2G64TZHMYTAMBQGI4DQMZXGE5US43TOVSTWNJWHAZDCNRRGQ2DJILWAI>.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS<https://github.com/notifications/mobile/ios/ACOO5QIYGP3AD2VA6IE7N635SIV2JA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKOJXHEZTENJUGA22M4TFMFZW63VGMF2XI2DPOKSWK5TFNZ2KUZTPN52GK4S7NFXXG> and Android<https://github.com/notifications/mobile/android/ACOO5QMNW3FXL3GHP6SIZZ35SIV2JA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKOJXHEZTENJUGA22M4TFMFZW63VGMF2XI2DPOKSWK5TFNZ2K4ZTPN52GK4S7MFXGI4TPNFSA>. Download it today!
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
|
That explains the PR better than any incident would: you brought the Junos habit with you. On an HA pair, commit confirmed is the first thing most of us reach for, and it's telling that the agent tool didn't have it until you added it. On the sandbox finding, I think two things, for what they're worth. Since it's a vendor repository, I'd probably send it to Juniper's security contact as well, so it reaches the right people and not only this thread. And if I were writing the fix, I'd look at jinja2's ImmutableSandboxedEnvironment and at passing only plain data into the template context, not Python objects; the sandbox narrows the paths, not exposing objects removes them. Happy to look at the change when you open it. One question, since you're building the MNHA skill: is that aimed at real SRX pairs, or lab for now? I'm trying to understand how far people are letting agents apply changes today. And welcome to collaborating on GitHub; this PR is a strong start :-) |
nileshsimaria
left a comment
There was a problem hiding this comment.
Thanks for this — the feature is well scoped, follows the existing cleanup patterns, and the clean-candidate guard in confirm_commit is the right design. Tests and Black pass for me locally.
Requesting changes for one design issue: on Junos, commit check confirms a pending commit confirmed, so the new dry_run (and the always-on commit check) can silently cancel a rollback timer. Details inline, along with a few smaller items. A single "is a confirmed commit pending?" helper would fix the two main findings together.
Non-blocking follow-up: render_and_apply_j2_template with confirm_timeout_mins can start timers on several routers, but confirm_commit takes one router. router_names support there would be a natural next step.
| # Validate before committing. PyEZ raises CommitError on a | ||
| # failed check; a False return is handled the same way. | ||
| try: | ||
| check_ok = config_util.commit_check() |
There was a problem hiding this comment.
Blocking: on Junos, a commit check issued inside the confirm window confirms a pending commit confirmed, the same as a plain commit does. That makes dry_run not side-effect-free:
load_and_commit_config(confirm_timeout_mins=2, ...)load_and_commit_config(dry_run=true, ...)with any other change- The first commit is now permanent, while the dry-run result says "Nothing was committed".
The same applies to a commit confirmed issued by a human on the CLI, and to the dry-run path in render_and_apply_j2_template (_dry_run_commit_check).
Could you verify this on your vSRX with the steps above, then check show system commit? If it reproduces, I'd suggest a small helper that queries junos_device.rpc.get_commit_information() and reports whether the latest commit is still an unconfirmed commit confirmed, called before commit_check() in both handlers. If one is pending, refuse with a message pointing to confirm_commit. Please also check how the pending state appears in the RPC reply when a commit comment is set.
There was a problem hiding this comment.
Reproduced and fixed. A pending-commit check now runs under the lock before loading in both handlers; dry run, check and commit are refused while one is pending.
| pending = config_util.diff() | ||
| if pending: | ||
| config_util.unlock() | ||
| return ( | ||
| f"Failed to confirm commit on {router_name}: the " | ||
| "candidate configuration has uncommitted changes. " | ||
| "Nothing was committed; review them first:\n" | ||
| f"{pending}" | ||
| ) | ||
| config_util.commit(comment=commit_comment, timeout=timeout) | ||
| config_util.unlock() | ||
| return ( | ||
| f"Commit confirmed on {router_name}. The automatic " | ||
| "rollback is cancelled." | ||
| ) |
There was a problem hiding this comment.
Blocking: this only checks that the candidate is clean. It never checks that a confirmed commit is actually pending. If the window already expired and the device rolled back, the diff is empty, so this issues a no-op commit and returns "Commit confirmed ... The automatic rollback is cancelled." The caller believes the change is live when it has been reverted.
The helper from my comment on the commit check covers this too: if nothing is pending, return something like "No pending commit confirmed on {router_name}; nothing to confirm" (worded so _is_error_content flags it).
There was a problem hiding this comment.
Fixed. It now returns "Error: No pending commit confirmed on X; nothing to confirm…", which _is_error_content flags.
| except Exception as e: | ||
| try: | ||
| config_util.unlock() | ||
| except Exception: | ||
| # Same reasoning as _load_and_commit_sync: never hand | ||
| # a possibly-locked session back to the pool. | ||
| try: | ||
| junos_device.close() | ||
| except Exception: | ||
| pass | ||
| return f"Failed to confirm commit on {router_name}: {e}" |
There was a problem hiding this comment.
If commit() raises RpcTimeoutError and the unlock() here succeeds, we return an error string and the session goes back to the pool. ConnectionPool.get_connection only evicts on RpcTimeoutError when the exception propagates out of the with block, so the pool keeps a session its own comment says is unreliable. Suggest closing the device explicitly in that case:
except Exception as e:
try:
config_util.unlock()
except Exception:
...
if isinstance(e, RpcTimeoutError):
try:
junos_device.close()
except Exception:
pass
return f"Failed to confirm commit on {router_name}: {e}"The message should also say the confirm may or may not have landed, and to check show system commit.
There was a problem hiding this comment.
Done. The session is closed on a timeout, and the message says the confirm may or may not have landed and to check show system commit.
| if confirm_timeout is None: | ||
| config_util.commit(comment=commit_comment, timeout=timeout) | ||
| else: | ||
| config_util.commit( | ||
| comment=commit_comment, | ||
| confirm=confirm_timeout, | ||
| timeout=timeout, | ||
| ) |
There was a problem hiding this comment.
Nit: PyEZ's commit() does if confirm:, so confirm=None behaves exactly like omitting it. Both branches collapse to one call, here and in _apply_rendered_config_sync:
config_util.commit(
comment=commit_comment, confirm=confirm_timeout, timeout=timeout
)The tests asserting assertNotIn("confirm", kwargs) would become assertIsNone(kwargs.get("confirm")).
There was a problem hiding this comment.
Done in both places. The tests now assert confirm is None.
| if confirm_timeout is None: | ||
| config_util.commit(comment=commit_comment, timeout=timeout) | ||
| else: | ||
| config_util.commit( |
There was a problem hiding this comment.
If this confirmed commit times out (RpcTimeoutError), it may still have been applied on the device, with a rollback timer running that the caller doesn't know about. The generic "Failed to load/commit configuration" message hides that. When confirm_timeout is set and the failure is a timeout, please tell the caller to check show system commit and call confirm_commit if the commit landed. Same for the J2 path.
There was a problem hiding this comment.
Done for both tools. The message says it may still have landed, and to check show system commit and call confirm_commit.
| if confirm_timeout is None: | ||
| return "" | ||
| return ( | ||
| f"\n\n⏳ Commit confirmed: {router_name} will automatically roll back in " |
There was a problem hiding this comment.
This note and the confirm_commit success message both start with "Commit confirmed" but mean opposite things: here the rollback is still armed, there it is cancelled. That is easy for an LLM client to misread. Suggest something like:
- here: "⏳ Commit is pending confirmation: {router} will automatically roll back in N minute(s) unless confirm_commit is called for it."
- in
confirm_commit: "Pending commit on {router} confirmed; automatic rollback cancelled."
test_commit_check_runs_before_plain_commit asserts on the "Commit confirmed" string and would need updating.
There was a problem hiding this comment.
Changed to "Commit is pending confirmation…" and "Pending commit on X confirmed; automatic rollback cancelled."
| except CommitError as ce: | ||
| check_ok = False | ||
| check_error = str(ce) | ||
| if not check_ok or dry_run: |
There was a problem hiding this comment.
Nit: in PyEZ 2.7.4 commit_check() never returns False. It returns True, raises, or (in an ncclient error corner case) returns a truthy error dict, which not check_ok would treat as a pass. if check_ok is not True or dry_run: is more robust, and the comment above could drop the "a False return" wording.
There was a problem hiding this comment.
Now is not True in all three places, plus a test for the error-dict case.
| "description": ( | ||
| "Commit with 'commit confirmed N': the device " | ||
| "automatically rolls back after N minutes unless " | ||
| "confirm_commit is called. Omit for a plain commit." | ||
| ), |
There was a problem hiding this comment.
Nit: the J2 tool's description says "Ignored when dry_run=true"; this one doesn't. Please add it here too. Once the pending-commit guard is in, the dry_run description should also say what happens when a confirmed commit is pending.
There was a problem hiding this comment.
"Ignored when dry_run=true" added, and the pending-commit refusal described on both tools and on confirm_commit.
| self.mock_config_cls.assert_not_called() | ||
|
|
||
|
|
||
| class ConfirmCommitTests(_DeviceTestCase): |
There was a problem hiding this comment.
A few cases worth adding:
commit_check()raising a non-CommitError(RpcTimeoutError/RpcError): rollback, unlock, and error text.confirm_commitwhenlock()fails, and whencommit()raises (covers the unlock andclose()eviction path).- Once the pending-commit guard exists: dry run refused while a confirmed commit is pending, and
confirm_commitwith nothing pending.
There was a problem hiding this comment.
All added: non-CommitError in the commit check, confirm_commit lock failure, commit errors (including unlock failure and timeout), the refusal while pending, and nothing pending.
I've been working on my demo lab with the JMCP, but I will present it to my colleagues, partners, and customers to start using it - I think the loop for operational automation starts with tested Skills, MCP Servers, and Human Review . |
On Junos a `commit check` or `commit` inside the confirm window confirms a pending `commit confirmed`, so dry_run and the always-on commit check could silently cancel a rollback timer (reproduced on vSRX 24.4R2.21). - Add _commit_confirmed_pending(): entry 0 of get-commit-information carries <commit-confirmed>rollback pending</commit-confirmed> while pending, with or without a commit comment; the <comment> text survives confirmation and is not used. - load_and_commit_config and render_and_apply_j2_template check it under the lock before loading and refuse (dry run included) while one is pending. - confirm_commit errors when nothing is pending instead of reporting a cancelled rollback after the device already rolled back. - Warn that a timed-out commit confirmed may have landed; evict the pooled session after an RpcTimeoutError that is handled in place. - Distinct messages for "pending confirmation" and "confirmed"; single commit() call; treat anything but True from commit_check() as failure; schema text for the refusal and dry_run/confirm interaction. - Tests with fixtures from captured replies. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks for the thorough review, @nileshsimaria. You were right on the blocking issue. Reproduced first on vSRX 24.4R2.21: I ran RPC reply, captured with
Pushed in e3ad5a4:
Live test with the fix, same vSRX:
|
|
Friendly ping: all review items are addressed in e3ad5a4 and live-tested on vSRX. Happy to make further changes. |
|
Looks good |
…confirms a pending commit (#115) * fix(srx-ips, srx-mnha-builder, srx-mnha-ipsec-builder): commit check confirms a pending commit Juniper/junos-mcp-server#34 merged on 2026-11-02, so the "junos-mcp-server with commit confirmed" column now points to Juniper's own main (no tagged release yet) instead of a third-party fork. On Junos a commit check or commit inside a confirm window confirms the pending commit. All three skills now say to run only read-only commands on a device while a commit confirmed is pending there; this matters most for the IPsec builder's self-restoring uplink test. The merged server's refusal and "No pending commit confirmed" messages are documented. Lab-verified on vSRX 24.4R2.21, 2026-10-05. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * review: "nothing pending" means rolled back or already confirmed Applies the maintainer's #115 review suggestions: a `No pending commit confirmed` reply does not prove the change rolled back. A lost confirm reply, another session, or a stray commit check also leaves it live with nothing pending, so compare with the baseline before reporting either. Also clarifies the traffic-generation snippet's early restore, and the CHANGELOG entry's wording. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: fastrevmd-lab <fastrevmd@gmail.com>
Summary
load_and_commit_configcurrently locks, loads, diffs and runs a plaincommit: there is no commit check, no dry run and nocommit confirmed, so a bad change (e.g. one that cuts off management access) has no automatic rollback. The project article (docs/junos-mcp-server-article.html) describescommit(confirm=1), but the handler does not do this.This PR adds those safety primitives:
load_and_commit_config. If the check fails, nothing is committed, the candidate is rolled back, and the Junos error is returned (the result starts withFailed, so_is_error_contentflags it as a tool error).dry_runonload_and_commit_config: load, commit check, return the diff, roll back. Previously a standalone dry run was only possible throughrender_and_apply_j2_template.confirm_timeout_minsonload_and_commit_configandrender_and_apply_j2_template: commits withcommit confirmed N(PyEZcommit(confirm=N)). Validated to Junos' range 1–65535 before any device is touched; booleans, strings and out-of-range values are rejected so a typo never silently becomes a non-reverting commit. Ignored whendry_run=true.confirm_committool: confirms a pending commit confirmed with a plain commit, cancelling the automatic rollback. It refuses when the candidate has uncommitted changes, so confirming can never commit someone else's edits.load_and_commit_confignow also declares its existingtimeoutargument in the schema.Existing behaviour is unchanged when the new arguments are omitted, apart from the added commit check (a config that fails the check would have failed the commit anyway).
Cleanup on failure follows the existing pattern:
confirm_commitcloses the transport if unlock fails, so the pool evicts a possibly-locked session.Testing
tests/test_commit_confirmed.py(17 tests): timeout validation; commit check before a plain commit; failed check (exception andFalse) never commits; dry run rolls back;confirmpassed to PyEZ for both tools; invalid timeouts rejected without touching the device;confirm_commitwith clean and dirty candidates; unknown router.tests/test_tool_registry.pyupdated for the new tool.black --check .clean. Full suite passes except the twotest_token_securitytests that useos.fchmod, which fail only on Windows and fail identically on currentmain.dry_run: true→ commit check passed, diff returned, no new commit inshow system commit.confirm_timeout_mins: 2, not confirmed →show system commitshowedcommit confirmed, rollback in 2mins/rollback pending; after 2 minutes the device rolled back automatically (by root via other) and the config diff against the pre-test rollback was empty.confirm_timeout_mins: 2thenconfirm_commit→ change still present after the 2-minute window.🤖 Generated with Claude Code