refactor(mcp): rename generate_job_file to write_job_file to match what it does
The MCP tool was named `generate_job_file` from Stage 2 but it does
NOT generate PySpark code — the calling LLM writes the code in its own
context, and this tool only persists it to a file under
SPARK_EXECUTOR_JOBS_DIR so `spark-submit` can see it. The misleading
`generate_` prefix sent agents (and humans) looking for a code
generator that doesn't exist.
This commit folds three related polish changes into one (split later
with rebase -i if you want them as separate history):
1. The rename itself:
- `tools/generate.py` → `tools/write_job.py`
- `generate_job_file` → `write_job_file`
- `GenerateJobFileRequest` → `WriteJobFileRequest`
- `/generate_job_file` route → `/write_job_file`
- `operation_id="generate_job_file"` → `operation_id="write_job_file"`
The internal helper `core.job_writer.write_job_file` (which just
writes bytes to disk with no SQL guard) is imported with an
`_write_to_disk` alias to avoid the name collision with the
MCP-exposed function in the same module.
The description for the tool now explicitly states 'this tool
does NOT generate PySpark code. The calling LLM is expected to
have already written the code; this tool only persists it.'
2. Skill for LLM agents operating the service
(`docs/superpowers/skills/spark-executor-mcp-operate/SKILL.md`,
449 lines). Covers the 16 tools, the two-step prepare/confirm
flow, the dual-ID contract (job_id vs application_id), the
PendingSubmission state machine, the Connection profile, the
job-file workflow, the error reference, common pitfalls, and a
full end-to-end word-count example.
3. Default `executor_memory` lowered 4G → 2G
(`_DEFAULTS_TO_CONFIRM` in `server.py`). Mirrors the matching
change in `test_mcp_routes.py` and the 5 unit tests that
reference the default. Aligns with the lighter workloads the
service is sized for in its current container profile.
Also tracked in git for the first time:
- `docs/superpowers/plans/2026-06-24-spark-executor-mcp.md`
(the original Stage 1/2/3 design plan, updated to use the new
tool name throughout).
Test rename:
- `tests/unit/test_generate_tool.py` → `test_write_job_tool.py`
- the new test file picks up an extra assertion that the SQL guard
rejects a `DROP TABLE` statement at write time.
243 tests pass (was 242; +1 new SQL-guard assertion). Zero regressions.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -36,7 +36,7 @@ def test_build_command_uses_provided_master_and_deploy_mode():
|
||||
deploy_mode="cluster",
|
||||
script_path="/tmp/jobs/job_001.py",
|
||||
queue="default",
|
||||
executor_memory="4G",
|
||||
executor_memory="2G",
|
||||
executor_cores=2,
|
||||
num_executors=2,
|
||||
)
|
||||
@@ -44,7 +44,7 @@ def test_build_command_uses_provided_master_and_deploy_mode():
|
||||
assert "yarn" in cmd
|
||||
assert "cluster" in cmd
|
||||
assert "--queue" in cmd and "default" in cmd
|
||||
assert "--executor-memory" in cmd and "4G" in cmd
|
||||
assert "--executor-memory" in cmd and "2G" in cmd
|
||||
assert "--executor-cores" in cmd and "2" in cmd
|
||||
assert "--num-executors" in cmd and "2" in cmd
|
||||
assert cmd[-1] == "/tmp/jobs/job_001.py"
|
||||
@@ -56,7 +56,7 @@ def test_extra_args_none_default():
|
||||
deploy_mode="cluster",
|
||||
script_path="/tmp/jobs/job_001.py",
|
||||
queue="default",
|
||||
executor_memory="4G",
|
||||
executor_memory="2G",
|
||||
executor_cores=2,
|
||||
num_executors=2,
|
||||
)
|
||||
@@ -70,7 +70,7 @@ def test_extra_args_single_pair():
|
||||
deploy_mode="cluster",
|
||||
script_path="/tmp/jobs/job_001.py",
|
||||
queue="default",
|
||||
executor_memory="4G",
|
||||
executor_memory="2G",
|
||||
executor_cores=2,
|
||||
num_executors=2,
|
||||
extra_args={"jars": "hdfs:///libs/foo.jar"},
|
||||
@@ -88,7 +88,7 @@ def test_extra_args_multiple_pairs_preserve_order():
|
||||
deploy_mode="cluster",
|
||||
script_path="/tmp/jobs/job_001.py",
|
||||
queue="default",
|
||||
executor_memory="4G",
|
||||
executor_memory="2G",
|
||||
executor_cores=2,
|
||||
num_executors=2,
|
||||
extra_args={
|
||||
@@ -112,7 +112,7 @@ def test_extra_args_does_not_collide_with_spark_conf():
|
||||
deploy_mode="cluster",
|
||||
script_path="/tmp/jobs/job_001.py",
|
||||
queue="default",
|
||||
executor_memory="4G",
|
||||
executor_memory="2G",
|
||||
executor_cores=2,
|
||||
num_executors=2,
|
||||
spark_conf={"spark.executor.memory": "8G"},
|
||||
@@ -146,7 +146,7 @@ def test_build_command_appends_spark_conf_entries():
|
||||
deploy_mode="cluster",
|
||||
script_path="/tmp/j.py",
|
||||
queue="default",
|
||||
executor_memory="4G",
|
||||
executor_memory="2G",
|
||||
executor_cores=2,
|
||||
num_executors=2,
|
||||
spark_conf={"spark.sql.shuffle.partitions": "200", "spark.executor.memoryOverhead": "1G"},
|
||||
@@ -169,7 +169,7 @@ def test_build_command_uses_settings_spark_submit_bin():
|
||||
deploy_mode="cluster",
|
||||
script_path="/tmp/j.py",
|
||||
queue="default",
|
||||
executor_memory="4G",
|
||||
executor_memory="2G",
|
||||
executor_cores=2,
|
||||
num_executors=2,
|
||||
)
|
||||
@@ -183,7 +183,7 @@ def test_build_command_supports_pyspark_binary():
|
||||
deploy_mode="cluster",
|
||||
script_path="/tmp/j.py",
|
||||
queue="default",
|
||||
executor_memory="4G",
|
||||
executor_memory="2G",
|
||||
executor_cores=2,
|
||||
num_executors=2,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user