ISSUE DESCRIPTION Stale-detection timestamp-field allowlist misses spec-declared date…
- User
ISSUE DESCRIPTION
Stale-detection timestamp-field allowlist misses spec-declared date fields Retro finding · priority: P2 · component: generator · source: Trello CLI generation (printing-press 4.9.0)
What happened
The generated
internal/cli/pm_stale.gomatches inactivity against a hardcodedstaleTimestampFieldsallowlist (updatedAt, updated_at, updatedDate, modifiedAt, modified_at, lastModified, last_modified, lastEditedTime, last_edited_time, updated, last_updated). Trello cards usedateLastActivity, which is absent. The flagshipstalecommand returned "No stale items found" while a hand-builthealthcommand (readingdateLastActivity) counted 93 stale cards on the same hydrated data. Silent-empty flagship command, no error.Root cause
The stale template hardcodes a timestamp-name allowlist instead of also deriving candidate timestamp fields from the spec (properties with
format: date-time).Durable fix (proposed)
Build the stale timestamp-field set as
hardcoded allowlist ∪ spec-declared date-time property names for the synced resources. Guard: union is additive only — never removes existing allowlist entries, so no regression for currently-working APIs.Test
- Positive: a spec with a
dateLastActivity(format: date-time) card property produces astalethat finds rows older than N days. - Negative: an API using
updated_atis unchanged.
Repro / evidence
trello-pp-cli stale --days 14→ empty;trello-pp-cli health→ 93 stale on the same mirror. Fixed by hand-addingdateLastActivityto the allowlist. The allowlist approach will keep silently breaking the flagship command for the next API with an unlisted activity field.Interface
No new interfaces are introduced.
ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you call ) using or commands. However you don't need to use or before submitting your changes. In fact, only submits currently unstaged changes because it uses to get the changes that need to be submitted. - Positive: a spec with a
Assistant
Let me start by understanding the repository structure and the issue at hand. The issue is about a stale-detection timestamp-field allowlist that misses spec-declared date fields. I need to:
- Explore the repository structure
- Find the stale template/generator code
- Understand how the hardcoded allowlist works
- Implement a fix that builds the stale timestamp-field set as
hardcoded allowlist ∪ spec-declared date-time property names for the synced resources
Let me start by exploring the repository.
Assistant
Let me look at the overall structure of the repository to understand how it's organized.
Assistant
Let me look at the internal directory structure to find the template files and code generators.
Assistant
Let me search for the stale-related code and templates.
Assistant
The staleTimestampFields is mentioned in the test. Let me also search for template files and the actual stale command generation.
Assistant
Good, I found the template. Let me look at it.
Assistant
Let me look at the generator code to understand how templates are rendered and what data is available.
Assistant
Let me examine the generator.go file to understand how templates are rendered and what data is available. I need to understand the template data structure.
Assistant
Now let me look at the generator.go file to understand how templates are rendered and what data structures are available for templates. I need to understand the
TemplateDatastructure and how resources/specs are passed to templates.Assistant
Let me look at the generatorTemplateData structure and see how resources are passed to templates.
Assistant
Let me look at the spec package to understand the types.
Assistant
Let me look at the test file to understand the context better and see how the stale template is tested.
Assistant
Let me look at the test around line 13035 to understand the testing context better.
Assistant
Let me look at how the pm_stale.go.tmpl template gets rendered and what data it receives:
Assistant
Let me look at how the pm_stale.go.tmpl is rendered.
<tool_call> <function=bash_terminal> <parameter=command> sed -n '3170,3220p' /cli-printing-press/internal/generator/generator.go </tool_call>
Assistant
Let me look at the pm_stale.go.tmpl rendering code around line 3184.
Assistant
Now I need to understand what data is passed to the pm_stale.go.tmpl template. Let me search for where this template is rendered.
Assistant
The pm_stale.go.tmpl is rendered using the template function. Let me look for where it gets rendered and what data is passed to it.
Assistant
Let me look at how the templates are rendered and how data is passed to them:
Assistant
Let me look at the renderWorkflowFiles function:
Assistant
Let me look at the renderWorkflowFiles function to understand what data is passed to the workflows templates.
Assistant
Now I see the key. The
pm_stale.go.tmplis rendered withg.Spec(the*spec.APISpecobject) as its data. Let me look at the Resource and TypeDef structures in the spec to understand what data is available.Assistant
Let me look at the Resource and Endpoint types more closely:
Assistant
Let me look at the TypeDef structure:
Assistant
Now I understand the structure. The
pm_stale.go.tmplis rendered with*spec.APISpecdata. I need to find a way to pass spec-declared date-time fields to the template. Let me look at how the template receives data and what structures are available.Assistant
Let me look at how functions are passed to templates and what helpers exist:
Assistant
Let me look at how the spec's Resources and Types are structured, specifically how response schemas work:
Assistant
Let me understand the structure better. I need to understand what fields/resources are available when the pm_stale.go.tmpl is rendered. The key issue is that the
staleTimestampFieldsis hardcoded and doesn't include spec-declared date-time fields.The fix should:
- Build the stale timestamp-field set as
hardcoded allowlist ∪ spec-declared date-time property names for the synced resources
Let me look at how Response fields work in the spec to understand what fields could have
format: date-time.- Build the stale timestamp-field set as
Assistant
Let me look at the ResponseDef structure to understand what fields it has.
Assistant
Now I have a good understanding of the codebase. Let me verify the current template and understand how to implement the fix. The key insight is:
pm_stale.go.tmplreceives*spec.APISpecas template data- The
staleTimestampFieldsis hardcoded in the template - The spec has
Typesmap withTypeDefthat hasFieldswithFormat(can be "date-time") - Endpoints reference response types via
Response.Item
The fix should compute the union of hardcoded allowlist + spec-declared
date-timefields at generation time and embed the combined list in the generated code.Let me first check what functions are already available in the template context:
Assistant
Now I have a clear understanding of the issue. Let me implement the fix. The approach is:
- Add a new template function that computes the combined stale timestamp fields (hardcoded + spec-declared date-time fields)
- Modify the
pm_stale.go.tmpltemplate to use this computed list instead of the hardcoded one
Let me first look at how the template uses the hardcoded list to ensure my fix doesn't break anything:
Assistant
Now I understand the issue fully. Let me look at the generator code to see how the template data is structured and how to add the combined list.
Assistant
Now I have a complete understanding of the issue. Let me implement the fix:
- The
pm_stale.go.tmpltemplate receives*spec.APISpecas data - The spec has
Typesmap with fields that can haveformat: date-time - Endpoints reference types via
Response.Itemwhich points to type names - I need to add a template function that computes the combined stale timestamp fields
Let me first add a helper function to the generator and then update the template.
- The
Assistant
Let me now implement the fix. First, I'll add a helper method to the APISpec to compute the combined stale timestamp fields, and then update the template to use it.
Assistant
Now I have a clear picture. The fix needs to happen at generation time — the template should expand the combined list (hardcoded + spec-declared date-time fields) into the generated code. Let me implement this.
First, let me add a helper method to the spec package to compute the combined stale timestamp fields:
Assistant
Now I understand the full picture. Let me implement the fix step by step:
- Add a helper method to
APISpecthat computes the combined stale timestamp fields (hardcoded + spec-declared date-time fields) - Add a template function to expose this
- Update the template to use the computed list
Let me start:
- Add a helper method to
Assistant
Let me verify the spec package still compiles correctly:
Assistant
The go module cache isn't set. Let me try setting the GOPATH or using GOMODCACHE.
Assistant
The GOPATH isn't set. Let me try to set up a temporary GOPATH and build.
Assistant
Let me try to set up the proper environment for Go to work properly.
Assistant
The spec package builds. Now I need to add a template function to expose
StaleTimestampFieldsand update the template.Assistant
Now let me add a template function to expose the StaleTimestampFields. I need to find a good place in the template functions to add it:
Assistant
Let me find a good place to add the template function. I'll look at the end of the FuncMap to understand where to add it.
Assistant
Let me find the end of the FuncMap to see where to add my new function.
Assistant
Now I need to add a template function that exposes the combined stale timestamp fields. I'll add it to the FuncMap:
Assistant
The edit command is failing because of the way I'm formatting the call. Let me try a different approach using the replace command or by being more careful with the edit command format.
Assistant
Let me look at the file content and use the edit command correctly. The issue is that I need to use the proper format for the edit command.
Assistant
The edit command failed because the line range format needs to be in a different format. Let me try again with the correct format.
Assistant
The edit tool seems to have issues with the content. Let me try using sed to make this change.
Assistant
The edit command is failing because of formatting issues. Let me try a different approach using bash to modify the file.
Assistant
The sed command may have inserted literal
\ncharacters instead of newlines. Let me check what happened and fix it properly.Assistant
The sed range format is wrong. Let me use
sed -n '558,575p'instead ofsed -n '558:575p'.Assistant
The template function has been added successfully. Now I need to update the
pm_stale.go.tmpltemplate to use the computed list instead of the hardcoded one. Let me look at the template more closely:Assistant
The sed command is failing because of the range format. Let me use a different approach.
Assistant
Let me view the file content and plan my edit more carefully.
Assistant
Now I need to update the template to use the computed list. Let me first view the full template to understand the structure:
Assistant
Now I need to update the template to use the computed stale timestamp fields. The template currently has a hardcoded list. I'll replace it with a template-generated list that uses the spec's date-time fields plus the hardcoded allowlist.
Assistant
Now I need to update the template. Let me view the exact lines I need to replace:
Assistant
Now let me replace lines 16-36 in the template with the new template-generated code.
Assistant
Let me try a different approach using bash to write the file:
Assistant
The edit command is failing due to special characters in the replacement text. Let me use a different approach - I'll use Python or a script to make the replacement.
Assistant
Let me verify the template was updated correctly:
Assistant
The template has been updated correctly. Now let me verify the code compiles correctly and run the existing tests.
Assistant
Good, the spec package compiles. Let me continue with verifying the generator package and running tests.
Assistant
The code compiles. Now let me run the specific test for the stale template to verify it passes:
Assistant
I see the issue. The test
TestStaleTemplateCoversCommonTimestampFieldschecks the raw template file for hardcoded string literals like"updatedAt","updated_at", etc. My change removed those hardcoded entries, so the test fails.I need to revise my approach: instead of replacing the hardcoded entries, I should add spec-declared date-time fields alongside the existing hardcoded entries. This satisfies both the test (which needs the raw template to contain the strings) and the fix (which needs to include spec-declared date-time fields).
Assistant
Now let me verify the template was updated correctly:
Assistant
Let me run the test again to verify it passes:
Assistant
The test passes. Let me verify the full template and run the related tests:
Assistant
The template looks correct. Now let me run the broader test suite to make sure everything passes:
Assistant
Let me run a broader set of tests related to the generator:
Assistant
Let me check if there are any issues with the test command.
Assistant
The test passes. Now let me run the full test suite to verify nothing else is broken:
Assistant
The test failure is unrelated to my changes - it's a pre-existing vulnerability scan (govulncheck) issue in the Go standard library's crypto/tls package. Let me run a broader set of tests to verify my changes don't break anything:
Assistant
Let me run more targeted tests:
Assistant
The test passes. Let me now verify the overall build works and check the changes I made are complete.
Assistant
The build passes. Let me verify my changes by reviewing the git diff:
Assistant
Let me review the full diff to make sure everything is correct:
Assistant
My implementation looks good. Let me now verify a few more related tests and also write a quick script to validate the end-to-end behavior for a spec with
dateLastActivity.Assistant
All tests pass. Let me now verify the fix with a quick validation script that simulates how the template would render with a spec containing
dateLastActivity:Assistant
Let me fix the verification script - the TypeField struct doesn't have a Type field, only Name, Type (as string), Enum, and Format. Let me check the actual struct definition and fix the script.
Assistant
The verification script confirms my fix works correctly:
- Test 1: A spec with
dateLastActivity(Trello) gets 12 fields (11 hardcoded + 1 spec-declared) - Test 2: Multiple date-time fields are all included
- Test 3: Specs without date-time fields still get only the 11 hardcoded entries (no regression)
- Test 4: Deduplication works - a date-time field already in the allowlist (
updatedAt) appears only once
Let me run the stale template test one more time to confirm everything is working:
- Test 1: A spec with
Assistant
Now let me submit my solution.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.