Spaces:
Sleeping
Sleeping
Harden sabotage prompts for logical bugs
Browse files5 unmodified lines678910111260 unmodified lines73747576777812 unmodified lines9192939495969710 unmodified lines10810911011111211311431 unmodified lines14614714814915015110 unmodified lines1621631641651661671681691701711721734 unmodified lines17817918018118218318418518618718818919038 unmodified lines22923023123223323414 unmodified lines2492502512522532542 unmodified lines2572582592602612621697 unmodified lines1960196119621963196419651966739 unmodified lines27062707270827092710271127125 unmodified linesimport reimport textwrapfrom langchain_openai import ChatOpenAIfrom langchain_core.messages import SystemMessage, HumanMessagefrom architect.state import ArchitectState60 unmodified linesCRITICAL: The "args" value must be a STRING, not actual Python syntax!Use double quotes around the tuple literal string.Focus on:- Normal cases- Edge cases (empty, None, zero, negative)12 unmodified lines1. A Python function (ORIGINAL, working correctly)2. Test cases with their CURRENT outputs on the original functionYour task: Inject ONE simple, logical bug so that AT LEAST HALF of the tests will produce DIFFERENT outputs.π¨ ABSOLUTELY CRITICAL - NO EXCEPTIONS ALLOWED:ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ10 unmodified lines3. Ask: "Could this bug cause an IndexError?" β If yes, choose different bug4. Ask: "Could this bug cause RecursionError?" β If yes, choose different bug5. Ask: "Will this bug change the output for at least 50% of tests?" β If no, make bug stronger6. ONLY after passing ALL checks above β write the codeREAL-WORLD EXAMPLES OF BUGS THAT WERE REJECTED:βββββββββββββββββββββββββββββββββββββββββββββββ31 unmodified linesβ string[:1].upper() β string[:1].lower() (wrong case, works even on empty string)β return lst[-1:] β return lst[-2:] (safe slicing, returns empty list if too short)CRITICAL REQUIREMENT:- You MUST mentally trace through EACH test case on both the original and buggy versions- If a test shows the SAME output on both versions, the bug is TOO SUBTLE or in the WRONG place10 unmodified lines6. Wrong variable name: use wrong variable in expression7. Wrong return statement: return final list with last/first element modified (if list is never empty)AVOID THESE (too complex or obscure):- Bitwise operations (unless the function already uses them)- Complex string manipulations that look intentional- Type conversions that seem unnatural- Lambda expressions or comprehensions changes (unless simple)- ANY changes that could cause exceptions!EXAMPLE - GOOD BUG SELECTION:Test 1: input [1,2,3,4], output [2,3,4,5]4 unmodified linesCRITICAL RULES:- Choose a SIMPLE, LOGICAL error that a human might make- Change EXACTLY ONE thing (one operator, one number, one variable name)- Bug must cause WRONG OUTPUT (not crashes!)- Do NOT add comments- Do NOT rename function or parameters- Function must still RUN without exceptions on all test inputs- At least HALF of the provided tests must produce DIFFERENT outputs- Bug should be the kind that could happen during normal coding- VERIFY: No IndexError, KeyError, TypeError, or any other exception possible!Return ONLY valid JSON (no markdown):38 unmodified linesYou must create EXACTLY 3 PUBLIC tests and EXACTLY 3 SECRET tests.Each test must be specifically designed to expose YOUR specific bug!PUBLIC TESTS (test_cases_public) - EXACTLY 3 TESTS:- Test #1: Normal case that should FAIL because of your bug- Test #2: Edge case that exposes your bug clearly14 unmodified lines- If you injected "range(n-1)" bug β test with lists of different lengths- If you injected "<=" bug β test with values exactly at the boundary- If you injected wrong variable β test where that variable matters- Your tests MUST actually catch YOUR SPECIFIC bug!- DO NOT create generic tests that pass despite the bug!2 unmodified lines- If bug is in loop condition β tests must trigger loop edge cases- If bug is in comparison β tests must hit the comparison boundary- NO TEST should crash with exceptions - only wrong output valuesCritical rules:- sabotaged_function_code must be ONLY the function definition (def ...: ...) β nothing before or after.1697 unmodified linesprint(f"[saboteur_init] Trying {len(candidate_files)} candidate files in random order")# Initialize data structures for collecting bugs across all filesllm = ChatOpenAI(model="gpt-4o", temperature=0.3, request_timeout=60)all_bugs_data = []bug_specific_tests = {} # {func_name: [test cases that detect this bug]}successful_funcs = [] # Track which functions actually got bugs739 unmodified linesf"FUNCTIONS TO INFLATE:\n{chain_source}")llm = ChatOpenAI(model="gpt-4o", temperature=0.3, request_timeout=60)try:response = llm.invoke([HumanMessage(content=prompt)])snippet = _strip_markdown_code(response.content)5 unmodified lines678910111260 unmodified lines7374757677787980818283848586878889909112 unmodified lines10410510610710810911011111211311411511611710 unmodified lines12812913013113213313413513631 unmodified lines16816917017117217317417517617717817918018118210 unmodified lines1931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232244 unmodified lines22923023123223323423523623723823924024124224338 unmodified lines28228328428528628728828929029129229329414 unmodified lines3093103113123133143153162 unmodified lines3193203213223233243251697 unmodified lines2023202420252026202720282029739 unmodified lines27692770277127722773277427755 unmodified linesimport reimport textwrapfrom llm_config import get_llmfrom langchain_core.messages import SystemMessage, HumanMessagefrom architect.state import ArchitectState60 unmodified linesCRITICAL: The "args" value must be a STRING, not actual Python syntax!Use double quotes around the tuple literal string.PROJECT-SPECIFIC TEST DESIGN RULES:- Do NOT create tests that only check formatting, capitalization, lowercase/uppercase differences,whitespace edits, comment changes, or naming-only behavior.- Prefer tests that validate real behavior and final outputs.- Prefer tests that exercise logic, control flow, data transformation, scoring, filtering,aggregation, fallback selection, state propagation, or helper interaction when relevant.- Include cases that would distinguish a correct implementation from a subtly wrong but stillexecutable implementation.- Include at least a few cases that stress edge conditions, stale state, boundary values,ordering, partial success, or fallback precedence when the function shape suggests them.- Avoid generic tests that would still pass if the implementation had a subtle logical bug.- Prefer inputs that make multi-step behavioral mistakes visible rather than cosmetic differences.Focus on:- Normal cases- Edge cases (empty, None, zero, negative)12 unmodified lines1. A Python function (ORIGINAL, working correctly)2. Test cases with their CURRENT outputs on the original functionYour task: Inject EXACTLY ONE meaningful, logical bug so that AT LEAST HALF of the tests will produce DIFFERENT outputs.PRIMARY GOAL:- Create a realistic bug that produces behaviorally incorrect results while keeping the codeexecutable, deterministic, and stable.- Prefer a subtle logical defect over an obvious breakage.- Prefer a bug that looks like a plausible implementation mistake or reasonable but incorrectdesign choice.π¨ ABSOLUTELY CRITICAL - NO EXCEPTIONS ALLOWED:ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ10 unmodified lines3. Ask: "Could this bug cause an IndexError?" β If yes, choose different bug4. Ask: "Could this bug cause RecursionError?" β If yes, choose different bug5. Ask: "Will this bug change the output for at least 50% of tests?" β If no, make bug stronger6. Ask: "Is this bug only a typo, capitalization change, or cosmetic edit?" β If yes, reject it7. Ask: "Does this bug still look like realistic production code?" β If no, rewrite it8. ONLY after passing ALL checks above β write the codeREAL-WORLD EXAMPLES OF BUGS THAT WERE REJECTED:βββββββββββββββββββββββββββββββββββββββββββββββ31 unmodified linesβ string[:1].upper() β string[:1].lower() (wrong case, works even on empty string)β return lst[-1:] β return lst[-2:] (safe slicing, returns empty list if too short)FORBIDDEN TRIVIAL BUG STYLES (NEVER DO THESE):β Capitalization-only or lowercase/uppercase-only editsβ Whitespace-only or formatting-only editsβ Typo-only edits that are obvious to spotβ Renaming-only changesβ Comment-only or docstring-only changesβ Bugs that are visible from a syntax error or import errorβ Bugs that simply stop the application from startingCRITICAL REQUIREMENT:- You MUST mentally trace through EACH test case on both the original and buggy versions- If a test shows the SAME output on both versions, the bug is TOO SUBTLE or in the WRONG place10 unmodified lines6. Wrong variable name: use wrong variable in expression7. Wrong return statement: return final list with last/first element modified (if list is never empty)PREFERRED NON-TRIVIAL BUG FAMILIES:8. Incorrect fallback precedence between a computed value, a default, and a user-provided value9. Stale state reuse: use a value before it is updated or reuse an earlier derived value10. Mutation vs copy confusion: update the wrong container or return a reused mutable result11. Incorrect filtering, deduplication, or aggregation that preserves plausibility but changes meaning12. Ordering mistakes: sort, merge, or apply steps in the wrong order while keeping valid output13. Partial-success misclassification: treat incomplete success as full success14. Normalization mismatch across steps: normalize one side but not the corresponding comparison input15. Helper propagation bug: return a structurally valid but semantically wrong intermediate valuePROJECT-SPECIFIC PREFERENCES:- Prefer bugs in scoring, challenge evaluation, state updates, hint accounting, submissionverification, diff interpretation, logging metadata, or orchestration.- Prefer bugs that can be hidden across 2-3 related functions when a helper is available.- It is acceptable to add a small amount of realistic-looking but harmless logic if it helpscamouflage the defect, but avoid excessive dead code or absurd branches.- The bug should ideally survive basic smoke behavior and only fail meaningful behavioral checks.AVOID THESE (too complex or obscure):- Bitwise operations (unless the function already uses them)- Complex string manipulations that look intentional- Type conversions that seem unnatural- Lambda expressions or comprehensions changes (unless simple)- ANY changes that could cause exceptions!- Random, time-dependent, race-condition, or network-dependent behavior- Large deletions or drastic rewrites that make the bug obviousEXAMPLE - GOOD BUG SELECTION:Test 1: input [1,2,3,4], output [2,3,4,5]4 unmodified linesCRITICAL RULES:- Choose a SIMPLE, LOGICAL error that a human might make- Change the SMALLEST number of logically related things needed to create ONE coherent bug- Bug must cause WRONG OUTPUT (not crashes!)- Do NOT add comments- Do NOT rename function or parameters- Function must still RUN without exceptions on all test inputs- At least HALF of the provided tests must produce DIFFERENT outputs- Bug should be the kind that could happen during normal coding- The bug should not be solvable by only changing capitalization, whitespace, or one obvious typo- The bug should require reasoning about logic, state, control flow, or data transformation- VERIFY: No IndexError, KeyError, TypeError, or any other exception possible!Return ONLY valid JSON (no markdown):38 unmodified linesYou must create EXACTLY 3 PUBLIC tests and EXACTLY 3 SECRET tests.Each test must be specifically designed to expose YOUR specific bug!PROJECT-SPECIFIC QUALITY BAR:- The injected bug must be logical, subtle, deterministic, and behaviorally meaningful.- Do NOT rely on capitalization-only, lowercase/uppercase-only, typo-only, whitespace-only,formatting-only, comment-only, or import-related defects.- Prefer tests that exercise logic across multiple steps or helper interactions when applicable.- The best bug returns plausible but incorrect outputs without crashing the application.PUBLIC TESTS (test_cases_public) - EXACTLY 3 TESTS:- Test #1: Normal case that should FAIL because of your bug- Test #2: Edge case that exposes your bug clearly14 unmodified lines- If you injected "range(n-1)" bug β test with lists of different lengths- If you injected "<=" bug β test with values exactly at the boundary- If you injected wrong variable β test where that variable matters- If you injected a fallback/state/aggregation bug β include tests that make the incorrect choice visible- If the bug spans helper behavior β test the surface behavior, not just an isolated trivial case- Your tests MUST actually catch YOUR SPECIFIC bug!- DO NOT create generic tests that pass despite the bug!2 unmodified lines- If bug is in loop condition β tests must trigger loop edge cases- If bug is in comparison β tests must hit the comparison boundary- NO TEST should crash with exceptions - only wrong output values- Tests must fail because of behavioral logic mistakes, not because of cosmetic differencesCritical rules:- sabotaged_function_code must be ONLY the function definition (def ...: ...) β nothing before or after.1697 unmodified linesprint(f"[saboteur_init] Trying {len(candidate_files)} candidate files in random order")# Initialize data structures for collecting bugs across all filesllm = get_llm(temperature=0.3, request_timeout=60)all_bugs_data = []bug_specific_tests = {} # {func_name: [test cases that detect this bug]}successful_funcs = [] # Track which functions actually got bugs739 unmodified linesf"FUNCTIONS TO INFLATE:\n{chain_source}")llm = get_llm(temperature=0.3, request_timeout=60)try:response = llm.invoke([HumanMessage(content=prompt)])snippet = _strip_markdown_code(response.content)
architect/saboteur.py+69-6