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 exploring the repository structure to understand the codebase and find the relevant files mentioned in the issue.
Assistant
Let me look for the stale-related file specifically and understand the template/generator structure.
Assistant
Found the template file. Let me examine it and understand how the stale detection works.
Assistant
The
opencommand doesn't accept a file path as argument. Let me use bash to read the file instead.Assistant
Now let me understand the generator structure and how templates are processed to see how I can derive timestamp fields from the spec.
Assistant
Let me explore the generator code to understand how templates are processed and how spec properties are available.
Assistant
Let me look at the spec package to understand how resources and their properties/fields are defined:
Assistant
Now let me look at the TypeDef and TypeField structures more closely, and understand how resources have their properties/fields defined.
Assistant
Let me look at the Resource struct to understand what fields/properties are available on resources.
Assistant
Let me look at how the spec's Types and their fields with date-time format are accessible to templates, and how the generator builds the template data:
Assistant
Let me understand how templates access the spec data and look at the template function map more closely:
Assistant
Let me look at the template function map more carefully.
Assistant
I need to look at the template functions. Let me search for how the funcs map is populated and used.
Assistant
Let me look at the generator.go file more carefully, specifically around where the template FuncMap is defined and populated.
Assistant
Let me look at the full function map and understand what data is available to templates.
Assistant
Let me understand the structure better. I need to see what template variables are available when rendering the pm_stale.go.tmpl template. Let me find how the template is rendered and what data is passed to it.
Assistant
Let me continue exploring. I need to find where the pm_stale.go.tmpl template is rendered and what data is passed to it.
<tool_call> <function=bash_terminal> <parameter=command> grep -n "pm_stale|staleTimestampFields" /cli-printing-press/internal/generator/generator.go </tool_call>
Assistant
It seems there's an error in parsing my tool call. Let me try again with the correct format.
Assistant
Let me look at how the pm_stale.go.tmpl template is rendered:
Assistant
Now I need to understand the full picture. Let me look at where the stale template is rendered and what data is passed to it. The template is rendered with
data any, and the key question is whatdatais when rendering pm_stale.go.tmpl.Let me search for where this template is invoked.
Assistant
There was an error. Let me try the command again properly.
Assistant
Hmm, so the pm_stale.go.tmpl template is listed but it seems like it's rendered dynamically somewhere. Let me look at how the generator handles workflow templates.
Assistant
Let me look at the renderWorkflowFiles function to understand what data is passed to workflow templates like pm_stale.go.tmpl.
Assistant
Now I understand the picture. The pm_stale.go.tmpl template is rendered with
g.Specas data. I need to:- Understand how the spec's Types with date-time format fields work
- Modify the template to also derive timestamp fields from the spec's types
Let me explore the spec's Types and how they relate to resources.
Assistant
Now let me look at the relevant test to understand the expected behavior better:
Assistant
Assistant
I need to look at how other template functions work to understand the pattern used in this codebase.
Assistant
Good. These functions return strings that are used directly in the template output. Let me look at how they're implemented.
Assistant
Now I have a clear understanding of the codebase. Let me implement the fix. My approach:
- Add a template function that builds the combined list (hardcoded allowlist + spec-declared date-time fields)
- Modify the template to use this function
Let me first check the current state of the template function map more thoroughly to find the right place to add my function:
Assistant
Now I understand the codebase structure. Let me implement the fix step by step.
Step 1: Add a template function that builds the combined stale timestamp field list
Assistant
Now I have a clear understanding of the codebase. Let me implement the fix step by step.
Step 1: Add a template function that builds the combined stale timestamp field list (hardcoded allowlist + spec-declared date-time fields)
Assistant
I need to find where the funcs map ends so I can add my new function there.
Assistant
I need to find where the funcs map ends (where the closing
}is). Let me continue reading to find it.Assistant
I need to find where the funcs map ends so I can add my new function there. Let me continue searching.
Assistant
I need to find where the funcs map ends (where the closing
}is) so I can add my new function there.Assistant
I need to find where the funcs map ends so I can add my new function there.
Assistant
Now I have found where the funcs map ends (line 556). Let me implement the fix:
Step 1: Add a template function that builds the combined stale timestamp field list
I'll add the function right before the closing
}of the funcs map (line 556), and then modify the template to use it.Assistant
Now I have a complete understanding of the codebase. Let me implement the fix step by step.
Plan:
- Add a template function that builds the combined stale timestamp field list (hardcoded allowlist + spec-declared date-time fields)
- Modify the template to use this function
Let me start by adding the template function to
generator.go:Assistant
Now I have a complete understanding of the codebase. Let me implement the fix.
Plan:
- Add a template function
staleTimestampFieldsthat builds the combined list (hardcoded allowlist + spec-declared date-time fields) - Modify the template to use this function instead of hardcoding the list
Let me add the template function to
generator.go:- Add a template function
Assistant
Let me try a different approach using bash to make the edit:
Assistant
Let me use sed to insert the new function:
Assistant
Now I'll insert the new template function after line 559 using sed:
Assistant
Good, the function was inserted. Now let me verify it was added correctly and then update the template to use this new function.
Assistant
The function was added correctly. Now I need to modify the template to use this new function instead of hardcoding the list.
Assistant
Now I need to modify the template to use the new
staleTimestampFieldstemplate function instead of hardcoding the list. Let me replace the hardcoded list with a call to the template function:Assistant
Now I need to modify the template to use the new
staleTimestampFieldstemplate function instead of hardcoding the list. Let me replace the hardcoded list with a call to the template function.Assistant
Now I need to replace the hardcoded list in the template with a call to the new template function.
Assistant
Good, the template was modified. Let me verify the changes are correct:
Assistant
The template was modified correctly. Now let me verify that the Go code compiles correctly:
Assistant
The Go module cache isn't set. Let me set some environment variables and try again.
Assistant
The Go code compiles. Now let me run the existing tests to make sure the changes don't break anything:
Assistant
I see the issue. The test
TestStaleTemplateCoversCommonTimestampFieldsreads the template source file directly and checks that individual field names like"updatedAt"are present in it. Since I replaced the hardcoded list with a template function call, the field names no longer appear in the template source.I need to take a different approach: keep the hardcoded list in the template source (so the test passes) and ALSO add spec-derived fields via a template function that generates an
init()function to append additional fields at runtime.Let me first restore the template with the hardcoded list and add a separate section for spec-derived fields:
Assistant
I see the issue. The test
TestStaleTemplateCoversCommonTimestampFieldsreads the template source file directly and checks that individual field names like"updatedAt"are present as literal strings. Since I replaced the hardcoded list with{{ staleTimestampFields .Types }}, the field names no longer appear in the template source.I need a different approach that:
- Keeps the hardcoded list visible in the template source (so the test passes)
- ALSO appends spec-derived date-time fields at runtime via an
init()function
Let me update the template:
Assistant
Good, now I need to also add a generated
typesMapvariable that theinit()function can use to access spec-derived date-time fields. Let me update the template:Assistant
Good. Now I need to add a
typesMapvariable that will be populated with the spec's Types. Let me update the template to include this:Assistant
Now let me run the tests to see if this approach works:
Assistant
The test passes. Let me verify the template looks correct and also check if there are any other tests that might be affected by these changes:
Assistant
The test failure (
TestGenerateWithNoAuth) is unrelated to my changes - it's failing due to a Go standard library vulnerability scan (GO-2026-5856), not because of my code changes. Let me verify my changes work correctly by running the stale-specific tests and also by checking a generated golden file:Assistant
Let me also check if there are any golden files that contain the stale template output, as they might need to be updated:
Assistant
Let me search for any golden test files that might contain the stale template output:
Assistant
Good - no golden files contain the stale template output. Let me also verify the code compiles correctly and check that the template generates valid Go code by running a quick generation test:
Assistant
The code compiles. Let me verify the template renders correctly by creating a quick test:
Assistant
Let me take a different approach to verify the template works correctly:
Assistant
The template renders correctly. Now I should remove the unused
staleTimestampFieldstemplate function I added togenerator.gosince the new approach generates thetypesMapdirectly in the template and uses aninit()function to append additional fields at runtime.Assistant
I need to remove the unused
staleTimestampFieldstemplate function fromgenerator.gosince the new approach generates thetypesMapdirectly in the template and uses aninit()function to append additional fields at runtime.Assistant
I need to remove the unused
staleTimestampFieldstemplate function fromgenerator.gosince the new approach doesn't use it - it generates thetypesMapdirectly in the template and uses aninit()function to append additional fields at runtime.Assistant
The unused
staleTimestampFieldsfunction has been removed fromgenerator.go. Let me verify the removal was clean and the code still compiles correctly.Assistant
Good. The code still compiles. Let me verify the stale test still passes:
Assistant
The test passes. Now let me verify the complete state of my changes:
Assistant
Let me see the full diff to understand what changes have been made.
Assistant
The changes look good. Let me verify the final state of the modified template file to ensure it's complete and correct:
Assistant
Let me run the final verification to confirm everything works:
Assistant
I have successfully implemented the fix for the stale-detection timestamp-field allowlist issue. Here's a summary of what was done:
Changes Made
File modified:
internal/generator/templates/workflows/pm_stale.go.tmplThe fix adds three components:
-
typesMapvariable - A new Go variable that mirrors the spec's type definitions at generation time, containing field names and their format hints (e.g.,date-time,date). -
Helper types (
typeDefandtypeField) - Lightweight structs to hold type information in the generated Go code without needing a spec dependency. -
init()function - Extends thestaleTimestampFieldsallowlist at runtime with any spec-declared type fields whose format is"date-time"or"date". Uses aknownmap for deduplication.
Key Design Decisions
- Purely additive union: The hardcoded allowlist is never pruned, so existing APIs are not affected. New date-time fields from specs are appended.
-
Assistant
The solution is complete. Let me submit the changes.
Assistant
I need to submit the changes using the proper command format.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.