Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .github/workflows/pm-stack-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ jobs:
- name: Test claimant and grist Python suites
run: |
fail=0
for t in pm-stack/opencode-claimant/test_poll.py pm-stack/opencode-claimant/test_claimant.py pm-stack/grist/test_update_choice_options.py; do
for t in pm-stack/opencode-claimant/test_poll.py pm-stack/opencode-claimant/test_claimant.py pm-stack/opencode-claimant/test/test_claimant.py pm-stack/grist/test_update_choice_options.py; do
if [ ! -f "$t" ]; then
echo "::error::Missing suite file $t — the pm-stack Python suites were not run in full."
fail=1
Expand All @@ -96,12 +96,13 @@ jobs:
fi
python3 -m unittest pm-stack/opencode-claimant/test_poll.py || fail=1
python3 -m unittest pm-stack/opencode-claimant/test_claimant.py || fail=1
python3 -m unittest pm-stack/opencode-claimant/test/test_claimant.py || fail=1
python3 -m unittest discover -s pm-stack/grist -p 'test_*.py' || fail=1
if [ "$fail" -ne 0 ]; then
echo "::error::pm-stack Python suites: at least one suite failed (see above)."
exit 1
fi
echo "pm-stack Python suites: test_poll.py + test_claimant.py + grist discovery passed."
echo "pm-stack Python suites: test_poll.py + test_claimant.py + test/test_claimant.py (#7670) + grist discovery passed."

# Python suite for #6217: pm-stack/external-comms/
# test_push_quarantine.py (6 tests, the pinning suite for the
Expand Down
76 changes: 75 additions & 1 deletion pm-stack/opencode-claimant/claimant.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,49 @@ def _collect_parked_handoffs(queue: str, want: int) -> Dict[int, Dict]:
return collected



HELD_ISSUE_LABELS = {"held", "user/owned", "do-not-merge", "do-not-auto-edit"}

_CREDENTIAL_KEY_PARTS = ("password", "secret", "token", "credential",
"api_key", "apikey", "private_key")


def _github_issue_labels(repo: str, issue_number: int) -> set:
"""Live label names on an issue, read through the gh CLI.
Raises on any failure so the caller can fail closed (#7670)."""
result = subprocess.run(
["gh", "issue", "view", str(issue_number), "--repo", repo,
"--json", "labels", "--jq", "[.labels[].name]"],
capture_output=True, text=True, timeout=15,
)
if result.returncode != 0:
raise RuntimeError(
f"gh issue view failed: {result.stderr.strip()[:200]}")
names = json.loads(result.stdout)
if not isinstance(names, list):
raise RuntimeError("gh issue view returned a non-list label set")
return {str(n) for n in names}


def _prompt_safe_packet(packet):
"""Deep-copy a packet for the execution prompt with any
credential-shaped values redacted (#7670): a credential must
never enter a prompt, log, or payload surface, and packets are
assembled by many hands - strip by key name, recursively."""
if isinstance(packet, dict):
safe = {}
for key, value in packet.items():
lowered = str(key).lower()
if any(part in lowered for part in _CREDENTIAL_KEY_PARTS):
safe[key] = "[redacted]"
continue
safe[key] = _prompt_safe_packet(value)
return safe
if isinstance(packet, list):
return [_prompt_safe_packet(v) for v in packet]
return packet


def launch_step(mode: str, cap_room: int) -> List[Dict]:
"""
Step 4: Launch - create sessions and bind tasks.
Expand Down Expand Up @@ -613,6 +656,37 @@ def launch_step(mode: str, cap_room: int) -> List[Dict]:
})
continue

# Step 4a2: Held-label gate (#7670). A candidate whose
# issue carries a held label (held, user/owned,
# do-not-merge, do-not-auto-edit) must never be launched:
# the queue-side hard stop is label-based, and the
# claimant is the last line of defense before a session
# exists. The check fails closed: an unreadable label set
# is a skip, never a launch. Candidates without a
# repo/issue reference have nothing to check.
_packet = packet if isinstance(packet, dict) else {}
_repo = _packet.get("repo") or ""
_issue_no = candidate.get("issue_number")
if _issue_no is None and isinstance(_packet.get("issue"), dict):
_issue_no = _packet["issue"].get("number")
if _repo and _issue_no:
try:
_labels = _github_issue_labels(
str(_repo), int(str(_issue_no).lstrip("#")))
except Exception as e:
skips.append({
"task_id": task_id,
"reason": f"held_label_check_failed: {str(e)}"
})
continue
_held = sorted(_labels & HELD_ISSUE_LABELS)
if _held:
skips.append({
"task_id": task_id,
"reason": f"held_issue_labels: {','.join(_held)}"
})
continue

# Step 4b: Create worker session
session_create_body = {
"location": {
Expand Down Expand Up @@ -705,7 +779,7 @@ def launch_step(mode: str, cap_room: int) -> List[Dict]:
prompt = f"""
Execute queue task {task_id}
Issue: {issue}
Packet: {json.dumps(packet, indent=2)}
Packet: {json.dumps(_prompt_safe_packet(packet), indent=2)}

You are a build agent working on this opencode-lane task.
Use --worker {worker_id} for all queue CLI operations.
Expand Down
1 change: 1 addition & 0 deletions pm-stack/opencode-claimant/test/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Package marker so unittest discovery descends into this suite directory (#7670).
Loading
Loading